@cablanchard/koelle-sort
v0.1.0
Published
koelle-sort - also known as alphanum sort
Downloads
3,171
Readme
Koelle Sort
Also known as alphanum sort
alphanum sort is designed to produce more sensible results than ascii sort for certain use cases
| ASCII Sort | Koelle's Alphanum Sort | |:-----------|:-----------------------| | z1.doc | z1.doc | | z10.doc | z2.doc | | z100.doc | z3.doc | | z101.doc | z4.doc | | z102.doc | z5.doc | | z11.doc | z6.doc | | z12.doc | z7.doc | | z13.doc | z8.doc | | z14.doc | z9.doc | | z15.doc | z10.doc | | z16.doc | z11.doc | | z17.doc | z12.doc | | z18.doc | z13.doc | | z19.doc | z14.doc | | z2.doc | z15.doc | | z20.doc | z16.doc | | z3.doc | z17.doc | | z4.doc | z18.doc | | z5.doc | z19.doc | | z6.doc | z20.doc | | z7.doc | z100.doc | | z8.doc | z101.doc | | z9.doc | z102.doc |
Behaviour
- Sorts alphanumeric strings
- Sorts numbers
- Sorts letters
- Sorts a number of different date formats
- Sorts decimal numbers
- Sorts zero padded numbers
- Sorts simple and complex filenames
- Sorts empty strings
- Sorts by number first
Notable Unsupported Behaviour
- Does not skip whitespace
- Does not support numbers separated by multiple decimal points (e.g. IP Address, Semver formatting)
Usage
npm install @cablanchard/koelle-sort
const { alphanum } = require("@cablanchard/koelle-sort");
const sorted = [
"file10.txt",
"file1.txt",
"file2.txt",
].sort(alphanum);
/**
* [
* "file1.txt",
* "file2.txt",
* "file10.txt",
* ]
*/
License
Based on the alphanum algorithm developed by Dave Koelle
This implementation is MIT licensed