json.sortify
Advanced tools
Comparing version
@@ -12,3 +12,3 @@ 'use strict'; | ||
Object.assign(babelOpts, { | ||
compact: true, | ||
minified: true, | ||
shouldPrintComment: c => c[0] === '!' | ||
@@ -18,8 +18,8 @@ }); | ||
let code = ` | ||
(function(name, factory) { | ||
if (typeof define == 'function' && typeof define.amd == 'object') | ||
define('json.sortify', factory); | ||
(function(factory) { | ||
if (typeof define == "function" && typeof define.amd == "object") | ||
define("json.sortify", factory); | ||
else | ||
JSON.sortify = factory(); | ||
})(this, function() { | ||
})(function() { | ||
${factory.replace(/\bmodule\s*\.\s*exports\s*=/, 'return ')} | ||
@@ -26,0 +26,0 @@ });`; |
@@ -1,2 +0,2 @@ | ||
'use strict';var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj;};(function(name,factory){if(typeof define=='function'&&_typeof(define.amd)=='object')define('json.sortify',factory);else JSON.sortify=factory();})(undefined,function(){ /*! | ||
"use strict";(function(factory){if(typeof define=="function"&&typeof define.amd=="object")define("json.sortify",factory);else JSON.sortify=factory()})(function(){ /*! | ||
* Copyright 2015-2016 Thomas Rosenau | ||
@@ -15,2 +15,2 @@ * | ||
* limitations under the License. | ||
*/'use strict';var sortKeys=function sortKeys(o){if(Array.isArray(o)){return o.map(sortKeys);}else if(o instanceof Object){var _ret=function(){var numeric=[];var nonNumeric=[];Object.keys(o).forEach(function(key){if(/^(0|[1-9][0-9]*)$/.test(key)){numeric.push(+key);}else {nonNumeric.push(key);}});return {v:numeric.sort(function(a,b){return a-b;}).concat(nonNumeric.sort()).reduce(function(result,key){result[key]=sortKeys(o[key]);return result;},{})};}();if((typeof _ret==='undefined'?'undefined':_typeof(_ret))==="object")return _ret.v;}return o;};var jsonStringify=JSON.stringify.bind(JSON);var sortify=function sortify(value,replacer,space){var native=jsonStringify(value,replacer,0);if(!native||native[0]!=='{'&&native[0]!=='['){return native;}var cleanObj=JSON.parse(native);return jsonStringify(sortKeys(cleanObj),null,space);};return sortify;}); | ||
*/"use strict";var sortKeys=function sortKeys(o){if(Array.isArray(o)){return o.map(sortKeys)}else if(o instanceof Object){var _ret=function(){var numeric=[];var nonNumeric=[];Object.keys(o).forEach(function(key){if(/^(0|[1-9][0-9]*)$/.test(key)){numeric.push(+key)}else {nonNumeric.push(key)}});return {v:numeric.sort(function(a,b){return a-b}).concat(nonNumeric.sort()).reduce(function(result,key){result[key]=sortKeys(o[key]);return result},{})}}();if(typeof _ret==="object")return _ret.v}return o};var jsonStringify=JSON.stringify.bind(JSON);var sortify=function sortify(value,replacer,space){var native=jsonStringify(value,replacer,0);if(!native||native[0]!=="{"&&native[0]!=="["){return native}var cleanObj=JSON.parse(native);return jsonStringify(sortKeys(cleanObj),null,space)};return sortify}); |
{ | ||
"name": "json.sortify", | ||
"description": "A deterministic version of JSON.stringify that sorts object keys alphabetically.", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"engines": { | ||
@@ -9,4 +9,23 @@ "node": ">=0.10.0" | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
"plugins": [ | ||
"check-es2015-constants", | ||
"transform-es2015-arrow-functions", | ||
"transform-es2015-block-scoped-functions", | ||
"transform-es2015-block-scoping", | ||
"transform-es2015-classes", | ||
"transform-es2015-computed-properties", | ||
"transform-es2015-destructuring", | ||
"transform-es2015-duplicate-keys", | ||
"transform-es2015-for-of", | ||
"transform-es2015-function-name", | ||
"transform-es2015-literals", | ||
"transform-es2015-modules-commonjs", | ||
"transform-es2015-object-super", | ||
"transform-es2015-parameters", | ||
"transform-es2015-shorthand-properties", | ||
"transform-es2015-spread", | ||
"transform-es2015-sticky-regex", | ||
"transform-es2015-template-literals", | ||
"transform-es2015-unicode-regex", | ||
"transform-regenerator" | ||
] | ||
@@ -38,3 +57,22 @@ }, | ||
"babel-core": "^6.7.2", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-plugin-check-es2015-constants": "^6.7.2", | ||
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2", | ||
"babel-plugin-transform-es2015-block-scoped-functions": "^6.6.5", | ||
"babel-plugin-transform-es2015-block-scoping": "^6.7.1", | ||
"babel-plugin-transform-es2015-classes": "^6.6.5", | ||
"babel-plugin-transform-es2015-computed-properties": "^6.6.5", | ||
"babel-plugin-transform-es2015-destructuring": "^6.6.5", | ||
"babel-plugin-transform-es2015-duplicate-keys": "^6.6.4", | ||
"babel-plugin-transform-es2015-for-of": "^6.6.0", | ||
"babel-plugin-transform-es2015-function-name": "^6.5.0", | ||
"babel-plugin-transform-es2015-literals": "^6.5.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.7.0", | ||
"babel-plugin-transform-es2015-object-super": "^6.6.5", | ||
"babel-plugin-transform-es2015-parameters": "^6.7.0", | ||
"babel-plugin-transform-es2015-shorthand-properties": "^6.5.0", | ||
"babel-plugin-transform-es2015-spread": "^6.6.5", | ||
"babel-plugin-transform-es2015-sticky-regex": "^6.5.0", | ||
"babel-plugin-transform-es2015-template-literals": "^6.6.5", | ||
"babel-plugin-transform-es2015-unicode-regex": "^6.5.0", | ||
"babel-plugin-transform-regenerator": "^6.6.5", | ||
"expect": "^1.15.2", | ||
@@ -52,5 +90,5 @@ "istanbul": "^0.3.17", | ||
"test:browser:amd": "mocha-phantomjs test/test-amd.html", | ||
"test:cov": "istanbul cover _mocha -- --check-leaks --reporter dot test/", | ||
"test:travis": "npm run test:browser && istanbul cover _mocha --report lcovonly -- --check-leaks --reporter spec test/" | ||
"test:cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/", | ||
"test:travis": "npm run test:browser && istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec test/" | ||
} | ||
} |
@@ -46,2 +46,8 @@ JSON.sortify | ||
Or, if you're using [bower](http://bower.io/), type `bower install json.sortify`. | ||
```html | ||
<script src="bower_components/json.sortify/dist/JSON.sortify.js"></script> | ||
``` | ||
`JSON.sortify` can be used exactly like `JSON.stringify`. As mentioned above, you can overwrite JSON.stringify if you want to: | ||
@@ -48,0 +54,0 @@ |
52646
4.82%14
7.69%327
9%134
4.69%25
316.67%