
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
javascript-natural-sort
Advanced tools
Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
Supply Chain Security
Vulnerability
Quality
Maintenance
License
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.
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']
The 'natural-sort' package provides a similar natural sorting algorithm. It is lightweight and easy to use, but may not have as many features as 'javascript-natural-sort'.
The 'alphanum-sort' package offers alphanumeric sorting capabilities. It is optimized for performance and can handle large datasets efficiently, but may lack some of the locale-aware features of 'javascript-natural-sort'.
The 'string-natural-compare' package provides a natural comparison function for strings. It is highly customizable and can be used in various sorting scenarios, but might require more configuration compared to 'javascript-natural-sort'.
>>> ['10',9,2,'1','4'].sort(naturalSort)
['1',2,'4',9,'10']
>>> ['10.0401',10.022,10.042,'10.021999'].sort(naturalSort)
['10.021999',10.022,'10.0401',10.042]
>>> ['10.04f','10.039F','10.038d','10.037D'].sort(naturalSort)
['10.037D','10.038d','10.039F','10.04f']
>>> ['1.528535047e5','1.528535047e7','1.528535047e3'].sort(naturalSort)
['1.528535047e3','1.528535047e5','1.528535047e7']
>>> ['192.168.0.100','192.168.0.1','192.168.1.1'].sort(naturalSort)
['192.168.0.1','192.168.0.100','192.168.1.1']
>>> ['car.mov','01alpha.sgi','001alpha.sgi','my.string_41299.tif'].sort(naturalSort)
['001alpha.sgi','01alpha.sgi','car.mov','my.string_41299.tif'
>>> ['10/12/2008','10/11/2008','10/11/2007','10/12/2007'].sort(naturalSort)
['10/11/2007', '10/12/2007', '10/11/2008', '10/12/2008']
>>> ['$10002.00','$10001.02','$10001.01'].sort(naturalSort)
['$10001.01','$10001.02','$10002.00']
>>> ['1 Title - The Big Lebowski','1 Title - Gattaca','1 Title - Last Picture Show'].sort(naturalSort)
['1 Title - Gattaca','1 Title - Last Picture Show','1 Title - The Big Lebowski']
>>> ['a', 'B'].sort(naturalSort);
['B', 'a']
>>> naturalSort.insensitive = true;
>>> ['a', 'B'].sort(naturalSort);
['a', 'B']
FAQs
Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
The npm package javascript-natural-sort receives a total of 2,322,578 weekly downloads. As such, javascript-natural-sort popularity was classified as popular.
We found that javascript-natural-sort demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.