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

sort-keys

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-keys - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

7

index.d.ts
declare namespace sortKeys {
interface Options {
/**
Recursively sort keys.
Recursively sort keys, including keys of objects inside arrays.

@@ -32,2 +32,5 @@ @default false

sortKeys({b: [{b: 0, a: 0}], a: 0}, {deep: true});
//=> {a: 0, b: [{a: 0, b: 0}]}
sortKeys({c: 0, a: 0, b: 0}, {

@@ -39,3 +42,3 @@ compare: (a, b) => -a.localeCompare(b)

*/
declare function sortKeys<T extends {[key: string]: unknown}>(
declare function sortKeys<T extends {[key: string]: any}>(
object: T,

@@ -42,0 +45,0 @@ options?: sortKeys.Options

@@ -13,2 +13,28 @@ 'use strict';

const deepSortArray = array => {
const seenIndex = seenInput.indexOf(array);
if (seenIndex !== -1) {
return seenOutput[seenIndex];
}
const result = [];
seenInput.push(array);
seenOutput.push(result);
result.push(...array.map(item => {
if (Array.isArray(item)) {
return deepSortArray(item);
}
if (isPlainObject(item)) {
return sortKeys(item);
}
return item;
}));
return result;
};
const sortKeys = object => {

@@ -31,3 +57,3 @@ const seenIndex = seenInput.indexOf(object);

if (deep && Array.isArray(value)) {
result[key] = value.map(arrayValue => isPlainObject(arrayValue) ? sortKeys(arrayValue) : arrayValue);
result[key] = deepSortArray(value);
continue;

@@ -34,0 +60,0 @@ }

{
"name": "sort-keys",
"version": "3.0.0",
"version": "4.0.0",
"description": "Sort the keys of an object",

@@ -37,6 +37,6 @@ "license": "MIT",

"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"ava": "^2.2.0",
"tsd": "^0.7.4",
"xo": "^0.24.0"
}
}

@@ -26,2 +26,5 @@ # sort-keys [![Build Status](https://travis-ci.org/sindresorhus/sort-keys.svg?branch=master)](https://travis-ci.org/sindresorhus/sort-keys)

sortKeys({b: [{b: 0, a: 0}], a: 0}, {deep: true});
//=> {a: 0, b: [{a: 0, b: 0}]}
sortKeys({c: 0, a: 0, b: 0}, {

@@ -36,3 +39,3 @@ compare: (a, b) => -a.localeCompare(b)

### sortKeys(object, [options])
### sortKeys(object, options?)

@@ -54,3 +57,3 @@ Returns a new object with sorted keys.

Recursively sort keys.
Recursively sort keys, including keys of objects inside arrays.

@@ -64,4 +67,12 @@ ##### compare

## License
---
MIT © [Sindre Sorhus](https://sindresorhus.com)
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-sort-keys?utm_source=npm-sort-keys&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
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