Comparing version 1.5.2 to 1.6.0
@@ -16,2 +16,4 @@ #!/usr/bin/env node | ||
var reverse = _.includes(process.argv, '--reverse') || _.includes(process.argv, '-r'); | ||
var dirtyDepth = process.argv.slice(0).filter(arg => arg.startsWith('-d') || arg.startsWith('--depth')); | ||
var depth = dirtyDepth.length > 0 ? parseInt(dirtyDepth[0].split('=')[1], 10) : Infinity; | ||
@@ -22,3 +24,3 @@ sortJson.overwrite( | ||
}), | ||
{ ignoreCase, reverse } | ||
{ ignoreCase, reverse, depth } | ||
); |
@@ -9,2 +9,3 @@ /** | ||
* @param [options.ignoreCase = false] - When sorting keys, converts all keys to | ||
* @param [options.depth = Infinity] - Depth's level sorting keys on a multidimensional object | ||
* @returns {*} - Object with sorted keys, if old wasn't an object | ||
@@ -17,2 +18,5 @@ * returns whatever was passed | ||
var reverse = options.reverse || false; | ||
var depth = options.depth || Infinity; | ||
var level = options.level || 1; | ||
var processing = level <= depth; | ||
@@ -24,7 +28,10 @@ if (typeof(old) !== 'object' || old === null) { | ||
var copy = Array.isArray(old) ? [] : {}; | ||
var keys = ignoreCase ? | ||
Object.keys(old).sort(function (a, b) { | ||
return a.toLowerCase().localeCompare(b.toLowerCase()); | ||
}) : | ||
Object.keys(old).sort(); | ||
var keys = Object.keys(old); | ||
if(processing) { | ||
keys = ignoreCase ? | ||
keys.sort(function (a, b) { | ||
return a.toLowerCase().localeCompare(b.toLowerCase()); | ||
}) : | ||
keys.sort(); | ||
} | ||
@@ -35,4 +42,6 @@ if (reverse) { | ||
keys.forEach(function (key) { | ||
keys.forEach(function (key, i) { | ||
options.level = ++level; | ||
copy[key] = visit(old[key], options); | ||
options.level = --level; | ||
}); | ||
@@ -39,0 +48,0 @@ |
{ | ||
"name": "sort-json", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "Takes a json-file and return a copy of the same file, but sorted", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
17939
12
349
4
3