@architect/parser
Advanced tools
Comparing version 6.0.2 to 6.0.3
{ | ||
"name": "@architect/parser", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "Architect Parser accepts plaintext, JSON, or YAML .arc manifests and returns a plain JavaScript Object", | ||
@@ -15,3 +15,3 @@ "main": "./src/index.js", | ||
"build": "rollup -c", | ||
"vendor:js-yaml": "mkdir -p tmp && browserify --node --standalone js-yaml --im --no-builtins node_modules/js-yaml/index.js > tmp/js-yaml.js && terser tmp/js-yaml.js -o src/compat/vendor/js-yaml.min.js", | ||
"vendor:js-yaml": "mkdir -p tmp && browserify --node --standalone js-yaml --im --no-builtins node_modules/js-yaml/index.js > tmp/js-yaml.js && mkdir -p src/compat/vendor && terser tmp/js-yaml.js -o src/compat/vendor/js-yaml.min.js", | ||
"vendor": "npm run vendor:js-yaml" | ||
@@ -32,15 +32,15 @@ }, | ||
"devDependencies": { | ||
"@architect/eslint-config": "~2.0.1", | ||
"@rollup/plugin-commonjs": "~21.0.1", | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@architect/eslint-config": "~2.1.1", | ||
"@rollup/plugin-commonjs": "~25.0.3", | ||
"@rollup/plugin-json": "^6.0.0", | ||
"@rollup/plugin-terser": "~0.4.3", | ||
"browserify": "~17.0.0", | ||
"cross-env": "~7.0.3", | ||
"eslint": "~8.26.0", | ||
"eslint": "~8.46.0", | ||
"js-yaml": "~4.1.0", | ||
"nyc": "^15.1.0", | ||
"rollup": "^2.67.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup": "^3.27.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "~5.6.1", | ||
"terser": "~5.15.1" | ||
"tape": "~5.6.6", | ||
"terser": "~5.19.2" | ||
}, | ||
@@ -47,0 +47,0 @@ "eslintConfig": { |
@@ -70,4 +70,4 @@ /** | ||
if (CONVERT.includes(pragma)) { | ||
if (isObject(values)) result[pragma] = Object.entries(values).map(i => i) | ||
else if (isArray(values)) result[pragma] = values | ||
/**/ if (isObject(values)) result[pragma] = remap(values) | ||
else if (isArray(values)) result[pragma] = values | ||
else invalidPragma(pragma) | ||
@@ -79,3 +79,3 @@ } | ||
if (isObject(values) || isArray(values)) { | ||
result[pragma] = isObject(values) ? Object.entries(values).map(i => i) : values | ||
result[pragma] = isObject(values) ? remap(values) : values | ||
return | ||
@@ -97,1 +97,7 @@ } | ||
} | ||
function remap (values) { | ||
return Object.entries(values).map(([ key, value ]) => { | ||
if (isArray(value)) return { [key]: value } | ||
return [ key, value ] | ||
}) | ||
} |
@@ -0,5 +1,15 @@ | ||
let { isArray } = Array | ||
let isObj = i => typeof i === 'object' && !isArray(i) | ||
module.exports = function stringify (obj) { | ||
if (typeof obj !== 'object') return | ||
if (!isObj(obj)) return | ||
let pragmas = Object.keys(obj) | ||
let out = '' | ||
function append (item) { | ||
/**/ if (isArray(item)) for (let i of item) { out += `\n ${i}` } | ||
else if (isObj(item)) for (let i in item) { out += `\n ${i} ${item[i]}` } | ||
else out += `${item} ` | ||
} | ||
pragmas.forEach(function (pragma, i) { | ||
@@ -10,6 +20,6 @@ let props = obj[pragma] | ||
: `\n@${pragma}\n` | ||
props.forEach(function (prop) { | ||
if (typeof prop === 'string') { | ||
out += `${prop}\n` | ||
let includesReserved = prop.includes('@') || prop.includes('#') | ||
out += includesReserved ? `"${prop}"\n` : `${prop}\n` | ||
} | ||
@@ -25,23 +35,18 @@ | ||
if (typeof prop === 'object') { | ||
if (Array.isArray(prop)) { | ||
prop.forEach(p => { | ||
out += `${p} ` | ||
}) | ||
out += '\n' | ||
if (isObj(prop)) { | ||
for (let key in prop) { | ||
out += `${key} ` | ||
append(prop[key]) | ||
out += `\n` | ||
} | ||
else { | ||
for (let key in prop) { | ||
out += `${key}` | ||
let subs = prop[key] | ||
for (let property in subs) { | ||
out += `\n ${property} ${subs[property]}` | ||
} | ||
out += `\n` | ||
} | ||
} | ||
} | ||
if (isArray(prop)) { | ||
prop.forEach(append) | ||
out += '\n' | ||
} | ||
}) | ||
}) | ||
return out | ||
let result = out.split('\n').map(l => l.trimEnd(l)).join('\n') | ||
return result | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1235
125150
44