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 2.0.0 to 3.0.0

index.d.ts

48

index.js
'use strict';
const isPlainObj = require('is-plain-obj');
const isPlainObject = require('is-plain-obj');
module.exports = (obj, opts) => {
if (!isPlainObj(obj)) {
module.exports = (object, options = {}) => {
if (!isPlainObject(object)) {
throw new TypeError('Expected a plain object');
}
opts = opts || {};
// DEPRECATED
if (typeof opts === 'function') {
throw new TypeError('Specify the compare function as an option instead');
}
const deep = opts.deep;
const {deep} = options;
const seenInput = [];
const seenOutput = [];
const sortKeys = x => {
const seenIndex = seenInput.indexOf(x);
const sortKeys = object => {
const seenIndex = seenInput.indexOf(object);

@@ -27,30 +20,23 @@ if (seenIndex !== -1) {

const ret = {};
const keys = Object.keys(x).sort(opts.compare);
const result = {};
const keys = Object.keys(object).sort(options.compare);
seenInput.push(x);
seenOutput.push(ret);
seenInput.push(object);
seenOutput.push(result);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const val = x[key];
for (const key of keys) {
const value = object[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;
if (deep && Array.isArray(value)) {
result[key] = value.map(arrayValue => isPlainObject(arrayValue) ? sortKeys(arrayValue) : arrayValue);
continue;
}
ret[key] = deep && isPlainObj(val) ? sortKeys(val) : val;
result[key] = deep && isPlainObject(value) ? sortKeys(value) : value;
}
return ret;
return result;
};
return sortKeys(obj);
return sortKeys(object);
};
{
"name": "sort-keys",
"version": "2.0.0",
"description": "Sort the keys of an object",
"license": "MIT",
"repository": "sindresorhus/sort-keys",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"sort",
"object",
"keys",
"obj",
"key",
"stable",
"deterministic",
"deep",
"recursive",
"recursively"
],
"dependencies": {
"is-plain-obj": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "sort-keys",
"version": "3.0.0",
"description": "Sort the keys of an object",
"license": "MIT",
"repository": "sindresorhus/sort-keys",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"sort",
"object",
"keys",
"key",
"stable",
"deterministic",
"deep",
"recursive",
"recursively"
],
"dependencies": {
"is-plain-obj": "^2.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

@@ -11,3 +11,3 @@ # sort-keys [![Build Status](https://travis-ci.org/sindresorhus/sort-keys.svg?branch=master)](https://travis-ci.org/sindresorhus/sort-keys)

```
$ npm install --save sort-keys
$ npm install sort-keys
```

@@ -36,15 +36,18 @@

### sortKeys(input, [options])
### sortKeys(object, [options])
Returns a new object with sorted keys.
#### input
#### object
Type: `Object`
Type: `object`
#### options
Type: `object`
##### deep
Type: `boolean`
Type: `boolean`<br>
Default: `false`

@@ -51,0 +54,0 @@ Recursively sort keys.

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