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

sort-keys

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-keys - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

37

index.js
'use strict';
var isPlainObj = require('is-plain-obj');
const isPlainObj = require('is-plain-obj');
module.exports = function (obj, opts) {
module.exports = (obj, opts) => {
if (!isPlainObj(obj)) {

@@ -13,11 +13,11 @@ throw new TypeError('Expected a plain object');

if (typeof opts === 'function') {
opts = {compare: opts};
throw new TypeError('Specify the compare function as an option instead');
}
var deep = opts.deep;
var seenInput = [];
var seenOutput = [];
const deep = opts.deep;
const seenInput = [];
const seenOutput = [];
var sortKeys = function (x) {
var seenIndex = seenInput.indexOf(x);
const sortKeys = x => {
const seenIndex = seenInput.indexOf(x);

@@ -28,4 +28,4 @@ if (seenIndex !== -1) {

var ret = {};
var keys = Object.keys(x).sort(opts.compare);
const ret = {};
const keys = Object.keys(x).sort(opts.compare);

@@ -35,6 +35,17 @@ seenInput.push(x);

for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = x[key];
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const val = x[key];
if (deep && Array.isArray(val)) {
const retArr = [];
for (let j = 0; j < val.length; j++) {
retArr[j] = isPlainObj(val[j]) ? sortKeys(val[j]) : val[j];
}
ret[key] = retArr;
continue;
}
ret[key] = deep && isPlainObj(val) ? sortKeys(val) : val;

@@ -41,0 +52,0 @@ }

{
"name": "sort-keys",
"version": "1.1.2",
"version": "2.0.0",
"description": "Sort the keys of an object",

@@ -13,6 +13,6 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && mocha"
"test": "xo && ava"
},

@@ -38,5 +38,5 @@ "files": [

"devDependencies": {
"mocha": "*",
"ava": "*",
"xo": "*"
}
}

Sorry, the diff of this file is not supported yet

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