![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
sort-keys-recursive
Advanced tools
Sort the keys of an object recursively.
npm install sort-keys-recursive --save
const sortKeysRecursive = require('sort-keys-recursive')
const object = {
c: 0,
a: {
c: ['c', 'a', 'b'],
a: 0,
b: 0
},
b: 0
}
const output = sortKeysRecursive(object)
console.log(output)
// {
// a: {
// a: 0,
// b: 0,
// c: ['a', 'b', 'c']
// },
// b: 0,
// c: 0
// };
Required
Type: array
|object
The collection to be sorted.
Type: function
Type: array
Don't sort the Array at the specified keys, if any.
Type: array
Don't sort the Object at the specified keys, if any.
ignoreArrayAtKeys
and ignoreObjectAtKeys
const options = {
ignoreArrayAtKeys: [ // Don't sort the Array at the specified keys, if any.
'b'
],
ignoreObjectAtKeys: [ // Don't sort the Object at the specified keys, if any.
'a'
]
}
const input = {
a: { // This Object will not be sorted.
a: 'a',
b: 'b',
c: 'c',
d: ['a', 'c', 'b']
},
b: ['a', 'c', 'b'], // This Array will not be sorted.
d: ['a', 'c', 'b']
}
const output = sort(object, options)
console.log(output)
// {
// a: {
// a: 'a',
// b: 'b',
// c: 'c',
// d: ['a', 'c', 'b']
// },
// b: ['a', 'c', 'b'],
// d: ['a', 'b', 'c']
// }
compareFunction
You can pass a custom sort function as compareFunction
. This function is passed to Javascript sort()
, that sorts in alphabetical order by default. The custom function should return zero, a negative or positive value:
const reverseAlphabeticalSort = function (a, b) {
return a < b
}
const options = {
compareFunction: reverseAlphabeticalSort
}
const object = {
a: {
a: 0,
c: ['c', 'a', 'b'],
b: 0
},
c: 0,
b: 0
}
const output = sort(object, options)
console.log(output)
// {
// c: 0,
// b: 0,
// a: {
// c: ['c', 'b', 'a'],
// b: 0,
// a: 0
// }
// }
MIT © Kiko Beats
FAQs
Sort the keys of an object recursively
The npm package sort-keys-recursive receives a total of 3,364 weekly downloads. As such, sort-keys-recursive popularity was classified as popular.
We found that sort-keys-recursive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.