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

natural-orderby

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natural-orderby

Lightweight and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
decreased by-8.31%
Maintainers
1
Weekly downloads
 
Created

What is natural-orderby?

The natural-orderby package is a utility for sorting arrays of strings or objects in a natural order, which means it sorts based on human-friendly sorting rules rather than strict lexicographical order. This is particularly useful for sorting strings that contain numbers, as it will sort them in a way that is more intuitive to humans.

What are natural-orderby's main functionalities?

Sorting an array of strings

Sorts an array of strings containing numbers in a natural order, so that 'a2' comes before 'a12'.

["a1", "a12", "a2"].sort(compare())

Sorting an array of objects

Sorts an array of objects based on the specified object key in a natural order.

objects.sort(compareOn(obj => obj.key))

Sorting with a custom accessor

Sorts an array of objects with a custom accessor, such as converting a date string to a Date object before sorting.

objects.sort(compareOn(obj => obj.date, { accessor: date => new Date(date) }))

Other packages similar to natural-orderby

Keywords

FAQs

Package last updated on 17 Jan 2019

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