@c-time/frelio-data-json-generator 3.7.2 → 3.9.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/dist/cli.js +23 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/preview/index.js +23 -2
- package/dist/preview/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -463,7 +463,8 @@ function formatValue(value, type, options = {}) {
|
|
|
463
463
|
case "last":
|
|
464
464
|
return Array.isArray(value) ? value[value.length - 1] : value;
|
|
465
465
|
case "join":
|
|
466
|
-
|
|
466
|
+
if (!Array.isArray(value)) return String(value);
|
|
467
|
+
return (options.key ? pluckValues(value, options.key) : value).join(options.separator ?? ", ");
|
|
467
468
|
case "url":
|
|
468
469
|
return encodeURIComponent(String(value));
|
|
469
470
|
case "picture":
|
|
@@ -475,6 +476,18 @@ function formatValue(value, type, options = {}) {
|
|
|
475
476
|
return value;
|
|
476
477
|
}
|
|
477
478
|
}
|
|
479
|
+
function pluckValues(items, key) {
|
|
480
|
+
const parts = key.split(".");
|
|
481
|
+
const result = [];
|
|
482
|
+
for (const item of items) {
|
|
483
|
+
let v = item;
|
|
484
|
+
for (const part of parts) {
|
|
485
|
+
v = v !== null && typeof v === "object" ? v[part] : void 0;
|
|
486
|
+
}
|
|
487
|
+
if (v !== void 0 && v !== null && v !== "") result.push(v);
|
|
488
|
+
}
|
|
489
|
+
return result;
|
|
490
|
+
}
|
|
478
491
|
function parseOffsetMinutes(timezone) {
|
|
479
492
|
if (timezone === "Z") return 0;
|
|
480
493
|
const m = /^([+-])(\d{2}):(\d{2})$/.exec(timezone);
|
|
@@ -745,16 +758,24 @@ function inferLegacyType(field) {
|
|
|
745
758
|
return field;
|
|
746
759
|
}
|
|
747
760
|
function applyTransformField(field, content, currentData, defaultTimezone) {
|
|
748
|
-
|
|
761
|
+
let sourceValue = resolveSourceExpression(field.source, content, currentData);
|
|
762
|
+
if (field.fallbackSource !== void 0 && isEmptySourceValue(sourceValue)) {
|
|
763
|
+
sourceValue = resolveSourceExpression(field.fallbackSource, content, currentData);
|
|
764
|
+
}
|
|
749
765
|
return formatValue(sourceValue, field.type, {
|
|
750
766
|
format: field.format,
|
|
751
767
|
timezone: field.timezone ?? defaultTimezone,
|
|
752
768
|
length: field.length,
|
|
753
769
|
suffix: field.suffix,
|
|
754
770
|
separator: field.separator,
|
|
771
|
+
key: field.key,
|
|
755
772
|
defaultValue: field.defaultValue
|
|
756
773
|
});
|
|
757
774
|
}
|
|
775
|
+
function isEmptySourceValue(value) {
|
|
776
|
+
if (value === void 0 || value === null) return true;
|
|
777
|
+
return typeof value === "string" && value.trim() === "";
|
|
778
|
+
}
|
|
758
779
|
function resolveSourceExpression(source, content, currentData) {
|
|
759
780
|
const singleVarMatch = source.match(/^\{\$this\.([^}]+)\}$/);
|
|
760
781
|
if (singleVarMatch) {
|