pacc 9.0.0 → 9.2.0
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/README.md +7 -6
- package/package.json +2 -1
- package/src/ast.mjs +1 -4
- package/src/tokens.mjs +77 -19
- package/types/tokens.d.mts +18 -16
package/README.md
CHANGED
|
@@ -546,6 +546,7 @@ Retrive attribute values from an object.
|
|
|
546
546
|
|
|
547
547
|
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute value source
|
|
548
548
|
* `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
549
|
+
* `filter` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
|
|
549
550
|
|
|
550
551
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** values
|
|
551
552
|
|
|
@@ -565,12 +566,12 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
565
566
|
|
|
566
567
|
## tokens
|
|
567
568
|
|
|
568
|
-
Split
|
|
569
|
+
Split expression path into tokens.
|
|
569
570
|
|
|
570
571
|
### Parameters
|
|
571
572
|
|
|
572
573
|
* `string` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
573
|
-
* `
|
|
574
|
+
* `context` (optional, default `{}`)
|
|
574
575
|
|
|
575
576
|
## setAttribute
|
|
576
577
|
|
|
@@ -582,7 +583,7 @@ The name may be a property path like 'a.b.c'.
|
|
|
582
583
|
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
583
584
|
* `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
584
585
|
* `value` **any** 
|
|
585
|
-
* `definition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
|
|
586
|
+
* `definition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** type def
|
|
586
587
|
|
|
587
588
|
## getAttribute
|
|
588
589
|
|
|
@@ -593,7 +594,7 @@ The name may be a property path like 'a.b.c' or a\[2]
|
|
|
593
594
|
|
|
594
595
|
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
595
596
|
* `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
596
|
-
* `definition`
|
|
597
|
+
* `definition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** 
|
|
597
598
|
|
|
598
599
|
Returns **any** value associated with the given property name
|
|
599
600
|
|
|
@@ -654,8 +655,8 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
|
|
|
654
655
|
* `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
655
656
|
* `precedence` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `0`)
|
|
656
657
|
* `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** 
|
|
657
|
-
* `led` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** (optional, default `()=>
|
|
658
|
-
* `nud` (optional, default `
|
|
658
|
+
* `led` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** (optional, default `(parser,node)=>node`)
|
|
659
|
+
* `nud` (optional, default `parser=>this`)
|
|
659
660
|
|
|
660
661
|
Returns **[Token](#token)** 
|
|
661
662
|
|
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) {
|
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,25 +334,68 @@ 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)
|
|
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
|
+
|
|
390
|
+
return data.sort();
|
|
391
|
+
},
|
|
392
|
+
truncate: (args, current, context) => {
|
|
393
|
+
const data = evalOne(args[0], current, context);
|
|
394
|
+
const length = evalOne(args[1], current, context);
|
|
395
|
+
|
|
396
|
+
data.length = length;
|
|
397
|
+
return data;
|
|
398
|
+
}
|
|
341
399
|
};
|
|
342
400
|
|
|
343
401
|
/**
|
|
@@ -349,7 +407,7 @@ export const globals = {
|
|
|
349
407
|
export function* tokens(string, context = {}) {
|
|
350
408
|
context.keywords ||= keywords;
|
|
351
409
|
context.parseFloat ||= parseFloat;
|
|
352
|
-
context.valueFor ||= (name,at) => globals[name];
|
|
410
|
+
context.valueFor ||= (name, at) => globals[name];
|
|
353
411
|
|
|
354
412
|
let state, value, hex, quote;
|
|
355
413
|
|
package/types/tokens.d.mts
CHANGED
|
@@ -47,23 +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(
|
|
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;
|
|
67
69
|
}
|
|
68
70
|
export type Token = {
|
|
69
71
|
str: string;
|