pacc 9.1.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ast.mjs +7 -4
- package/src/tokens.mjs +71 -20
- package/types/tokens.d.mts +18 -18
package/package.json
CHANGED
package/src/ast.mjs
CHANGED
|
@@ -12,10 +12,7 @@ export function pathEval(node, current, context) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function functionEval(node, current, context) {
|
|
15
|
-
|
|
16
|
-
typeof a === "object" ? a.eval(a, current, context) : a
|
|
17
|
-
);
|
|
18
|
-
return context.valueFor(node.name)(...args);
|
|
15
|
+
return context.valueFor(node.name)(node.args, current, context);
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
export function keyedAccessOrGlobalEval(node, current, context) {
|
|
@@ -33,6 +30,12 @@ export function keyedAccessEval(node, current, context) {
|
|
|
33
30
|
return current.has(node.key) ? node.key : undefined;
|
|
34
31
|
}
|
|
35
32
|
if (current instanceof Iterator) {
|
|
33
|
+
if(typeof node.key === 'number') {
|
|
34
|
+
for(const item of current.drop(node.key)) {
|
|
35
|
+
return item;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
36
39
|
return current.map(item => item[node.key]);
|
|
37
40
|
}
|
|
38
41
|
|
package/src/tokens.mjs
CHANGED
|
@@ -308,8 +308,23 @@ export const keywords = {
|
|
|
308
308
|
false: [BOOLEAN, false]
|
|
309
309
|
};
|
|
310
310
|
|
|
311
|
+
function evalAll(args, current, context) {
|
|
312
|
+
return args.map(a =>
|
|
313
|
+
typeof a?.eval === "function" ? a.eval(a, current, context) : a
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function evalOne(arg, current, context) {
|
|
318
|
+
return typeof arg?.eval === "function"
|
|
319
|
+
? arg.eval(arg, current, context)
|
|
320
|
+
: arg;
|
|
321
|
+
}
|
|
322
|
+
|
|
311
323
|
export const globals = {
|
|
312
|
-
in: (
|
|
324
|
+
in: (args,current,context) => {
|
|
325
|
+
const a = evalOne(args[0], current, context);
|
|
326
|
+
const b = evalOne(args[1], current, context);
|
|
327
|
+
|
|
313
328
|
if (b?.[Symbol.iterator]) {
|
|
314
329
|
for (const x of b) {
|
|
315
330
|
if (x === a) {
|
|
@@ -319,29 +334,65 @@ export const globals = {
|
|
|
319
334
|
}
|
|
320
335
|
return false;
|
|
321
336
|
},
|
|
322
|
-
ceil:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
ceil: (args, current, context) =>
|
|
338
|
+
Math.ceil(evalOne(args[0], current, context)),
|
|
339
|
+
floor: (args, current, context) =>
|
|
340
|
+
Math.floor(evalOne(args[0], current, context)),
|
|
341
|
+
abs: (args, current, context) => Math.abs(evalOne(args[0], current, context)),
|
|
342
|
+
min: (args, current, context) => Math.min(...evalAll(args, current, context)),
|
|
343
|
+
max: (args, current, context) => Math.max(...evalAll(args, current, context)),
|
|
344
|
+
encodeURI: (args, current, context) =>
|
|
345
|
+
encodeURI(...evalAll(args, current, context)),
|
|
346
|
+
decodeURI: (args, current, context) =>
|
|
347
|
+
decodeURI(...evalAll(args, current, context)),
|
|
348
|
+
encodeURIComponent: (args, current, context) =>
|
|
349
|
+
encodeURIComponent(...evalAll(args, current, context)),
|
|
350
|
+
decodeURIComponent: (args, current, context) =>
|
|
351
|
+
decodeURIComponent(...evalAll(args, current, context)),
|
|
352
|
+
trim: (args, current, context) => evalOne(args[0], current, context).trim(),
|
|
353
|
+
length: (args, current, context) => evalOne(args[0], current, context).length,
|
|
354
|
+
uppercase: (args, current, context) =>
|
|
355
|
+
evalOne(args[0], current, context).toUpperCase(),
|
|
356
|
+
lowercase: (args, current, context) =>
|
|
357
|
+
evalOne(args[0], current, context).toLowerCase(),
|
|
358
|
+
substring: (args, current, context) => {
|
|
359
|
+
const str = evalOne(args[0], current, context);
|
|
360
|
+
const n1 = evalOne(args[1], current, context);
|
|
361
|
+
return args.length > 2
|
|
362
|
+
? str.substring(n1, evalOne(args[2], current, context))
|
|
363
|
+
: str.substring(n1);
|
|
364
|
+
},
|
|
365
|
+
join: (args, current, context) => {
|
|
366
|
+
const separator = evalOne(args.shift(), current, context);
|
|
367
|
+
return evalAll(args, current, context)
|
|
338
368
|
.map(item => (item instanceof Iterator ? Array.from(item) : item))
|
|
339
369
|
.flat()
|
|
340
|
-
.join(separator)
|
|
341
|
-
|
|
370
|
+
.join(separator);
|
|
371
|
+
},
|
|
372
|
+
sort: (args, current, context) => {
|
|
373
|
+
const data = evalOne(args[0], current, context);
|
|
374
|
+
if (args.length >= 2) {
|
|
375
|
+
let order = 1;
|
|
376
|
+
if(args.length > 2) {
|
|
377
|
+
const str = evalOne(args[2], current, context);
|
|
378
|
+
if(str === 'descending') {
|
|
379
|
+
order = -1;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const selector = args[1];
|
|
383
|
+
return data.sort(
|
|
384
|
+
(a, b) =>
|
|
385
|
+
(selector.eval(selector, a, context) -
|
|
386
|
+
selector.eval(selector, b, context)) * order
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
342
390
|
return data.sort();
|
|
343
391
|
},
|
|
344
|
-
truncate: (
|
|
392
|
+
truncate: (args, current, context) => {
|
|
393
|
+
const data = evalOne(args[0], current, context);
|
|
394
|
+
const length = evalOne(args[1], current, context);
|
|
395
|
+
|
|
345
396
|
data.length = length;
|
|
346
397
|
return data;
|
|
347
398
|
}
|
package/types/tokens.d.mts
CHANGED
|
@@ -47,25 +47,25 @@ export namespace keywords {
|
|
|
47
47
|
export { _false as false };
|
|
48
48
|
}
|
|
49
49
|
export namespace globals {
|
|
50
|
-
export function _in(
|
|
50
|
+
export function _in(args: any, current: any, context: any): boolean;
|
|
51
51
|
export { _in as in };
|
|
52
|
-
export
|
|
53
|
-
export
|
|
54
|
-
export
|
|
55
|
-
export
|
|
56
|
-
export
|
|
57
|
-
export
|
|
58
|
-
export
|
|
59
|
-
export
|
|
60
|
-
export
|
|
61
|
-
export function trim(
|
|
62
|
-
export function
|
|
63
|
-
export function
|
|
64
|
-
export function
|
|
65
|
-
export function
|
|
66
|
-
export function join(
|
|
67
|
-
export function sort(
|
|
68
|
-
export function truncate(
|
|
52
|
+
export function ceil(args: any, current: any, context: any): number;
|
|
53
|
+
export function floor(args: any, current: any, context: any): number;
|
|
54
|
+
export function abs(args: any, current: any, context: any): number;
|
|
55
|
+
export function min(args: any, current: any, context: any): number;
|
|
56
|
+
export function max(args: any, current: any, context: any): number;
|
|
57
|
+
export function encodeURI(args: any, current: any, context: any): string;
|
|
58
|
+
export function decodeURI(args: any, current: any, context: any): string;
|
|
59
|
+
export function encodeURIComponent(args: any, current: any, context: any): string;
|
|
60
|
+
export function decodeURIComponent(args: any, current: any, context: any): string;
|
|
61
|
+
export function trim(args: any, current: any, context: any): any;
|
|
62
|
+
export function length(args: any, current: any, context: any): any;
|
|
63
|
+
export function uppercase(args: any, current: any, context: any): any;
|
|
64
|
+
export function lowercase(args: any, current: any, context: any): any;
|
|
65
|
+
export function substring(args: any, current: any, context: any): any;
|
|
66
|
+
export function join(args: any, current: any, context: any): any;
|
|
67
|
+
export function sort(args: any, current: any, context: any): any;
|
|
68
|
+
export function truncate(args: any, current: any, context: any): any;
|
|
69
69
|
}
|
|
70
70
|
export type Token = {
|
|
71
71
|
str: string;
|