pacc 4.19.0 → 4.20.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/package.json +1 -1
- package/src/expand.mjs +33 -0
- package/src/expression.mjs +2 -0
- package/src/module.mjs +1 -0
- package/types/expand.d.mts +1 -0
- package/types/module.d.mts +1 -0
package/package.json
CHANGED
package/src/expand.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parse } from "./expression.mjs";
|
|
2
|
+
import { tokens } from "./tokens.mjs";
|
|
3
|
+
|
|
4
|
+
export function expand(object, context) {
|
|
5
|
+
switch (typeof object) {
|
|
6
|
+
case "string":
|
|
7
|
+
return object.replaceAll(/\$\{([^\}]*)\}/g, (match, m1) => {
|
|
8
|
+
context.tokens = tokens(m1);
|
|
9
|
+
return parse(context) ?? "${" + m1 + "}";
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
case "object":
|
|
13
|
+
if (object instanceof Map) {
|
|
14
|
+
return new Map(
|
|
15
|
+
[...object].map(([k, v]) => [expand(k, context), expand(v, context)])
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (object instanceof Set) {
|
|
20
|
+
return new Set([...object].map(e => expand(e, context)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(object)) {
|
|
24
|
+
return object.map(e => expand(e, context));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return Object.fromEntries(
|
|
28
|
+
Object.entries(object).map(([k, v]) => [k, expand(v, context)])
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return object;
|
|
33
|
+
}
|
package/src/expression.mjs
CHANGED
|
@@ -172,8 +172,10 @@ export function parse(context) {
|
|
|
172
172
|
|
|
173
173
|
case "infix": {
|
|
174
174
|
let right = expression(token.precedence);
|
|
175
|
+
|
|
175
176
|
if (typeof left === typeof right) {
|
|
176
177
|
switch (typeof left) {
|
|
178
|
+
case "string":
|
|
177
179
|
case "number":
|
|
178
180
|
case "bigint":
|
|
179
181
|
return binop(token, left, right, binopError);
|
package/src/module.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function expand(object: any, context: any): any;
|
package/types/module.d.mts
CHANGED