sort-keys-recursive
Advanced tools
Comparing version
52
index.js
@@ -1,10 +0,44 @@ | ||
'use strict'; | ||
require('coffee-script/register'); | ||
var typeOf = require('fn-typeof'); | ||
var sort = require('./lib/SortRecursive'); | ||
'use strict' | ||
module.exports = function(something, compareFn) { | ||
var type = typeOf(something); | ||
if (sort[type]) return sort[type](something, compareFn); | ||
return something; | ||
}; | ||
var sortKeys = require('sort-keys') | ||
var kindOf = require('kind-of') | ||
function sortObjectKeys (obj, compare) { | ||
return sortKeys(obj, compare) | ||
} | ||
function sortArray (arr, compare) { | ||
return arr.slice().sort(compare) | ||
} | ||
function sortObject (obj, compare) { | ||
var result = sortObjectKeys(obj, compare) | ||
Object.keys(obj).forEach(function (key) { | ||
var current = result[key] | ||
var type = kindOf(current) | ||
if (type === 'object') { | ||
result[key] = sortObject(current, compare) | ||
return | ||
} | ||
if (type === 'array') { | ||
result[key] = sortArray(current) | ||
return | ||
} | ||
}) | ||
return result | ||
} | ||
function sort (something, compareFn) { | ||
var type = kindOf(something) | ||
if (sort[type]) return sort[type](something, compareFn) | ||
return something | ||
} | ||
sort.array = sortArray | ||
sort.object = sortObject | ||
module.exports = sort |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/Kikobeats/sort-keys-recursive", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "./index.js", | ||
@@ -13,3 +13,6 @@ "author": { | ||
}, | ||
"repository": "Kikobeats/sort-keys-recursive", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kikobeats/sort-keys-recursive.git" | ||
}, | ||
"bugs": { | ||
@@ -19,2 +22,5 @@ "url": "https://github.com/Kikobeats/sort-keys-recursive/issues" | ||
"keywords": [ | ||
"array", | ||
"deep", | ||
"deterministic", | ||
"key", | ||
@@ -25,28 +31,27 @@ "keys", | ||
"recursive", | ||
"sort" | ||
"recursively", | ||
"sort", | ||
"stable" | ||
], | ||
"dependencies": { | ||
"fn-typeof": "*", | ||
"sort-keys": "*" | ||
"kind-of": "~3.1.0", | ||
"sort-keys": "~1.1.2" | ||
}, | ||
"devDependencies": { | ||
"browserify": "*", | ||
"coffee-script": "*", | ||
"coffeeify": "*", | ||
"gulp": "*", | ||
"gulp-header": "*", | ||
"gulp-uglify": "*", | ||
"gulp-util": "*", | ||
"mocha": "*", | ||
"should": "*", | ||
"vinyl-buffer": "*", | ||
"vinyl-source-stream": "*" | ||
"ava": "latest", | ||
"coveralls": "latest", | ||
"nyc": "latest", | ||
"standard": "latest", | ||
"standard-markdown": "latest" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "sh test/test.sh" | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"lint": "standard-markdown && standard", | ||
"pretest": "npm run lint", | ||
"test": "nyc ava" | ||
}, | ||
"license": "MIT" | ||
} |
# sort-keys-recursive | ||
[](https://travis-ci.org/Kikobeats/sort-keys-recursive) | ||
[](https://david-dm.org/Kikobeats/sort-keys-recursive) | ||
[](https://david-dm.org/Kikobeats/sort-keys-recursive#info=devDependencies) | ||
[](https://www.npmjs.org/package/sort-keys-recursive) | ||
[](https://www.gittip.com/Kikobeats/) | ||
 | ||
[](https://travis-ci.org/Kikobeats/sort-keys-recursive) | ||
[](https://coveralls.io/github/Kikobeats/sort-keys-recursive) | ||
[](https://david-dm.org/Kikobeats/sort-keys-recursive) | ||
[](https://david-dm.org/Kikobeats/sort-keys-recursive#info=devDependencies) | ||
[](https://www.npmjs.org/package/str-match) | ||
[](https://paypal.me/Kikobeats) | ||
@@ -22,13 +24,6 @@ > Sort the keys of an object recursively | ||
``` | ||
and later link in your HTML: | ||
```html | ||
<script src="bower_components/sort-keys-recursive/dist/sort-keys-recursive.js"></script> | ||
``` | ||
## Usage | ||
```js | ||
recursive = require('sort-keys-recursive'); | ||
var sort = require('sort-keys-recursive') | ||
@@ -43,6 +38,8 @@ var object = { | ||
b: 0 | ||
}; | ||
} | ||
console.log(recursive(object)); | ||
var output = sort(object) | ||
console.log(output) | ||
// { | ||
@@ -63,3 +60,1 @@ // a: { | ||
MIT © [Kiko Beats](http://www.kikobeats.com) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
5
-54.55%95
106.52%0
-100%0
-100%0
-100%0
-100%13053
-14.42%13
-31.58%58
-7.94%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated