https://github.com/discoveryjs/natural-compare
Compare strings in a natural order
https://github.com/discoveryjs/natural-compare
Last synced: 12 months ago
JSON representation
Compare strings in a natural order
- Host: GitHub
- URL: https://github.com/discoveryjs/natural-compare
- Owner: discoveryjs
- License: mit
- Created: 2022-03-14T16:50:56.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-16T22:11:30.000Z (almost 4 years ago)
- Last Synced: 2025-07-10T09:06:49.726Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 154 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@discoveryjs/natural-compare)
[](https://github.com/discoveryjs/natural-compare/actions/workflows/build.yml)
[](https://coveralls.io/github/discoveryjs/natural-compare?branch=main)
[](https://bundlephobia.com/result?p=@discoveryjs/natural-compare)
[](https://bundlephobia.com/result?p=@discoveryjs/natural-compare)
# @discoveryjs/natural-compare
Compare strings in a natural order
## Install
```
npm install @discoveryjs/natural-compare
```
## Usage
```js
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:
```html
import { natualCompare } from "@discoveryjs/natural-compare/dist/natural-compare.esm.js";
array.sort(naturalCompare);
array.sort(naturalCompare);
```
## License
MIT