🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

javascript-natural-sort

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
j

javascript-natural-sort

Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license

0.7.1
latest
100

Supply Chain Security

100

Vulnerability

89

Quality

78

Maintenance

100

License

Version published
Maintainers
1
Created

What is javascript-natural-sort?

The javascript-natural-sort npm package provides a natural sorting algorithm for JavaScript. It allows you to sort strings in a way that is intuitive to humans, such as sorting 'item2' before 'item10'. This is particularly useful for sorting lists of filenames, version numbers, or any other strings that contain numbers.

What are javascript-natural-sort's main functionalities?

Basic Natural Sort

This feature allows you to sort an array of strings in a natural order. The code sample demonstrates sorting a list of items where the numerical part of the strings is taken into account.

const naturalSort = require('javascript-natural-sort');
const items = ['item10', 'item2', 'item1'];
items.sort(naturalSort);
console.log(items); // Output: ['item1', 'item2', 'item10']

Case Insensitive Sort

This feature allows you to perform a case-insensitive natural sort. The code sample shows how the sorting algorithm treats 'Item10' and 'item10' as equivalent.

const naturalSort = require('javascript-natural-sort');
const items = ['Item10', 'item2', 'item1'];
items.sort(naturalSort);
console.log(items); // Output: ['item1', 'item2', 'Item10']

Locale Aware Sort

This feature allows you to sort strings in a locale-aware manner. The code sample demonstrates sorting a list of strings with special characters.

const naturalSort = require('javascript-natural-sort');
const items = ['ä', 'a', 'z'];
items.sort(naturalSort);
console.log(items); // Output: ['a', 'ä', 'z']

Other packages similar to javascript-natural-sort

FAQs

Package last updated on 02 Jan 2014

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