pacc 7.2.0 → 8.0.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 +5 -0
- package/package.json +1 -1
- package/src/expression.mjs +6 -5
- package/src/tokens.mjs +19 -16
- package/src/types.mjs +3 -2
- package/types/expression.d.mts +1 -14
- package/types/tokens.d.mts +7 -1
- package/types/types.d.mts +1 -0
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
|
|
|
64
64
|
* [secret\_attribute](#secret_attribute-2)
|
|
65
65
|
* [secret\_attribute](#secret_attribute-3)
|
|
66
66
|
* [secret\_attribute](#secret_attribute-4)
|
|
67
|
+
* [secret\_attribute\_writable](#secret_attribute_writable)
|
|
67
68
|
* [private\_key\_attribute](#private_key_attribute)
|
|
68
69
|
* [public\_key\_attribute](#public_key_attribute)
|
|
69
70
|
* [number\_attribute](#number_attribute)
|
|
@@ -344,6 +345,10 @@ Type: [AttributeDefinition](#attributedefinition)
|
|
|
344
345
|
|
|
345
346
|
Type: [AttributeDefinition](#attributedefinition)
|
|
346
347
|
|
|
348
|
+
## secret\_attribute\_writable
|
|
349
|
+
|
|
350
|
+
Type: [AttributeDefinition](#attributedefinition)
|
|
351
|
+
|
|
347
352
|
## private\_key\_attribute
|
|
348
353
|
|
|
349
354
|
Type: [AttributeDefinition](#attributedefinition)
|
package/package.json
CHANGED
package/src/expression.mjs
CHANGED
|
@@ -71,8 +71,9 @@ function binopError(op, left, right) {
|
|
|
71
71
|
error(`Unexpected '${op.str || op}'`);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export function parse(input, context = {
|
|
75
|
-
|
|
74
|
+
export function parse(input, context = {}) {
|
|
75
|
+
const getGlobal = context?.getGlobal ?? (a => globals[a]);
|
|
76
|
+
input = tokens(input, context);
|
|
76
77
|
|
|
77
78
|
let node, token, value;
|
|
78
79
|
|
|
@@ -101,12 +102,12 @@ export function parse(input, context = { globals }) {
|
|
|
101
102
|
result = r;
|
|
102
103
|
} else {
|
|
103
104
|
if (result === undefined) {
|
|
104
|
-
result =
|
|
105
|
+
result = getGlobal(p);
|
|
105
106
|
} else {
|
|
106
107
|
if (result instanceof Map) {
|
|
107
108
|
result = result.get(p);
|
|
108
109
|
} else {
|
|
109
|
-
result = result[p] ??
|
|
110
|
+
result = result[p] ?? getGlobal(p);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
}
|
|
@@ -283,7 +284,7 @@ export function parse(input, context = { globals }) {
|
|
|
283
284
|
const args = node.path[1].map(a =>
|
|
284
285
|
typeof a === "object" ? a.eval(a, current) : a
|
|
285
286
|
);
|
|
286
|
-
return
|
|
287
|
+
return getGlobal(node.path[0])(...args);
|
|
287
288
|
};
|
|
288
289
|
|
|
289
290
|
advance();
|
package/src/tokens.mjs
CHANGED
|
@@ -56,7 +56,7 @@ export /** @type {Token} */ const DOUBLE_BAR = createToken("||", 30, "infixr");
|
|
|
56
56
|
export /** @type {Token} */ const IDENTIFIER = createToken("IDENTIFIER", 0);
|
|
57
57
|
export /** @type {Token} */ const EOF = createToken("EOF", -1, "eof");
|
|
58
58
|
|
|
59
|
-
const keywords = {
|
|
59
|
+
export const keywords = {
|
|
60
60
|
true: [true],
|
|
61
61
|
false: [false]
|
|
62
62
|
};
|
|
@@ -76,10 +76,14 @@ const esc = {
|
|
|
76
76
|
* @param {string} string
|
|
77
77
|
* @yields {Token}
|
|
78
78
|
*/
|
|
79
|
-
export function* tokens(string) {
|
|
79
|
+
export function* tokens(string, options = {}) {
|
|
80
|
+
options.keywords ||= keywords;
|
|
81
|
+
options.parseFloat ||= parseFloat;
|
|
82
|
+
|
|
80
83
|
let state, value, hex, quote;
|
|
81
84
|
|
|
82
|
-
const keywordOrIdentifier = () =>
|
|
85
|
+
const keywordOrIdentifier = () =>
|
|
86
|
+
options.keywords[value] || [IDENTIFIER, value];
|
|
83
87
|
const startString = c => {
|
|
84
88
|
value = "";
|
|
85
89
|
state = "string";
|
|
@@ -116,7 +120,7 @@ export function* tokens(string) {
|
|
|
116
120
|
case " ":
|
|
117
121
|
switch (state) {
|
|
118
122
|
case "number":
|
|
119
|
-
yield [parseFloat(value)];
|
|
123
|
+
yield [options.parseFloat(value)];
|
|
120
124
|
state = undefined;
|
|
121
125
|
case undefined:
|
|
122
126
|
break;
|
|
@@ -145,7 +149,7 @@ export function* tokens(string) {
|
|
|
145
149
|
case "'":
|
|
146
150
|
switch (state) {
|
|
147
151
|
case "number":
|
|
148
|
-
yield [parseFloat(value)];
|
|
152
|
+
yield [options.parseFloat(value)];
|
|
149
153
|
case undefined:
|
|
150
154
|
startString(c);
|
|
151
155
|
break;
|
|
@@ -173,7 +177,7 @@ export function* tokens(string) {
|
|
|
173
177
|
case "|":
|
|
174
178
|
switch (state) {
|
|
175
179
|
case "number":
|
|
176
|
-
yield [parseFloat(value)];
|
|
180
|
+
yield [options.parseFloat(value)];
|
|
177
181
|
case undefined:
|
|
178
182
|
state = c;
|
|
179
183
|
break;
|
|
@@ -204,7 +208,7 @@ export function* tokens(string) {
|
|
|
204
208
|
case "=":
|
|
205
209
|
switch (state) {
|
|
206
210
|
case "number":
|
|
207
|
-
yield [parseFloat(value)];
|
|
211
|
+
yield [options.parseFloat(value)];
|
|
208
212
|
case undefined:
|
|
209
213
|
state = c;
|
|
210
214
|
break;
|
|
@@ -222,12 +226,11 @@ export function* tokens(string) {
|
|
|
222
226
|
|
|
223
227
|
case ".":
|
|
224
228
|
if (state === "number") {
|
|
225
|
-
value +=
|
|
229
|
+
value += ".";
|
|
226
230
|
break;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
state="number";
|
|
231
|
+
} else if (state === "-") {
|
|
232
|
+
value = "-.";
|
|
233
|
+
state = "number";
|
|
231
234
|
break;
|
|
232
235
|
}
|
|
233
236
|
|
|
@@ -246,7 +249,7 @@ export function* tokens(string) {
|
|
|
246
249
|
case "}":
|
|
247
250
|
switch (state) {
|
|
248
251
|
case "number":
|
|
249
|
-
yield [parseFloat(value)];
|
|
252
|
+
yield [options.parseFloat(value)];
|
|
250
253
|
case undefined:
|
|
251
254
|
state = c;
|
|
252
255
|
break;
|
|
@@ -282,7 +285,7 @@ export function* tokens(string) {
|
|
|
282
285
|
case "-":
|
|
283
286
|
state = "number";
|
|
284
287
|
value = "-" + c;
|
|
285
|
-
|
|
288
|
+
break;
|
|
286
289
|
case ".":
|
|
287
290
|
state = "number";
|
|
288
291
|
value = ".";
|
|
@@ -297,7 +300,7 @@ export function* tokens(string) {
|
|
|
297
300
|
default:
|
|
298
301
|
switch (state) {
|
|
299
302
|
case "number":
|
|
300
|
-
yield [parseFloat(value)];
|
|
303
|
+
yield [options.parseFloat(value)];
|
|
301
304
|
case undefined:
|
|
302
305
|
state = "identifier";
|
|
303
306
|
value = c;
|
|
@@ -320,7 +323,7 @@ export function* tokens(string) {
|
|
|
320
323
|
case "string":
|
|
321
324
|
throw new Error("unterminated string", { cause: string });
|
|
322
325
|
case "number":
|
|
323
|
-
yield [parseFloat(value)];
|
|
326
|
+
yield [options.parseFloat(value)];
|
|
324
327
|
break;
|
|
325
328
|
case "identifier":
|
|
326
329
|
yield keywordOrIdentifier();
|
package/src/types.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { attributeIterator } from "./attributes.mjs";
|
|
2
|
-
import { parseDuration } from "./time.mjs";
|
|
2
|
+
import { parseDuration, formatDuration } from "./time.mjs";
|
|
3
3
|
import { parseBytes } from "./bytes.mjs";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -54,7 +54,8 @@ export const types = {
|
|
|
54
54
|
duration: {
|
|
55
55
|
name: "duration",
|
|
56
56
|
primitive: true,
|
|
57
|
-
toInternal: value => parseDuration(value)
|
|
57
|
+
toInternal: value => parseDuration(value),
|
|
58
|
+
toExternal: value => value === undefined ? undefined : formatDuration(value)
|
|
58
59
|
},
|
|
59
60
|
duration_ms: {
|
|
60
61
|
name: "duration_ms",
|
package/types/expression.d.mts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
export function binop(op: any, left: any, right: any, fallback: any): any;
|
|
2
|
-
export function parse(input: any, context?: {
|
|
3
|
-
globals: {
|
|
4
|
-
in: (a: any, b: any) => boolean;
|
|
5
|
-
ceil: (x: number) => number;
|
|
6
|
-
floor: (x: number) => number;
|
|
7
|
-
abs: (x: number) => number;
|
|
8
|
-
min: (...values: number[]) => number;
|
|
9
|
-
max: (...values: number[]) => number;
|
|
10
|
-
uppercase: (a: any) => any;
|
|
11
|
-
lowercase: (a: any) => any;
|
|
12
|
-
substring: (s: any, a: any, b: any) => any;
|
|
13
|
-
length: (s: any) => any;
|
|
14
|
-
};
|
|
15
|
-
}): any;
|
|
2
|
+
export function parse(input: any, context?: {}): any;
|
|
16
3
|
export namespace globals {
|
|
17
4
|
export function _in(a: any, b: any): boolean;
|
|
18
5
|
export { _in as in };
|
package/types/tokens.d.mts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {string} string
|
|
5
5
|
* @yields {Token}
|
|
6
6
|
*/
|
|
7
|
-
export function tokens(string: string): Generator<any, void, unknown>;
|
|
7
|
+
export function tokens(string: string, options?: {}): Generator<any, void, unknown>;
|
|
8
8
|
export namespace PLUS {
|
|
9
9
|
let str: string;
|
|
10
10
|
}
|
|
@@ -35,6 +35,12 @@ export namespace BAR { }
|
|
|
35
35
|
export namespace DOUBLE_BAR { }
|
|
36
36
|
export namespace IDENTIFIER { }
|
|
37
37
|
export namespace EOF { }
|
|
38
|
+
export namespace keywords {
|
|
39
|
+
let _true: boolean[];
|
|
40
|
+
export { _true as true };
|
|
41
|
+
let _false: boolean[];
|
|
42
|
+
export { _false as false };
|
|
43
|
+
}
|
|
38
44
|
export type Token = {
|
|
39
45
|
str: string;
|
|
40
46
|
};
|