format-json-cli
Advanced tools
Comparing version 0.1.2 to 1.0.0
23
cli.js
@@ -33,2 +33,19 @@ #!/usr/bin/env node | ||
function isObject(o) { | ||
return o && typeof o === 'object' | ||
} | ||
function compare(a, b) { | ||
return a < b ? -1 : a > b ? 1 : 0 | ||
} | ||
function sortObject(object, key) { | ||
let o = object[key] | ||
if (!isObject(o)) { | ||
return | ||
} | ||
o = Object.fromEntries(Object.entries(o).sort((a, b) => compare(a[0], b[0]))) | ||
object[key] = o | ||
} | ||
function scanFile(file) { | ||
@@ -39,3 +56,7 @@ if (path.extname(file) !== '.json') return | ||
try { | ||
newText = JSON.stringify(JSON.parse(text), null, 2) + os.EOL | ||
let json = JSON.parse(text) | ||
sortObject(json, 'dependencies') | ||
sortObject(json, 'devDependencies') | ||
sortObject(json, 'peerDependencies') | ||
newText = JSON.stringify(json, null, 2) + os.EOL | ||
} catch (error) { | ||
@@ -42,0 +63,0 @@ console.error('Failed to parse file:', file) |
{ | ||
"name": "format-json-cli", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "format json file as post-hook to fix prettier", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4573
63
0