pacc 4.24.1 → 4.25.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/README.md CHANGED
@@ -125,6 +125,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
125
125
  * [DOUBLE\_AMPERSAND](#double_ampersand)
126
126
  * [BAR](#bar)
127
127
  * [DOUBLE\_BAR](#double_bar)
128
+ * [IDENTIFIER](#identifier)
128
129
  * [EOF](#eof)
129
130
 
130
131
  ## prepareAttributesDefinitions
@@ -571,6 +572,10 @@ Type: [Token](#token)
571
572
 
572
573
  Type: [Token](#token)
573
574
 
575
+ ## IDENTIFIER
576
+
577
+ Type: [Token](#token)
578
+
574
579
  ## EOF
575
580
 
576
581
  Type: [Token](#token)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.24.1",
3
+ "version": "4.25.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -32,7 +32,7 @@ export const types = {
32
32
  /**
33
33
  * Create attributes from its definition.
34
34
  * @param {Object} newDefinitions
35
- * @param {Object} [presentDefinitions] optional merg in attributes
35
+ * @param {Object} [presentDefinitions] optional merge in attributes
36
36
  * @return {Object} attributes
37
37
  */
38
38
  export function prepareAttributesDefinitions(
package/src/expand.mjs CHANGED
@@ -2,9 +2,20 @@ import { parse } from "./expression.mjs";
2
2
 
3
3
  const maxNestingLevel = 5;
4
4
 
5
- export function expand(object, context) {
5
+ /**
6
+ *
7
+ * @param {any} object
8
+ * @param {Object} context
9
+ * @param {any} context.root
10
+ * @param {function} context.stopClass
11
+ * @returns {any}
12
+ */
13
+ export function expand(object, context = {}) {
6
14
  const promises = [];
7
15
 
16
+ const leadIn = context.leadIn ?? "${";
17
+ const leadOut = context.leadOut ?? "}";
18
+
8
19
  function _expand(object, path) {
9
20
  if (path.length >= maxNestingLevel) {
10
21
  throw new Error(
@@ -13,27 +24,70 @@ export function expand(object, context) {
13
24
  }
14
25
 
15
26
  if (typeof object === "string" || object instanceof String) {
16
- let wholeValue;
27
+ let result = "";
17
28
 
18
29
  const localPromises = [];
30
+
31
+ let cur = 0;
32
+ let start;
33
+
34
+ while ((start = object.indexOf(leadIn, cur)) >= 0) {
35
+ const end = object.indexOf(leadOut, cur + leadIn.length);
36
+
37
+ if (end >= 0) {
38
+ const expression = object.substring(start + leadIn.length, end);
39
+
40
+ let value = parse(expression, context);
41
+ if (value === undefined) {
42
+ result += object.substring(start, end + leadOut.length);
43
+ } else {
44
+ if (typeof value === "string") {
45
+ value = _expand(value, path);
46
+ }
47
+ if (value instanceof Promise) {
48
+ localPromises.push(value);
49
+ value = localPromises.length - 1;
50
+ }
51
+
52
+ if (start === 0 && end === object.length - leadOut.length) {
53
+ return value;
54
+ }
55
+ result += object.substring(cur, start) + value;
56
+ }
57
+
58
+ cur = end + leadOut.length;
59
+ } else {
60
+ throw new Error(
61
+ `Unterminated expression between '${leadIn}' and '${leadOut}'`
62
+ );
63
+ }
64
+ }
65
+
66
+ result += object.substring(cur);
67
+
68
+ return result;
69
+ /*
19
70
  const v = object.replace(
20
71
  /\$\{([^\}]*)\}/g,
21
72
  (match, expression, offset, string) => {
22
- let value = parse(expression,context);
73
+ let value = parse(expression, context);
23
74
 
24
75
  if (typeof value === "string" || value instanceof String) {
25
76
  value = _expand(value, path);
26
77
  } else if (value === undefined) {
27
- value = "${" + expression + "}";
78
+ value = leadIn + expression + leadOut;
28
79
  }
29
- if (string.length === expression.length + 3) {
80
+ if (
81
+ string.length ===
82
+ expression.length + leadIn.length + leadOut.length
83
+ ) {
30
84
  wholeValue = value;
31
85
  return "";
32
86
  }
33
87
 
34
88
  if (value instanceof Promise) {
35
89
  localPromises.push(value);
36
- return "${" + (localPromises.length - 1) + "}";
90
+ return leadIn + (localPromises.length - 1) + leadOut;
37
91
  }
38
92
  return value;
39
93
  }
@@ -50,6 +104,7 @@ export function expand(object, context) {
50
104
  }
51
105
 
52
106
  return v;
107
+ */
53
108
  }
54
109
 
55
110
  switch (typeof object) {
@@ -114,7 +169,7 @@ export function expand(object, context) {
114
169
  return array;
115
170
  }
116
171
 
117
- if(object instanceof context.stopClass) {
172
+ if (context.stopClass && object instanceof context.stopClass) {
118
173
  return object;
119
174
  }
120
175
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Create attributes from its definition.
3
3
  * @param {Object} newDefinitions
4
- * @param {Object} [presentDefinitions] optional merg in attributes
4
+ * @param {Object} [presentDefinitions] optional merge in attributes
5
5
  * @return {Object} attributes
6
6
  */
7
7
  export function prepareAttributesDefinitions(newDefinitions: any, presentDefinitions?: any): any;
@@ -1 +1,12 @@
1
- export function expand(object: any, context: any): any;
1
+ /**
2
+ *
3
+ * @param {any} object
4
+ * @param {Object} context
5
+ * @param {any} context.root
6
+ * @param {function} context.stopClass
7
+ * @returns {any}
8
+ */
9
+ export function expand(object: any, context?: {
10
+ root: any;
11
+ stopClass: Function;
12
+ }): any;