@discoveryjs/natural-compare
v1.1.0
Published
Compare strings in a natural order
Downloads
441,836
Readme
@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);
// file1.js
// file2.js
// file9.js
// file10.js
// file12.js
// standart sorting
[
'file10.js',
'file1.js',
'file2.js',
'file12.js',
'file9.js'
].sort();
// file1.js
// file10.js
// file12.js
// file2.js
// file9.js
In browser:
<!-- ESM -->
<script type="module">
import { natualCompare } from "@discoveryjs/natural-compare/dist/natural-compare.esm.js";
array.sort(naturalCompare);
</script>
<!-- Old way -->
<script src="@discoveryjs/natural-compare/dist/natural-compare.js"></script>
<script>
array.sort(naturalCompare);
</script>
License
MIT