You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

sort-object-keys

Package Overview
Dependencies
Maintainers
1
Versions
8
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.1.3
to
2.0.0
+15
index.d.ts
// From DefinitelyTyped by Emily Marigold Klassen <https://github.com/forivall>
/**
* Sort an object's keys, including an optional key list.
*
* @param object - An object.
* @param sortWith - An ordered keys array or a sort function.
* @returns Sorted object.
*/
declare function sortObjectByKeyNameList<T>(
object: T,
sortWith?: ReadonlyArray<keyof T> | ((a: keyof T, b: keyof T) => number),
): T;
export default sortObjectByKeyNameList;
+7
-6

@@ -1,5 +0,6 @@

module.exports = function sortObjectByKeyNameList(object, sortWith) {
var keys;
var sortFn;
const has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
export default function sortObjectByKeyNameList(object, sortWith) {
let keys, sortFn;
if (typeof sortWith === 'function') {

@@ -11,5 +12,5 @@ sortFn = sortWith;

var objectKeys = Object.keys(object);
return (keys || []).concat(objectKeys.sort(sortFn)).reduce(function(total, key) {
if (objectKeys.indexOf(key) !== -1) {
const objectKeys = Object.keys(object);
return [...(keys ?? []), ...objectKeys.sort(sortFn)].reduce((total, key) => {
if (has(object, key)) {
total[key] = object[key];

@@ -16,0 +17,0 @@ }

{
"name": "sort-object-keys",
"version": "1.1.3",
"version": "2.0.0",
"description": "Sort an object's keys, including an optional key list",

@@ -14,28 +14,30 @@ "keywords": [

},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/keithamus/sort-object-keys.git"
},
"license": "MIT",
"author": "Keith Cirkel <npm@keithcirkel.co.uk> (http://keithcirkel.co.uk/)",
"type": "module",
"exports": {
".": {
"import": {
"types": "./index.d.ts",
"default": "./index.js"
}
}
},
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"main": "index.js",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/keithamus/sort-object-keys.git"
},
"scripts": {
"semantic-release": "travis-after-all && semantic-release pre && npm publish && semantic-release post",
"sort": "sort-package-json",
"test": "node test.js"
},
"config": {
"ghooks": {
"pre-commit": "npm t",
"commit-msg": "validate-commit-msg"
}
},
"devDependencies": {
"ghooks": "^1.0.1",
"semantic-release": "^4.3.5",
"travis-after-all": "^1.4.4",
"validate-commit-msg": "^2.4.1"
"sort-package-json": "^3.4.0"
}
}