@discoveryjs/natural-compare
Compare strings in a natural order
Install
npm install @discoveryjs/natural-compare
Usage
import { naturalCompare } from '@discoveryjs/natural-compare';
[
'file10.js',
'file1.js',
'file2.js',
'file12.js',
'file9.js'
].sort(naturalCompare);
[
'file10.js',
'file1.js',
'file2.js',
'file12.js',
'file9.js'
].sort();
In browser:
<script type="module">
import { natualCompare } from "@discoveryjs/natural-compare/dist/natural-compare.esm.js";
array.sort(naturalCompare);
</script>
<script src="@discoveryjs/natural-compare/dist/natural-compare.js"></script>
<script>
array.sort(naturalCompare);
</script>
License
MIT