Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-json

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-json - npm Package Compare versions

Comparing version 1.5.2 to 1.6.0

tests/cmd.js

4

app/cmd.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc