spooder 5.1.4 → 5.1.6
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/bun.lock +1 -1
- package/package.json +4 -2
- package/src/api.ts +36 -31
package/bun.lock
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"packages": {
|
|
15
15
|
"@types/bun": ["@types/bun@1.2.19", "", { "dependencies": { "bun-types": "1.2.19" } }, "sha512-d9ZCmrH3CJ2uYKXQIUuZ/pUnTqIvLDS0SK7pFmbx8ma+ziH/FRMoAq5bYpRG7y+w1gl+HgyNZbtqgMq4W4e2Lg=="],
|
|
16
16
|
|
|
17
|
-
"@types/node": ["@types/node@24.0
|
|
17
|
+
"@types/node": ["@types/node@24.1.0", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w=="],
|
|
18
18
|
|
|
19
19
|
"@types/react": ["@types/react@19.1.8", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-AwAfQ2Wa5bCx9WP8nZL2uMZWod7J7/JSplxbTmBQ5ms6QpqNYm672H0Vu9ZVKVngQ+ii4R/byguVEUZQyeg44g=="],
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spooder",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.1.
|
|
4
|
+
"version": "5.1.6",
|
|
5
5
|
"module": "./src/api.ts",
|
|
6
6
|
"bin": {
|
|
7
7
|
"spooder": "./src/cli.ts"
|
|
8
8
|
},
|
|
9
|
+
"main": "./src/api.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"bun": "./src/api.ts",
|
|
12
|
-
"import": "./src/api.ts"
|
|
13
|
+
"import": "./src/api.ts",
|
|
14
|
+
"default": "./src/api.ts"
|
|
13
15
|
}
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
package/src/api.ts
CHANGED
|
@@ -431,41 +431,46 @@ export async function parse_template(template: string, replacements: Replacement
|
|
|
431
431
|
// Parse t-for tags first (outermost structures)
|
|
432
432
|
const for_regex = /<t-for\s+items="([^"]+)"\s+as="([^"]+)"\s*>(.*?)<\/t-for>/gs;
|
|
433
433
|
result = await replace_async(result, for_regex, async (match, entries_key, alias_name, loop_content) => {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (loop_entries !== undefined && Array.isArray(loop_entries)) {
|
|
437
|
-
let loop_result = '';
|
|
438
|
-
for (const loop_entry of loop_entries) {
|
|
439
|
-
let scoped_replacements: Replacements;
|
|
440
|
-
|
|
441
|
-
if (typeof replacements === 'function') {
|
|
442
|
-
scoped_replacements = async (key: string) => {
|
|
443
|
-
if (key === alias_name)
|
|
444
|
-
return loop_entry;
|
|
445
|
-
|
|
446
|
-
if (key.startsWith(alias_name + '.')) {
|
|
447
|
-
const prop_path = key.substring(alias_name.length + 1);
|
|
448
|
-
return get_nested_property(loop_entry, prop_path);
|
|
449
|
-
}
|
|
434
|
+
let loop_entries = is_replacer_fn ? await replacements(entries_key) : replacements[entries_key];
|
|
450
435
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
436
|
+
if (loop_entries !== undefined) {
|
|
437
|
+
if (typeof loop_entries === 'function')
|
|
438
|
+
loop_entries = await loop_entries();
|
|
439
|
+
|
|
440
|
+
if (Array.isArray(loop_entries)) {
|
|
441
|
+
let loop_result = '';
|
|
442
|
+
for (const loop_entry of loop_entries) {
|
|
443
|
+
let scoped_replacements: Replacements;
|
|
444
|
+
|
|
445
|
+
if (typeof replacements === 'function') {
|
|
446
|
+
scoped_replacements = async (key: string) => {
|
|
447
|
+
if (key === alias_name)
|
|
448
|
+
return loop_entry;
|
|
449
|
+
|
|
450
|
+
if (key.startsWith(alias_name + '.')) {
|
|
451
|
+
const prop_path = key.substring(alias_name.length + 1);
|
|
452
|
+
return get_nested_property(loop_entry, prop_path);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return await replacements(key);
|
|
456
|
+
};
|
|
457
|
+
} else {
|
|
458
|
+
scoped_replacements = {
|
|
459
|
+
...replacements,
|
|
460
|
+
[alias_name]: loop_entry
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
loop_result += await parse_template(loop_content, scoped_replacements, drop_missing);
|
|
458
465
|
}
|
|
459
|
-
|
|
460
|
-
loop_result += await parse_template(loop_content, scoped_replacements, drop_missing);
|
|
466
|
+
return loop_result;
|
|
461
467
|
}
|
|
462
|
-
return loop_result;
|
|
463
|
-
} else {
|
|
464
|
-
if (!drop_missing)
|
|
465
|
-
return match;
|
|
466
|
-
|
|
467
|
-
return '';
|
|
468
468
|
}
|
|
469
|
+
|
|
470
|
+
if (!drop_missing)
|
|
471
|
+
return match;
|
|
472
|
+
|
|
473
|
+
return '';
|
|
469
474
|
});
|
|
470
475
|
|
|
471
476
|
// Parse t-if tags
|