fix: omit empty arrays and objects too

This commit is contained in:
orion kindel 2023-11-28 14:30:20 -06:00
parent fe1bcc1989
commit 6e17bd3004
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -16,11 +16,12 @@ export function toYAMLImpl(a) {
const replacer = (_, o) => { const replacer = (_, o) => {
if (typeof o === 'object') { if (typeof o === 'object') {
Object.entries(o).forEach(([k, v]) => { Object.entries(o).forEach(([k, v]) => {
if (typeof v === 'undefined' || v === null) { if (typeof v === 'undefined' || v === null || (v instanceof Array && v.length === 0) || (typeof v === 'object' && Object.keys(v).length === 0)) {
delete o[k] delete o[k]
} }
}) })
} }
return o return o
} }