sort-keys-recursive
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,17 @@ | ||
<a name="2.0.1"></a> | ||
## 2.0.1 (2017-07-18) | ||
* Fix interface ([883ae34](https://github.com/kikobeats/sort-keys-recursive/commit/883ae34)) | ||
* Fix linter ([81b0cd3](https://github.com/kikobeats/sort-keys-recursive/commit/81b0cd3)) | ||
* Fix linter ([1792395](https://github.com/kikobeats/sort-keys-recursive/commit/1792395)) | ||
* Little Refactor ([0a40c2c](https://github.com/kikobeats/sort-keys-recursive/commit/0a40c2c)) | ||
* Update README.md ([f986868](https://github.com/kikobeats/sort-keys-recursive/commit/f986868)) | ||
* Update travis builds ([0a949fe](https://github.com/kikobeats/sort-keys-recursive/commit/0a949fe)) | ||
* docs(readme): add Greenkeeper badge ([14b62b8](https://github.com/kikobeats/sort-keys-recursive/commit/14b62b8)) | ||
* chore(package): update dependencies ([2dcdb49](https://github.com/kikobeats/sort-keys-recursive/commit/2dcdb49)) | ||
* chore(package): update kind-of to version 3.2.2 ([39b9d7f](https://github.com/kikobeats/sort-keys-recursive/commit/39b9d7f)) | ||
* chore(package): update kind-of to version 4.0.0 ([4cedab2](https://github.com/kikobeats/sort-keys-recursive/commit/4cedab2)) | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +18,0 @@ # 2.0.0 (2017-02-26) |
50
index.js
'use strict' | ||
var sortKeys = require('sort-keys') | ||
var kindOf = require('kind-of') | ||
const sortKeys = require('sort-keys') | ||
const kindOf = require('kind-of') | ||
function inArray (value, arr) { | ||
if (!arr || kindOf(arr) !== 'array') return false | ||
const inArray = (value, arr) => ( | ||
!arr || kindOf(arr) !== 'array' | ||
? false | ||
: arr.indexOf(value) > -1 | ||
) | ||
return arr.indexOf(value) > -1 | ||
} | ||
const sortObjectKeys = (obj, compare) => sortKeys(obj, {compare}) | ||
function sortObjectKeys (obj, compare) { | ||
return sortKeys(obj, compare) | ||
} | ||
function sortArray (arr, options) { | ||
const compareFunction = options && options.compareFunction | ||
const sortArray = (arr, opts) => { | ||
const compareFunction = opts && opts.compareFunction | ||
return arr.slice().sort(compareFunction) | ||
} | ||
function sortObject (obj, options) { | ||
const compareFunction = options && options.compareFunction | ||
var result = sortObjectKeys(obj, compareFunction) | ||
function sortObject (obj, opts) { | ||
const compareFunction = opts && opts.compareFunction | ||
const result = sortObjectKeys(obj, compareFunction) | ||
Object.keys(obj).forEach(function (key) { | ||
var current = result[key] | ||
var type = kindOf(current) | ||
const current = result[key] | ||
const type = kindOf(current) | ||
if (type === 'object') { | ||
if (!options || !inArray(key, options.ignoreObjectAtKeys)) { | ||
result[key] = sortObject(current, options) | ||
if (!opts || !inArray(key, opts.ignoreObjectAtKeys)) { | ||
result[key] = sortObject(current, opts) | ||
} | ||
@@ -38,6 +35,5 @@ return | ||
if (type === 'array') { | ||
if (!options || !inArray(key, options.ignoreArrayAtKeys)) { | ||
result[key] = sortArray(current, options) | ||
if (!opts || !inArray(key, opts.ignoreArrayAtKeys)) { | ||
result[key] = sortArray(current, opts) | ||
} | ||
return | ||
} | ||
@@ -49,7 +45,5 @@ }) | ||
function sort (something, opts) { | ||
var type = kindOf(something) | ||
if (sort[type]) return sort[type](something, opts) | ||
return something | ||
const sort = (something, opts) => { | ||
const type = kindOf(something) | ||
return sort[type] ? sort[type](something, opts) : something | ||
} | ||
@@ -56,0 +50,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/Kikobeats/sort-keys-recursive", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"main": "./index.js", | ||
@@ -34,4 +34,4 @@ "author": { | ||
"dependencies": { | ||
"kind-of": "~3.1.0", | ||
"sort-keys": "~1.1.2" | ||
"kind-of": "~5.0.0", | ||
"sort-keys": "~2.0.0" | ||
}, | ||
@@ -55,5 +55,5 @@ "devDependencies": { | ||
"pretest": "npm run lint", | ||
"test": "nyc ava" | ||
"test": "nyc ava --verbose" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -47,3 +47,2 @@ # sort-keys-recursive | ||
// }; | ||
``` | ||
@@ -122,3 +121,2 @@ | ||
// } | ||
``` | ||
@@ -162,3 +160,2 @@ | ||
// } | ||
``` | ||
@@ -165,0 +162,0 @@ |
11418
40
163
+ Addedkind-of@5.0.2(transitive)
+ Addedsort-keys@2.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedkind-of@3.1.0(transitive)
- Removedsort-keys@1.1.2(transitive)
Updatedkind-of@~5.0.0
Updatedsort-keys@~2.0.0