sort-package-json
Advanced tools
Comparing version 1.32.3 to 1.33.0
23
index.js
@@ -154,3 +154,3 @@ #!/usr/bin/env node | ||
const sortOrder = fields.map(({ key }) => key) | ||
const defaultSortOrder = fields.map(({ key }) => key) | ||
@@ -174,2 +174,11 @@ function editStringJSON(json, over) { | ||
const isPrivateKey = key => key[0] === '_' | ||
const partition = (array, predicate) => | ||
array.reduce( | ||
(result, value) => { | ||
result[predicate(value) ? 0 : 1].push(value) | ||
return result | ||
}, | ||
[[], []], | ||
) | ||
function sortPackageJson(jsonIsh, options = {}) { | ||
@@ -179,4 +188,12 @@ return editStringJSON( | ||
onObject(json => { | ||
const newJson = sortObjectKeys(json, options.sortOrder || sortOrder) | ||
let sortOrder = options.sortOrder ? options.sortOrder : defaultSortOrder | ||
if (Array.isArray(sortOrder)) { | ||
const keys = Object.keys(json) | ||
const [privateKeys, publicKeys] = partition(keys, isPrivateKey) | ||
sortOrder = [...sortOrder, ...publicKeys.sort(), ...privateKeys.sort()] | ||
} | ||
const newJson = sortObjectKeys(json, sortOrder) | ||
for (const { key, over } of fields) { | ||
@@ -193,3 +210,3 @@ if (over && newJson[key]) newJson[key] = over(newJson[key]) | ||
module.exports.sortPackageJson = sortPackageJson | ||
module.exports.sortOrder = sortOrder | ||
module.exports.sortOrder = defaultSortOrder | ||
@@ -196,0 +213,0 @@ if (require.main === module) { |
{ | ||
"name": "sort-package-json", | ||
"version": "1.32.3", | ||
"version": "1.33.0", | ||
"description": "Sort an Object or package.json based on the well-known package.json keys", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
13401
241