+10
-4
@@ -95,2 +95,3 @@ import { XMLBuilder, XMLParser, XMLValidator } from "fast-xml-parser"; | ||
| * If data is an array, name it 'root' | ||
| * If data is an object with no arrays, wrap it as a single-element array | ||
| */ | ||
@@ -107,6 +108,10 @@ function findRootArray$1(data) { | ||
| }; | ||
| return { | ||
| name: "data", | ||
| array: [data] | ||
| }; | ||
| } | ||
| return { | ||
| name: "root", | ||
| array: null | ||
| name: "data", | ||
| array: [data] | ||
| }; | ||
@@ -489,3 +494,2 @@ } | ||
| const rootArray = findRootArray(data); | ||
| if (!rootArray) throw new Error("Data must contain at least one array"); | ||
| const records = encodeArray(rootArray, new PathWriter(config), config); | ||
@@ -498,2 +502,3 @@ const { recordSeparator } = config; | ||
| * Find root array in data | ||
| * Auto-wraps single objects/primitives into arrays | ||
| */ | ||
@@ -504,4 +509,5 @@ function findRootArray(data) { | ||
| for (const value of Object.values(data)) if (isJsonArray(value)) return value; | ||
| return [data]; | ||
| } | ||
| return null; | ||
| return [data]; | ||
| } | ||
@@ -508,0 +514,0 @@ /** |
+1
-1
| { | ||
| "name": "ploon", | ||
| "version": "1.0.5", | ||
| "version": "1.0.6", | ||
| "description": "Path-Level Object Oriented Notation - The Most Token-Efficient Format for Nested Hierarchical Data", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
199123
0.34%2084
0.29%