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

Sort an object's keys, including an optional key list

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9M
decreased by-11.26%
Maintainers
1
Weekly downloads
 
Created

What is sort-object-keys?

The sort-object-keys npm package is designed to sort the keys of an object based on a specific order provided by the user or in natural order if no order is specified. This can be particularly useful for ensuring consistent object key ordering, for example, when formatting JSON files or ensuring consistent object structures in code.

What are sort-object-keys's main functionalities?

Sort keys in natural order

This feature allows the user to sort the keys of an object in ascending natural order. It is useful for creating predictable object key orders.

const sortObjectKeys = require('sort-object-keys');
const obj = {b: 2, a: 1, c: 3};
const sortedObj = sortObjectKeys(obj);
console.log(sortedObj); // Output: {a: 1, b: 2, c: 3}

Sort keys according to a custom order

This feature allows the user to sort the keys of an object based on a custom order array provided. This is particularly useful when a specific key order is required for readability or functionality.

const sortObjectKeys = require('sort-object-keys');
const order = ['c', 'a', 'b'];
const obj = {b: 2, a: 1, c: 3};
const sortedObj = sortObjectKeys(obj, order);
console.log(sortedObj); // Output: {c: 3, a: 1, b: 2}

Other packages similar to sort-object-keys

Keywords

FAQs

Package last updated on 02 Dec 2015

Did you know?

Socket

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.

Install

Related posts

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