Comparing version 1.1.1 to 1.1.2
13
index.js
@@ -17,7 +17,18 @@ 'use strict'; | ||
var deep = opts.deep; | ||
var seenInput = []; | ||
var seenOutput = []; | ||
var sortKeys = function (x) { | ||
var seenIndex = seenInput.indexOf(x); | ||
if (seenIndex !== -1) { | ||
return seenOutput[seenIndex]; | ||
} | ||
var ret = {}; | ||
var keys = Object.keys(x).sort(opts.compare); | ||
seenInput.push(x); | ||
seenOutput.push(ret); | ||
for (var i = 0; i < keys.length; i++) { | ||
@@ -27,3 +38,3 @@ var key = keys[i]; | ||
ret[key] = deep && val !== x && isPlainObj(val) ? sortKeys(val) : val; | ||
ret[key] = deep && isPlainObj(val) ? sortKeys(val) : val; | ||
} | ||
@@ -30,0 +41,0 @@ |
{ | ||
"name": "sort-keys", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Sort the keys of an object", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && mocha" | ||
}, | ||
@@ -23,7 +23,7 @@ "files": [ | ||
"keywords": [ | ||
"sort", | ||
"object", | ||
"keys", | ||
"obj", | ||
"keys", | ||
"key", | ||
"sort", | ||
"stable", | ||
@@ -39,4 +39,5 @@ "deterministic", | ||
"devDependencies": { | ||
"mocha": "*" | ||
"mocha": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -18,3 +18,3 @@ # sort-keys [![Build Status](https://travis-ci.org/sindresorhus/sort-keys.svg?branch=master)](https://travis-ci.org/sindresorhus/sort-keys) | ||
```js | ||
var sortKeys = require('sort-keys'); | ||
const sortKeys = require('sort-keys'); | ||
@@ -28,5 +28,3 @@ sortKeys({c: 0, a: 0, b: 0}); | ||
sortKeys({c: 0, a: 0, b: 0}, { | ||
compare: function (a, b) { | ||
return -a.localeCompare(b); | ||
} | ||
compare: (a, b) => -a.localeCompare(b) | ||
}); | ||
@@ -45,4 +43,3 @@ //=> {c: 0, b: 0, a: 0} | ||
*Required* | ||
Type: `object` | ||
Type: `Object` | ||
@@ -59,3 +56,3 @@ #### options | ||
Type: `function` | ||
Type: `Function` | ||
@@ -67,2 +64,2 @@ [Compare function.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
3582
32
2
61