Package Exports
- alphanumeric-sort
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (alphanumeric-sort) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Alphanumeric sort for JavaScript
A usable, portable, algorithm/comparator for sorting things like filenames and addresses that contain numbers.
For example
The algorithm will sort the following files in this order:
file 1.txt
file 5.txt
file 39.txt
file 100.txtas opposed to this order (which is what the default JavaScript comparator produces)
file 1.txt
file 100.txt
file 39.txt
file 5.txtUsage
The library provides a comparator that can be fed to Array.prototype.sort.
First you do
> npm install alphanumeric-sortAnd then you do
var compare = require('alphanumeric-sort').compare;
["file 100.txt", "file 5.txt", "file 39.txt"].sort(compare);
//=> ["file 5.txt", "file 39.txt", "file 100.txt"]Caveats
The implementation is quick & dirty - it just prepends "enough" zeroes before every digit sequence in the string before comparing lexicographically.
The maximum amount of consecutive digits is 20, after that all bets are off.
(Thanks for the idea, http://www.bennadel.com/blog/2495-User-Friendly-Sort-Of-Alpha-Numeric-Data-In-JavaScript.htm)
It's not probably very fast. (To be honest, I haven't really tested.)