xnl-core 0.1.2 → 0.1.4
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/index.cjs +227 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +227 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -545,24 +545,24 @@ function isDocument(value) {
|
|
|
545
545
|
}
|
|
546
546
|
function serializeNode(node, state) {
|
|
547
547
|
if (isComment(node)) {
|
|
548
|
-
const
|
|
549
|
-
return `${
|
|
548
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
549
|
+
return `${pad2}<!-- ${node.value} -->`;
|
|
550
550
|
}
|
|
551
551
|
if (isElement(node)) {
|
|
552
|
-
const
|
|
552
|
+
const pad2 = state.pretty ? state.indent.repeat(state.depth) : "";
|
|
553
553
|
if (node.kind === "TextElement") {
|
|
554
554
|
const metaStr2 = serializeInlineAttributes(node.metadata, state);
|
|
555
555
|
const attrStr = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
556
556
|
const idPart2 = node.id ? ` #${formatWord(node.id)}` : "";
|
|
557
557
|
const marker = node.textMarker ?? "";
|
|
558
|
-
return `${
|
|
558
|
+
return `${pad2}<${node.tag}${idPart2}${metaStr2}${attrStr} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
559
559
|
}
|
|
560
560
|
const metaStr = serializeInlineAttributes(node.metadata, state);
|
|
561
561
|
const attrPart = node.attributes ? ` ${serializeAttributeBlock(node.attributes, state)}` : "";
|
|
562
562
|
const bodyPart = node.body ? ` ${serializeArrayBlock(node.body, state)}` : "";
|
|
563
563
|
const extendPart = node.extend ? ` ${serializeExtendBlock(node.extend, state)}` : "";
|
|
564
564
|
const idPart = node.id ? ` #${formatWord(node.id)}` : "";
|
|
565
|
-
return `${
|
|
565
|
+
return `${pad2}<${node.tag}${idPart}${metaStr}${attrPart}${bodyPart}${extendPart}>`;
|
|
566
566
|
}
|
|
567
567
|
if (Array.isArray(node)) {
|
|
568
568
|
return serializeArrayLiteral(node, state);
|
|
@@ -585,9 +585,9 @@ function serializeAttributeBlock(attrs, state) {
|
|
|
585
585
|
return `{ ${entries} }`;
|
|
586
586
|
}
|
|
587
587
|
const nextDepth = state.depth + 1;
|
|
588
|
-
const
|
|
588
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
589
589
|
const lines = Object.entries(attrs).map(
|
|
590
|
-
([k, v]) => `${
|
|
590
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
591
591
|
);
|
|
592
592
|
const closingPad = state.indent.repeat(state.depth);
|
|
593
593
|
return `{
|
|
@@ -600,8 +600,8 @@ function serializeArrayBlock(items, state) {
|
|
|
600
600
|
return `[ ${serialized} ]`;
|
|
601
601
|
}
|
|
602
602
|
const nextDepth = state.depth + 1;
|
|
603
|
-
const
|
|
604
|
-
const lines = items.map((item) => `${
|
|
603
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
604
|
+
const lines = items.map((item) => `${pad2}${serializeValueNode(item, { ...state, depth: nextDepth })}`);
|
|
605
605
|
const closingPad = state.indent.repeat(state.depth);
|
|
606
606
|
return `[
|
|
607
607
|
${lines.join("\n")}
|
|
@@ -613,8 +613,8 @@ function serializeExtendBlock(extend, state) {
|
|
|
613
613
|
return `( ${children} )`;
|
|
614
614
|
}
|
|
615
615
|
const nextDepth = state.depth + 1;
|
|
616
|
-
const
|
|
617
|
-
const childStrings = extend.order.map((name) => `${
|
|
616
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
617
|
+
const childStrings = extend.order.map((name) => `${pad2}${serializeNode(extend.children[name], { ...state, depth: nextDepth })}`);
|
|
618
618
|
const closingPad = state.indent.repeat(state.depth);
|
|
619
619
|
return `(
|
|
620
620
|
${childStrings.join("\n")}
|
|
@@ -638,9 +638,9 @@ function serializeObjectLiteral(obj, state) {
|
|
|
638
638
|
return `{ ${Object.entries(obj).map(([k, v]) => `${serializeKey(k)} = ${serializeValueNode(v, state)}`).join(" ")} }`;
|
|
639
639
|
}
|
|
640
640
|
const nextDepth = state.depth + 1;
|
|
641
|
-
const
|
|
641
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
642
642
|
const lines = Object.entries(obj).map(
|
|
643
|
-
([k, v]) => `${
|
|
643
|
+
([k, v]) => `${pad2}${serializeKey(k)} = ${serializeValueNode(v, { ...state, depth: nextDepth })}`
|
|
644
644
|
);
|
|
645
645
|
const closingPad = state.indent.repeat(state.depth);
|
|
646
646
|
return `{
|
|
@@ -652,8 +652,8 @@ function serializeArrayLiteral(arr, state) {
|
|
|
652
652
|
return `[${arr.map((v) => serializeValueNode(v, state)).join(" ")}]`;
|
|
653
653
|
}
|
|
654
654
|
const nextDepth = state.depth + 1;
|
|
655
|
-
const
|
|
656
|
-
const lines = arr.map((v) => `${
|
|
655
|
+
const pad2 = state.indent.repeat(nextDepth);
|
|
656
|
+
const lines = arr.map((v) => `${pad2}${serializeValueNode(v, { ...state, depth: nextDepth })}`);
|
|
657
657
|
const closingPad = state.indent.repeat(state.depth);
|
|
658
658
|
return `[
|
|
659
659
|
${lines.join("\n")}
|
|
@@ -679,6 +679,191 @@ function formatWord(word) {
|
|
|
679
679
|
return wordToString(word) ?? "";
|
|
680
680
|
}
|
|
681
681
|
|
|
682
|
+
// src/lineBlockFormatter.ts
|
|
683
|
+
var ULID_ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
684
|
+
var lastUlidTime = -1;
|
|
685
|
+
var lastUlidRandom = [];
|
|
686
|
+
function stringify2(value, options = {}) {
|
|
687
|
+
const state = {
|
|
688
|
+
indent: typeof options.indent === "string" ? options.indent : " ".repeat(options.indent ?? 2),
|
|
689
|
+
depth: 0,
|
|
690
|
+
textMarkerFactory: options.textMarkerFactory ?? makeUlid
|
|
691
|
+
};
|
|
692
|
+
if (isDocument2(value)) {
|
|
693
|
+
return value.nodes.map((node) => serializeNode2(node, state)).join("\n");
|
|
694
|
+
}
|
|
695
|
+
return serializeNode2(value, state);
|
|
696
|
+
}
|
|
697
|
+
function serializeNode2(node, state) {
|
|
698
|
+
if (isComment2(node)) return `${pad(state)}<!-- ${node.value} -->`;
|
|
699
|
+
if (isElement2(node)) return serializeElement(node, state);
|
|
700
|
+
return `${pad(state)}${serializeInlineValue(node, state)}`;
|
|
701
|
+
}
|
|
702
|
+
function serializeElement(node, state) {
|
|
703
|
+
if (node.kind === "TextElement") return serializeTextElement(node, state);
|
|
704
|
+
return serializeDataElement(node, state);
|
|
705
|
+
}
|
|
706
|
+
function serializeTextElement(node, state) {
|
|
707
|
+
const marker = node.textMarker ?? state.textMarkerFactory();
|
|
708
|
+
const open = [
|
|
709
|
+
`<${node.tag}`,
|
|
710
|
+
serializeId(node.id),
|
|
711
|
+
serializeMetadata(node.metadata, state),
|
|
712
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : "",
|
|
713
|
+
` ?${marker}>`
|
|
714
|
+
].join("");
|
|
715
|
+
const text = node.text ?? "";
|
|
716
|
+
const currentPad = pad(state);
|
|
717
|
+
const alignedText = text.replace(/\r?\n/g, (lineBreak) => `${lineBreak}${currentPad}`);
|
|
718
|
+
return `${currentPad}${open}${alignedText}</?${marker}>`;
|
|
719
|
+
}
|
|
720
|
+
function serializeDataElement(node, state) {
|
|
721
|
+
const open = [
|
|
722
|
+
`<${node.tag}`,
|
|
723
|
+
serializeId(node.id),
|
|
724
|
+
serializeMetadata(node.metadata, state),
|
|
725
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
726
|
+
].join("");
|
|
727
|
+
const sections = [];
|
|
728
|
+
if (node.body) sections.push(serializeArrayBlock2(node.body, state));
|
|
729
|
+
if (node.extend) sections.push(serializeExtendBlock2(node.extend, state));
|
|
730
|
+
if (sections.length === 0) return `${pad(state)}${open}>`;
|
|
731
|
+
if (sections.length === 1) return `${pad(state)}${open} ${sections[0]}>`;
|
|
732
|
+
return `${pad(state)}${open} ${sections.join(" ")}>`;
|
|
733
|
+
}
|
|
734
|
+
function serializeArrayBlock2(items, state) {
|
|
735
|
+
if (items.length === 0) return "[]";
|
|
736
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
737
|
+
const lines = items.map((item) => serializeNode2(item, nextState));
|
|
738
|
+
return `[
|
|
739
|
+
${lines.join("\n")}
|
|
740
|
+
${pad(state)}]`;
|
|
741
|
+
}
|
|
742
|
+
function serializeExtendBlock2(extend, state) {
|
|
743
|
+
if (extend.order.length === 0) return "()";
|
|
744
|
+
const nextState = { ...state, depth: state.depth + 1 };
|
|
745
|
+
const lines = extend.order.map((name) => serializeElement(extend.children[name], nextState));
|
|
746
|
+
return `(
|
|
747
|
+
${lines.join("\n")}
|
|
748
|
+
${pad(state)})`;
|
|
749
|
+
}
|
|
750
|
+
function serializeMetadata(attrs, state) {
|
|
751
|
+
const entries = Object.entries(attrs);
|
|
752
|
+
if (entries.length === 0) return "";
|
|
753
|
+
return " " + entries.map(([key, value]) => `${serializeKey2(key)}=${serializeInlineValue(value, state)}`).join(" ");
|
|
754
|
+
}
|
|
755
|
+
function serializeAttributeBlock2(attrs, state) {
|
|
756
|
+
const entries = Object.entries(attrs).map(([key, value]) => `${serializeKey2(key)} = ${serializeInlineValue(value, state)}`).join(" ");
|
|
757
|
+
return `{ ${entries} }`;
|
|
758
|
+
}
|
|
759
|
+
function serializeInlineValue(value, state) {
|
|
760
|
+
if (isComment2(value)) return `<!-- ${value.value} -->`;
|
|
761
|
+
if (isElement2(value)) return serializeInlineElement(value, state);
|
|
762
|
+
if (isWord(value)) return formatWord2(value);
|
|
763
|
+
if (Array.isArray(value)) return serializeInlineArray(value, state);
|
|
764
|
+
if (isPlainObject2(value)) return serializeInlineObject(value, state);
|
|
765
|
+
return serializePrimitive2(value);
|
|
766
|
+
}
|
|
767
|
+
function serializeInlineElement(node, state) {
|
|
768
|
+
const marker = node.kind === "TextElement" ? node.textMarker ?? state.textMarkerFactory() : void 0;
|
|
769
|
+
const open = [
|
|
770
|
+
`<${node.tag}`,
|
|
771
|
+
serializeId(node.id),
|
|
772
|
+
serializeMetadata(node.metadata, state),
|
|
773
|
+
node.attributes ? ` ${serializeAttributeBlock2(node.attributes, state)}` : ""
|
|
774
|
+
].join("");
|
|
775
|
+
if (node.kind === "TextElement") return `${open} ?${marker}>${node.text ?? ""}</?${marker}>`;
|
|
776
|
+
const sections = [];
|
|
777
|
+
if (node.body) sections.push(serializeInlineArrayBlock(node.body, state));
|
|
778
|
+
if (node.extend) sections.push(serializeInlineExtendBlock(node.extend, state));
|
|
779
|
+
if (sections.length === 0) return `${open}>`;
|
|
780
|
+
return `${open} ${sections.join(" ")}>`;
|
|
781
|
+
}
|
|
782
|
+
function serializeInlineArrayBlock(items, state) {
|
|
783
|
+
return `[ ${items.map((item) => serializeInlineValue(item, state)).join(" ")} ]`;
|
|
784
|
+
}
|
|
785
|
+
function serializeInlineExtendBlock(extend, state) {
|
|
786
|
+
return `( ${extend.order.map((name) => serializeInlineElement(extend.children[name], state)).join(" ")} )`;
|
|
787
|
+
}
|
|
788
|
+
function serializeInlineObject(value, state) {
|
|
789
|
+
const entries = Object.entries(value).map(([key, child]) => `${serializeKey2(key)} = ${serializeInlineValue(child, state)}`).join(" ");
|
|
790
|
+
return `{ ${entries} }`;
|
|
791
|
+
}
|
|
792
|
+
function serializeInlineArray(value, state) {
|
|
793
|
+
return `[${value.map((child) => serializeInlineValue(child, state)).join(" ")}]`;
|
|
794
|
+
}
|
|
795
|
+
function serializePrimitive2(value) {
|
|
796
|
+
if (value === null) return "null";
|
|
797
|
+
if (typeof value === "string") return `"${escapeString2(value)}"`;
|
|
798
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
799
|
+
return String(value);
|
|
800
|
+
}
|
|
801
|
+
function serializeId(id) {
|
|
802
|
+
const value = formatWord2(id);
|
|
803
|
+
return value ? ` #${value}` : "";
|
|
804
|
+
}
|
|
805
|
+
function formatWord2(word) {
|
|
806
|
+
return wordToString(word) ?? "";
|
|
807
|
+
}
|
|
808
|
+
function serializeKey2(key) {
|
|
809
|
+
if (/^[A-Za-z_][A-Za-z0-9_-]*$/.test(key)) return key;
|
|
810
|
+
return `"${escapeString2(key)}"`;
|
|
811
|
+
}
|
|
812
|
+
function escapeString2(value) {
|
|
813
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\t/g, "\\t").replace(/\r/g, "\\r");
|
|
814
|
+
}
|
|
815
|
+
function pad(state) {
|
|
816
|
+
return state.indent.repeat(state.depth);
|
|
817
|
+
}
|
|
818
|
+
function isDocument2(value) {
|
|
819
|
+
return value && Array.isArray(value.nodes);
|
|
820
|
+
}
|
|
821
|
+
function isElement2(value) {
|
|
822
|
+
return typeof value === "object" && value !== null && (value.kind === "DataElement" || value.kind === "TextElement");
|
|
823
|
+
}
|
|
824
|
+
function isComment2(value) {
|
|
825
|
+
return typeof value === "object" && value !== null && value.kind === "Comment";
|
|
826
|
+
}
|
|
827
|
+
function isPlainObject2(value) {
|
|
828
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
829
|
+
const kind = value.kind;
|
|
830
|
+
return kind !== "DataElement" && kind !== "TextElement" && kind !== "Comment" && kind !== "Word";
|
|
831
|
+
}
|
|
832
|
+
function makeUlid(now = Date.now()) {
|
|
833
|
+
if (now > lastUlidTime) {
|
|
834
|
+
lastUlidTime = now;
|
|
835
|
+
lastUlidRandom = nextRandom();
|
|
836
|
+
} else {
|
|
837
|
+
lastUlidRandom = incrementRandom(lastUlidRandom);
|
|
838
|
+
}
|
|
839
|
+
return encodeTime(lastUlidTime, 10) + encodeRandom(lastUlidRandom);
|
|
840
|
+
}
|
|
841
|
+
function encodeTime(time, length) {
|
|
842
|
+
let out = "";
|
|
843
|
+
for (let index = length - 1; index >= 0; index--) {
|
|
844
|
+
out = ULID_ENCODING.charAt(time % 32) + out;
|
|
845
|
+
time = Math.floor(time / 32);
|
|
846
|
+
}
|
|
847
|
+
return out;
|
|
848
|
+
}
|
|
849
|
+
function encodeRandom(values) {
|
|
850
|
+
return values.map((value) => ULID_ENCODING.charAt(value)).join("");
|
|
851
|
+
}
|
|
852
|
+
function nextRandom() {
|
|
853
|
+
return Array.from({ length: 16 }, () => Math.random() * 32 | 0);
|
|
854
|
+
}
|
|
855
|
+
function incrementRandom(values) {
|
|
856
|
+
const next = [...values];
|
|
857
|
+
for (let index = next.length - 1; index >= 0; index--) {
|
|
858
|
+
if (next[index] < 31) {
|
|
859
|
+
next[index] += 1;
|
|
860
|
+
return next;
|
|
861
|
+
}
|
|
862
|
+
next[index] = 0;
|
|
863
|
+
}
|
|
864
|
+
return next;
|
|
865
|
+
}
|
|
866
|
+
|
|
682
867
|
// src/path/index.ts
|
|
683
868
|
var XnlPathError = class extends Error {
|
|
684
869
|
};
|
|
@@ -774,7 +959,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
774
959
|
current = current[item.value];
|
|
775
960
|
} else if (current && isTextElement(current)) {
|
|
776
961
|
current = current[item.value];
|
|
777
|
-
} else if (
|
|
962
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
778
963
|
current = current[item.value];
|
|
779
964
|
} else {
|
|
780
965
|
if (strict) throw new XnlPathError(`InstanceProperty '${item.value}' not allowed on current node`);
|
|
@@ -792,7 +977,7 @@ function resolvePath(target, path, options = {}) {
|
|
|
792
977
|
current = child;
|
|
793
978
|
continue;
|
|
794
979
|
}
|
|
795
|
-
if (!
|
|
980
|
+
if (!isPlainObject3(current)) {
|
|
796
981
|
if (strict) throw new XnlPathError("MapKey requires a map/object target");
|
|
797
982
|
return void 0;
|
|
798
983
|
}
|
|
@@ -890,7 +1075,7 @@ function deleteAtPath(target, path, options = {}) {
|
|
|
890
1075
|
const { parent, last } = getParentAndLast(target, parsed, { strict, createMissing: false });
|
|
891
1076
|
switch (last.type) {
|
|
892
1077
|
case "InstanceProperty":
|
|
893
|
-
if (
|
|
1078
|
+
if (isPlainObject3(parent) || isDataElement(parent) || isTextElement(parent) || isDocument3(parent)) {
|
|
894
1079
|
if (!(last.value in parent) && strict) {
|
|
895
1080
|
throw new XnlPathError(`InstanceProperty '${last.value}' not found`);
|
|
896
1081
|
}
|
|
@@ -974,8 +1159,8 @@ function getParentAndLast(target, path, opts) {
|
|
|
974
1159
|
current = current[item.value];
|
|
975
1160
|
} else if (current && isTextElement(current)) {
|
|
976
1161
|
current = current[item.value];
|
|
977
|
-
} else if (
|
|
978
|
-
if (current[item.value] === void 0 && createMissing &&
|
|
1162
|
+
} else if (isPlainObject3(current) || isDocument3(current)) {
|
|
1163
|
+
if (current[item.value] === void 0 && createMissing && isPlainObject3(current)) {
|
|
979
1164
|
current[item.value] = {};
|
|
980
1165
|
}
|
|
981
1166
|
current = current[item.value];
|
|
@@ -1087,7 +1272,7 @@ function readWhile(input, start, pred) {
|
|
|
1087
1272
|
return out;
|
|
1088
1273
|
}
|
|
1089
1274
|
function findByUniqueName(target, id) {
|
|
1090
|
-
const roots =
|
|
1275
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1091
1276
|
for (const root of roots) {
|
|
1092
1277
|
const found = findInNode(root, id);
|
|
1093
1278
|
if (found) return found;
|
|
@@ -1096,7 +1281,7 @@ function findByUniqueName(target, id) {
|
|
|
1096
1281
|
}
|
|
1097
1282
|
function findByMetadataSelector(target, selector) {
|
|
1098
1283
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1099
|
-
const roots =
|
|
1284
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1100
1285
|
for (const root of roots) {
|
|
1101
1286
|
const found = findInNodeByMeta(root, parsed.key, parsed.value);
|
|
1102
1287
|
if (found) return found;
|
|
@@ -1105,7 +1290,7 @@ function findByMetadataSelector(target, selector) {
|
|
|
1105
1290
|
}
|
|
1106
1291
|
function findAllByMetadataSelector(target, selector) {
|
|
1107
1292
|
const parsed = parseMetadataSelectorValue(selector);
|
|
1108
|
-
const roots =
|
|
1293
|
+
const roots = isDocument3(target) ? target.nodes : [target];
|
|
1109
1294
|
const out = [];
|
|
1110
1295
|
for (const root of roots) {
|
|
1111
1296
|
collectInNodeByMeta(root, parsed.key, parsed.value, out);
|
|
@@ -1141,7 +1326,7 @@ function findInNodeByMeta(node, key, value) {
|
|
|
1141
1326
|
const found = findInNodeByMeta(child, key, value);
|
|
1142
1327
|
if (found) return found;
|
|
1143
1328
|
}
|
|
1144
|
-
} else if (
|
|
1329
|
+
} else if (isPlainObject3(node)) {
|
|
1145
1330
|
for (const k of Object.keys(node)) {
|
|
1146
1331
|
const found = findInNodeByMeta(node[k], key, value);
|
|
1147
1332
|
if (found) return found;
|
|
@@ -1175,7 +1360,7 @@ function collectInNodeByMeta(node, key, value, out) {
|
|
|
1175
1360
|
for (const child of node) {
|
|
1176
1361
|
collectInNodeByMeta(child, key, value, out);
|
|
1177
1362
|
}
|
|
1178
|
-
} else if (
|
|
1363
|
+
} else if (isPlainObject3(node)) {
|
|
1179
1364
|
for (const k of Object.keys(node)) {
|
|
1180
1365
|
collectInNodeByMeta(node[k], key, value, out);
|
|
1181
1366
|
}
|
|
@@ -1222,7 +1407,7 @@ function findInNode(node, id) {
|
|
|
1222
1407
|
const found = findInNode(child, id);
|
|
1223
1408
|
if (found) return found;
|
|
1224
1409
|
}
|
|
1225
|
-
} else if (
|
|
1410
|
+
} else if (isPlainObject3(node)) {
|
|
1226
1411
|
for (const key of Object.keys(node)) {
|
|
1227
1412
|
const found = findInNode(node[key], id);
|
|
1228
1413
|
if (found) return found;
|
|
@@ -1242,14 +1427,14 @@ function isTextElement(node) {
|
|
|
1242
1427
|
function isExtendBody(value) {
|
|
1243
1428
|
return value && typeof value === "object" && Array.isArray(value.order) && value.children;
|
|
1244
1429
|
}
|
|
1245
|
-
function
|
|
1430
|
+
function isDocument3(value) {
|
|
1246
1431
|
return value && typeof value === "object" && Array.isArray(value.nodes);
|
|
1247
1432
|
}
|
|
1248
|
-
function
|
|
1433
|
+
function isPlainObject3(value) {
|
|
1249
1434
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isElementNode(value) && !isExtendBody(value) && !isWord(value);
|
|
1250
1435
|
}
|
|
1251
1436
|
function ensureMap(value, strict) {
|
|
1252
|
-
if (!
|
|
1437
|
+
if (!isPlainObject3(value)) {
|
|
1253
1438
|
if (strict) throw new XnlPathError("Target is not a map/object");
|
|
1254
1439
|
}
|
|
1255
1440
|
}
|
|
@@ -1288,13 +1473,13 @@ function diffNodes(oldNode, newNode, basePath = [], opts = {}) {
|
|
|
1288
1473
|
if (!sameKind(oldNode, newNode)) {
|
|
1289
1474
|
throw new XnlPathError("Root kinds must match to diff");
|
|
1290
1475
|
}
|
|
1291
|
-
if (isValueLiteral(oldNode) ||
|
|
1476
|
+
if (isValueLiteral(oldNode) || isComment3(oldNode)) {
|
|
1292
1477
|
return oldNode === newNode ? [] : [{ type: "OBJECT_UPDATE", path: pathItems, valueAfter: newNode }];
|
|
1293
1478
|
}
|
|
1294
1479
|
if (Array.isArray(oldNode) && Array.isArray(newNode)) {
|
|
1295
1480
|
return diffArray(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1296
1481
|
}
|
|
1297
|
-
if (
|
|
1482
|
+
if (isPlainObject4(oldNode) && isPlainObject4(newNode)) {
|
|
1298
1483
|
return diffMap(oldNode, newNode, pathItems, void 0, void 0, opts);
|
|
1299
1484
|
}
|
|
1300
1485
|
if (isTextElement2(oldNode) && isTextElement2(newNode)) {
|
|
@@ -1586,7 +1771,7 @@ function sameKind(a, b) {
|
|
|
1586
1771
|
if (isDataElement2(a) && isDataElement2(b)) return true;
|
|
1587
1772
|
if (isTextElement2(a) && isTextElement2(b)) return true;
|
|
1588
1773
|
if (Array.isArray(a) && Array.isArray(b)) return true;
|
|
1589
|
-
if (
|
|
1774
|
+
if (isPlainObject4(a) && isPlainObject4(b)) return true;
|
|
1590
1775
|
if (isValueLiteral(a) && isValueLiteral(b)) return true;
|
|
1591
1776
|
return typeof a === typeof b;
|
|
1592
1777
|
}
|
|
@@ -1600,7 +1785,7 @@ function isEqual(a, b) {
|
|
|
1600
1785
|
if (a.length !== b.length) return false;
|
|
1601
1786
|
return a.every((item, idx) => isEqual(item, b[idx]));
|
|
1602
1787
|
}
|
|
1603
|
-
if (
|
|
1788
|
+
if (isPlainObject4(a) && isPlainObject4(b)) {
|
|
1604
1789
|
const keysA = Object.keys(a);
|
|
1605
1790
|
const keysB = Object.keys(b);
|
|
1606
1791
|
if (keysA.length !== keysB.length) return false;
|
|
@@ -1608,7 +1793,7 @@ function isEqual(a, b) {
|
|
|
1608
1793
|
}
|
|
1609
1794
|
return false;
|
|
1610
1795
|
}
|
|
1611
|
-
function
|
|
1796
|
+
function isPlainObject4(value) {
|
|
1612
1797
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement2(value) && !isTextElement2(value) && !isWord(value);
|
|
1613
1798
|
}
|
|
1614
1799
|
function isDataElement2(node) {
|
|
@@ -1620,7 +1805,7 @@ function isTextElement2(node) {
|
|
|
1620
1805
|
function isValueLiteral(node) {
|
|
1621
1806
|
return typeof node === "string" || typeof node === "number" || typeof node === "boolean" || node === null || isWord(node);
|
|
1622
1807
|
}
|
|
1623
|
-
function
|
|
1808
|
+
function isComment3(node) {
|
|
1624
1809
|
return node && node.kind === "Comment";
|
|
1625
1810
|
}
|
|
1626
1811
|
var ip = (value) => ({ type: "InstanceProperty", value });
|
|
@@ -1955,7 +2140,7 @@ function cloneNode(node) {
|
|
|
1955
2140
|
if (isWord(node)) {
|
|
1956
2141
|
return cloneWord(node);
|
|
1957
2142
|
}
|
|
1958
|
-
if (
|
|
2143
|
+
if (isPlainObject5(node)) {
|
|
1959
2144
|
const out = {};
|
|
1960
2145
|
for (const key of Object.keys(node)) {
|
|
1961
2146
|
out[key] = cloneNode(node[key]);
|
|
@@ -1981,7 +2166,7 @@ function mergeMaps(ctx, base, override, scope) {
|
|
|
1981
2166
|
continue;
|
|
1982
2167
|
}
|
|
1983
2168
|
const resolvedValue = resolveValue(ctx, value, scope);
|
|
1984
|
-
if (
|
|
2169
|
+
if (isPlainObject5(resolvedValue) && isPlainObject5(result[key])) {
|
|
1985
2170
|
result[key] = mergeMaps(ctx, result[key], resolvedValue, scope);
|
|
1986
2171
|
} else if (Array.isArray(resolvedValue) && Array.isArray(result[key])) {
|
|
1987
2172
|
result[key] = mergeArray(ctx, result[key], resolvedValue, scope);
|
|
@@ -2002,7 +2187,7 @@ function mergeArray(ctx, baseArr, overrideArr, scope) {
|
|
|
2002
2187
|
const resolved = resolveValue(ctx, value, scope);
|
|
2003
2188
|
if (i < result.length) {
|
|
2004
2189
|
const baseVal = result[i];
|
|
2005
|
-
if (
|
|
2190
|
+
if (isPlainObject5(baseVal) && isPlainObject5(resolved)) {
|
|
2006
2191
|
result[i] = mergeMaps(ctx, baseVal, resolved, scope);
|
|
2007
2192
|
} else if (Array.isArray(baseVal) && Array.isArray(resolved)) {
|
|
2008
2193
|
result[i] = mergeArray(ctx, baseVal, resolved, scope);
|
|
@@ -2057,7 +2242,7 @@ function isDataElement3(node) {
|
|
|
2057
2242
|
function isTextElement3(node) {
|
|
2058
2243
|
return node && node.kind === "TextElement";
|
|
2059
2244
|
}
|
|
2060
|
-
function
|
|
2245
|
+
function isPlainObject5(value) {
|
|
2061
2246
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !isDataElement3(value) && !isWord(value);
|
|
2062
2247
|
}
|
|
2063
2248
|
function resolveValue(ctx, value, scope) {
|
|
@@ -2074,7 +2259,7 @@ function resolveValue(ctx, value, scope) {
|
|
|
2074
2259
|
if (Array.isArray(value)) {
|
|
2075
2260
|
return value.map((v) => resolveValue(ctx, v, scope));
|
|
2076
2261
|
}
|
|
2077
|
-
if (
|
|
2262
|
+
if (isPlainObject5(value)) {
|
|
2078
2263
|
const out = {};
|
|
2079
2264
|
for (const key of Object.keys(value)) {
|
|
2080
2265
|
out[key] = resolveValue(ctx, value[key], scope);
|
|
@@ -2146,6 +2331,7 @@ var XNL = {
|
|
|
2146
2331
|
parseSingle: parseXnlSingleNode,
|
|
2147
2332
|
parseUnique: parseUniqueChildren,
|
|
2148
2333
|
stringify,
|
|
2334
|
+
stringifyLineBlock: stringify2,
|
|
2149
2335
|
path: {
|
|
2150
2336
|
parse: parsePath,
|
|
2151
2337
|
resolve: resolvePath,
|
|
@@ -2181,6 +2367,7 @@ exports.parseXnl = parseXnl;
|
|
|
2181
2367
|
exports.parseXnlSingleNode = parseXnlSingleNode;
|
|
2182
2368
|
exports.resolvePath = resolvePath;
|
|
2183
2369
|
exports.setPathValue = setPathValue;
|
|
2370
|
+
exports.stringifyLineBlock = stringify2;
|
|
2184
2371
|
exports.wordToString = wordToString;
|
|
2185
2372
|
//# sourceMappingURL=index.cjs.map
|
|
2186
2373
|
//# sourceMappingURL=index.cjs.map
|