Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-object-keys

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-object-keys - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.travis.yml

12

index.js

@@ -1,3 +0,11 @@

module.exports = function sortObjectByKeyNameList(object, keys) {
return (keys || []).concat(Object.keys(object).sort()).reduce((total, key) => {
module.exports = function sortObjectByKeyNameList(object, sortWith) {
var keys;
var sortFn;
if (typeof sortWith === 'function') {
sortFn = sortWith;
} else {
keys = sortWith;
}
return (keys || []).concat(Object.keys(object).sort(sortFn)).reduce((total, key) => {
total[key] = object[key];

@@ -4,0 +12,0 @@ return total;

4

package.json
{
"name": "sort-object-keys",
"version": "1.0.0",
"version": "1.1.0",
"description": "Sort an object's keys, including an optional key list",
"main": "index.js",
"scripts": {
"test": "test.js"
"test": "node test.js"
},

@@ -9,0 +9,0 @@ "repository": {

Sort Object
[![Build Status](https://travis-ci.org/keithamus/sort-object-keys.svg)](https://travis-ci.org/keithamus/sort-object-keys)
Returns a copy of an object with all keys sorted.
You can pass an array of keys, which it will use for ordering - to provide custom sorts.
The second argument is optional and is used for ordering - to provide custom sorts. You can either pass an array containing ordered keys or a function to sort the keys (same signature as in [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)).

@@ -34,2 +36,20 @@ ```js

}));
function removeKeyAncCompareIndex(keyA, keyB){
var a = parseInt(keyA.slice(4));
var b = parseInt(keyB.slice(4));
return a - b;
}
assert.equal(JSON.stringify(sortObject({
"key-1": 1,
"key-3": 1,
"key-10": 1,
"key-2": 1,
}, removeKeyAncCompareIndex)), JSON.stringify({
"key-1": 1,
"key-2": 1,
"key-3": 1,
"key-10": 1,
}));
```

@@ -27,1 +27,19 @@ const assert = require('assert');

}));
function removeKeyAncCompareIndex(keyA, keyB){
var a = parseInt(keyA.slice(4));
var b = parseInt(keyB.slice(4));
return a - b;
}
assert.equal(JSON.stringify(sortObject({
"key-1": 1,
"key-3": 1,
"key-10": 1,
"key-2": 1,
}, removeKeyAncCompareIndex)), JSON.stringify({
"key-1": 1,
"key-2": 1,
"key-3": 1,
"key-10": 1,
}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc