| Current Path : /home/emeraadmin/public_html/4d695/ |
| Current File : /home/emeraadmin/public_html/4d695/json-stringify-nice.tar |
package.json 0000644 00000002742 15170146047 0007044 0 ustar 00 {
"_id": "json-stringify-nice@1.1.4",
"_inBundle": true,
"_location": "/npm/json-stringify-nice",
"_phantomChildren": {},
"_requiredBy": [
"/npm/@npmcli/arborist"
],
"author": {
"name": "Isaac Z. Schlueter",
"email": "i@izs.me",
"url": "https://izs.me"
},
"bugs": {
"url": "https://github.com/isaacs/json-stringify-nice/issues"
},
"description": "Stringify an object sorting scalars before objects, and defaulting to 2-space indent",
"devDependencies": {
"eslint": "^7.25.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"tap": "^15.0.6"
},
"files": [
"index.js"
],
"funding": {
"url": "https://github.com/sponsors/isaacs"
},
"homepage": "https://github.com/isaacs/json-stringify-nice#readme",
"license": "ISC",
"name": "json-stringify-nice",
"repository": {
"type": "git",
"url": "git+https://github.com/isaacs/json-stringify-nice.git"
},
"scripts": {
"eslint": "eslint",
"lint": "npm run eslint -- index.js test/**/*.js",
"lintfix": "npm run lint -- --fix",
"postpublish": "git push origin --follow-tags",
"postsnap": "npm run lintfix",
"posttest": "npm run lint",
"postversion": "npm publish",
"preversion": "npm test",
"snap": "tap",
"test": "tap"
},
"tap": {
"test-env": [
"LC_ALL=sk"
],
"check-coverage": true
},
"version": "1.1.4"
}
LICENSE 0000644 00000001375 15170146047 0005564 0 ustar 00 The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
index.js 0000644 00000001766 15170146047 0006230 0 ustar 00 const isObj = val => !!val && !Array.isArray(val) && typeof val === 'object'
const compare = (ak, bk, prefKeys) =>
prefKeys.includes(ak) && !prefKeys.includes(bk) ? -1
: prefKeys.includes(bk) && !prefKeys.includes(ak) ? 1
: prefKeys.includes(ak) && prefKeys.includes(bk)
? prefKeys.indexOf(ak) - prefKeys.indexOf(bk)
: ak.localeCompare(bk, 'en')
const sort = (replacer, seen) => (key, val) => {
const prefKeys = Array.isArray(replacer) ? replacer : []
if (typeof replacer === 'function')
val = replacer(key, val)
if (!isObj(val))
return val
if (seen.has(val))
return seen.get(val)
const ret = Object.entries(val).sort(
([ak, av], [bk, bv]) =>
isObj(av) === isObj(bv) ? compare(ak, bk, prefKeys)
: isObj(av) ? 1
: -1
).reduce((set, [k, v]) => {
set[k] = v
return set
}, {})
seen.set(val, ret)
return ret
}
module.exports = (obj, replacer, space = 2) =>
JSON.stringify(obj, sort(replacer, new Map()), space)
+ (space ? '\n' : '')