feed-common 1.21.0 → 1.22.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +15 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/utils.ts +60 -54
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [1.22.1](https://github.com/advertikon/package-maxify-feed-common/compare/v1.22.0...v1.22.1) (2024-07-28)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* fix metafield parser ([ded430a](https://github.com/advertikon/package-maxify-feed-common/commit/ded430a194d1ac20eb467cf60be94e291c6ae099))
|
7
|
+
|
8
|
+
# [1.22.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.21.0...v1.22.0) (2024-07-28)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* add metafield support to macro parser ([c85df83](https://github.com/advertikon/package-maxify-feed-common/commit/c85df83ecea5c6599afad706f99332646fc63e2b))
|
14
|
+
|
1
15
|
# [1.21.0](https://github.com/advertikon/package-maxify-feed-common/compare/v1.20.5...v1.21.0) (2024-07-28)
|
2
16
|
|
3
17
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,wBAAgB,IAAI,WAEnB;AAED,wBAAgB,iBAAiB,CAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,wBAAgB,IAAI,WAEnB;AAED,wBAAgB,iBAAiB,CAAE,WAAW,EAAE,MAAM,GAAG,aAAa,EAAE,CA4DvE"}
|
package/dist/utils/utils.js
CHANGED
@@ -7,10 +7,12 @@ export function parseMacrosString(textContent) {
|
|
7
7
|
let startPos = 0;
|
8
8
|
const parts = [];
|
9
9
|
if (!textContent) {
|
10
|
-
return [
|
10
|
+
return [
|
11
|
+
{
|
11
12
|
content: '',
|
12
13
|
type: 'string',
|
13
|
-
}
|
14
|
+
},
|
15
|
+
];
|
14
16
|
}
|
15
17
|
while (startPos !== -1 && startPos < textContent.length) {
|
16
18
|
const nextStartPos = textContent.indexOf(openTag, startPos);
|
@@ -40,10 +42,20 @@ export function parseMacrosString(textContent) {
|
|
40
42
|
parts.push({
|
41
43
|
content: tagValue.trim(),
|
42
44
|
type: 'macro',
|
43
|
-
subtype: tagValue
|
45
|
+
subtype: getMacroSubtype(tagValue),
|
44
46
|
});
|
45
47
|
startPos = nextEndPos + closeTag.length;
|
46
48
|
}
|
47
49
|
return parts;
|
48
50
|
}
|
51
|
+
function getMacroSubtype(tagValue) {
|
52
|
+
switch (tagValue.trim().split('.')[0]) {
|
53
|
+
case 'action':
|
54
|
+
return 'action';
|
55
|
+
case 'metafield':
|
56
|
+
return 'metafield';
|
57
|
+
default:
|
58
|
+
return 'mapping';
|
59
|
+
}
|
60
|
+
}
|
49
61
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI;
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI;IAChB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAE,WAAmB;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC;IACrB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CACX,6DAA6D,WAAW,mBAAmB,YAAY,EAAE,CAC5G,CAAC;QACN,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAElF,KAAK,CAAC,IAAI,CAAC;YACP,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE;YACxB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC;SACrC,CAAC,CAAC;QAEH,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC5C,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAE,QAAgB;IACtC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,KAAK,QAAQ;YACT,OAAO,QAAQ,CAAC;QACpB,KAAK,WAAW;YACZ,OAAO,WAAW,CAAC;QACvB;YACI,OAAO,SAAS,CAAC;IACzB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/utils/utils.ts
CHANGED
@@ -1,72 +1,78 @@
|
|
1
1
|
import { MacroPartType } from '../types/profile.types.js';
|
2
2
|
|
3
3
|
export function code () {
|
4
|
-
|
4
|
+
return (Math.random() * 1000000).toFixed(0);
|
5
5
|
}
|
6
6
|
|
7
7
|
export function parseMacrosString (textContent: string): MacroPartType[] {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
const openTag = '{{';
|
9
|
+
const closeTag = '}}';
|
10
|
+
let startPos = 0;
|
11
|
+
const parts: MacroPartType[] = [];
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
if (!textContent) {
|
14
|
+
return [
|
15
|
+
{
|
16
|
+
content: '',
|
17
|
+
type: 'string',
|
18
|
+
},
|
19
|
+
];
|
20
|
+
}
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
while (startPos !== -1 && startPos < textContent.length) {
|
23
|
+
const nextStartPos = textContent.indexOf(openTag, startPos);
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
if (nextStartPos === -1) {
|
26
|
+
parts.push({
|
27
|
+
content: textContent.substring(startPos),
|
28
|
+
type: 'string',
|
29
|
+
});
|
30
|
+
break;
|
31
|
+
} else if (nextStartPos > startPos) {
|
32
|
+
parts.push({
|
33
|
+
content: textContent.substring(startPos, nextStartPos),
|
34
|
+
type: 'string',
|
35
|
+
});
|
36
|
+
}
|
35
37
|
|
36
|
-
|
38
|
+
const nextEndPos = textContent.indexOf(closeTag, nextStartPos);
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
if (nextEndPos === -1) {
|
41
|
+
throw new Error(
|
42
|
+
`[TAG PARSER] Cannot find closing tag for string '${textContent}' starting from ${nextStartPos}`
|
43
|
+
);
|
44
|
+
}
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
openTag,
|
47
|
-
nextStartPos + openTag.length
|
48
|
-
);
|
46
|
+
// console.log('check for nex opening tag', textContent.indexOf(openTag, nextStartPos + openTag.length))
|
47
|
+
const checkNextOpeningTag = textContent.indexOf(openTag, nextStartPos + openTag.length);
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
if (checkNextOpeningTag !== -1 && checkNextOpeningTag < nextEndPos) {
|
50
|
+
throw new Error(
|
51
|
+
`[TAG PARSER] Expecting closing tag, found opening tag in '${textContent}' starting from ${nextStartPos}`
|
52
|
+
);
|
53
|
+
}
|
55
54
|
|
56
|
-
|
57
|
-
nextStartPos + openTag.length,
|
58
|
-
nextEndPos
|
59
|
-
);
|
55
|
+
const tagValue = textContent.substring(nextStartPos + openTag.length, nextEndPos);
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
});
|
57
|
+
parts.push({
|
58
|
+
content: tagValue.trim(),
|
59
|
+
type: 'macro',
|
60
|
+
subtype: getMacroSubtype(tagValue),
|
61
|
+
});
|
67
62
|
|
68
|
-
|
69
|
-
|
63
|
+
startPos = nextEndPos + closeTag.length;
|
64
|
+
}
|
65
|
+
|
66
|
+
return parts;
|
67
|
+
}
|
70
68
|
|
71
|
-
|
69
|
+
function getMacroSubtype (tagValue: string): MacroPartType['subtype'] {
|
70
|
+
switch (tagValue.trim().split('.')[0]) {
|
71
|
+
case 'action':
|
72
|
+
return 'action';
|
73
|
+
case 'metafield':
|
74
|
+
return 'metafield';
|
75
|
+
default:
|
76
|
+
return 'mapping';
|
77
|
+
}
|
72
78
|
}
|