fix: encode mixed-format arrays at root level (fixes #202)

This commit is contained in:
Johann Schopplich
2025-11-21 09:01:26 +01:00
parent 2e992aed74
commit 36ddd2e0ea
3 changed files with 18 additions and 9 deletions

View File

@@ -38,6 +38,6 @@
"test": "vitest"
},
"devDependencies": {
"@toon-format/spec": "^2.0.0"
"@toon-format/spec": "^2.0.1"
}
}

View File

@@ -361,9 +361,18 @@ function* encodeListItemValueLines(
if (isJsonPrimitive(value)) {
yield indentedListItem(depth, encodePrimitive(value, options.delimiter), options.indent)
}
else if (isJsonArray(value) && isArrayOfPrimitives(value)) {
const arrayLine = encodeInlineArrayLine(value, options.delimiter)
yield indentedListItem(depth, arrayLine, options.indent)
else if (isJsonArray(value)) {
if (isArrayOfPrimitives(value)) {
const arrayLine = encodeInlineArrayLine(value, options.delimiter)
yield indentedListItem(depth, arrayLine, options.indent)
}
else {
const header = formatHeader(value.length, { delimiter: options.delimiter })
yield indentedListItem(depth, header, options.indent)
for (const item of value) {
yield* encodeListItemValueLines(item, depth + 1, options)
}
}
}
else if (isJsonObject(value)) {
yield* encodeObjectAsListItemLines(value, depth, options)