Socket
Socket
Sign inDemoInstall

sort-keys

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.2.0 to 5.0.0

41

index.d.ts

@@ -1,15 +0,15 @@

declare namespace sortKeys {
interface Options {
/**
Recursively sort keys, including keys of objects inside arrays.
/* eslint-disable import/export */
@default false
*/
readonly deep?: boolean;
export interface Options {
/**
Recursively sort keys, including keys of objects inside arrays.
/**
[Compare function.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
*/
readonly compare?: (left: string, right: string) => number;
}
@default false
*/
readonly deep?: boolean;
/**
[Compare function.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
*/
readonly compare?: (left: string, right: string) => number;
}

@@ -24,3 +24,3 @@

```
import sortKeys = require('sort-keys');
import sortKeys from 'sort-keys';

@@ -45,12 +45,9 @@ sortKeys({c: 0, a: 0, b: 0});

*/
declare function sortKeys<T extends {[key: string]: any}>(
export default function sortKeys<T extends Record<string, any>>(
object: T,
options?: sortKeys.Options
options?: Options
): T;
declare function sortKeys<T>(
object: Array<T>,
options?: sortKeys.Options
): Array<T>;
export = sortKeys;
export default function sortKeys<T>(
object: T[],
options?: Options
): T[];

@@ -1,5 +0,4 @@

'use strict';
const isPlainObject = require('is-plain-obj');
import isPlainObject from 'is-plain-obj';
module.exports = (object, options = {}) => {
export default function sortKeys(object, options = {}) {
if (!isPlainObject(object) && !Array.isArray(object)) {

@@ -9,3 +8,3 @@ throw new TypeError('Expected a plain object or array');

const {deep} = options;
const {deep, compare} = options;
const seenInput = [];

@@ -16,3 +15,2 @@ const seenOutput = [];

const seenIndex = seenInput.indexOf(array);
if (seenIndex !== -1) {

@@ -32,3 +30,3 @@ return seenOutput[seenIndex];

if (isPlainObject(item)) {
return sortKeys(item);
return _sortKeys(item);
}

@@ -42,5 +40,4 @@

const sortKeys = object => {
const _sortKeys = object => {
const seenIndex = seenInput.indexOf(object);
if (seenIndex !== -1) {

@@ -51,3 +48,3 @@ return seenOutput[seenIndex];

const result = {};
const keys = Object.keys(object).sort(options.compare);
const keys = Object.keys(object).sort(compare);

@@ -64,3 +61,3 @@ seenInput.push(object);

} else {
newValue = deep && isPlainObject(value) ? sortKeys(value) : value;
newValue = deep && isPlainObject(value) ? _sortKeys(value) : value;
}

@@ -81,3 +78,3 @@

return sortKeys(object);
};
return _sortKeys(object);
}
{
"name": "sort-keys",
"version": "4.2.0",
"version": "5.0.0",
"description": "Sort the keys of an object",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},

@@ -33,12 +35,15 @@ "scripts": {

"recursive",
"recursively"
"recursively",
"array",
"sorted",
"sorting"
],
"dependencies": {
"is-plain-obj": "^2.0.0"
"is-plain-obj": "^4.0.0"
},
"devDependencies": {
"ava": "^2.2.0",
"tsd": "^0.7.4",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

@@ -1,2 +0,2 @@

# sort-keys [![Build Status](https://travis-ci.com/sindresorhus/sort-keys.svg?branch=master)](https://travis-ci.com/github/sindresorhus/sort-keys)
# sort-keys

@@ -16,3 +16,3 @@ > Sort the keys of an object

```js
const sortKeys = require('sort-keys');
import sortKeys from 'sort-keys';

@@ -19,0 +19,0 @@ sortKeys({c: 0, a: 0, b: 0});

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc