# node-natural-sort

> Natural Sort algorithm for Javascript - Version 0.8.6 - Released under MIT license

Latest version **0.8.7** (published 2018-06-30) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install node-natural-sort
pnpm add node-natural-sort
yarn add node-natural-sort
bun add node-natural-sort
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.8.7 |
| Published | 2018-06-30 |
| First published | 2016-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 55 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Jim Palmer |
| Maintainers | posicore |
| Keywords | sort, alphanum, alphanumeric, natural, human, javascript, array, sorting, case sensitive, case insensitive, ascending, descending |

## Links

- npm: https://www.npmjs.com/package/node-natural-sort
- Repository: https://github.com/yobacca/node-natural-sort
- Issues: https://github.com/yobacca/node-natural-sort/issues
- npm.io page: https://npm.io/package/node-natural-sort

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.8.7 (latest) — 2018-06-30
- 0.8.6 — 2016-09-16
- 0.8.5 — 2016-05-13
- 0.8.4 — 2016-05-13
- 0.8.3 — 2016-05-13
- 0.8.2 — 2016-05-10
- 0.8.1 — 2016-04-04

## README

# Status of this module

This module is deprecated. Please use [natural-orderby](https://www.npmjs.com/package/natural-orderby) instead. It is more mature, performant and offers additional-features.

# node-natural-sort

> A Node.js package containing a fast and lightweight function to be used in conjunction with Array.prototype.sort() or likewise functions of other (immutable) data structures using the default bubble sort. This will properly sort padded numbers, numbers preceding text, dates, floats, unicode, etc.
> Written in ES6, transpiled to ES5, includes unit tests using Mocha and Chai and code coverage using Istanbul.

## Install

```
npm install node-natural-sort
```

## API

### naturalSort()

Returns a compare function that defines the sort order due to the given `options`.

```javascript
naturalSort(options?: {[key: string]: V}): comparator: (valueA: V, valueB: V) => number
```

#### JSON Schema for `options` parameter

```json
{
  "properties": {
      "caseSensitive": {
        "type": "boolean"
      },
      "order": {
        "enum": [ "ASC", "DESC" ]
      }
  },
  "additionalProperties": false
}
```

##### caseSensitive

Compare items case-sensitive.
Defaults to `true`.

##### order

Sorting in ascending or descending order.
Defaults to `"ASC"`.

#### Examples

##### Simple numerics

```javascript
['10', 9, 2, '1', '4'].sort(naturalSort())
// ['1', 2, '4', 9, '10']
```

##### Floats

```javascript
['10.0401', 10.022, 10.042, '10.021999'].sort(naturalSort())
// ['10.021999', 10.022, '10.0401', 10.042]
```

##### Float & decimal notation

```javascript
['10.04f', '10.039F', '10.038d', '10.037D'].sort(naturalSort())
// ['10.037D', '10.038d', '10.039F', '10.04f']
```

##### Scientific notation

```javascript
['1.528535047e5', '1.528535047e7', '1.528535047e3'].sort(naturalSort())
// ['1.528535047e3', '1.528535047e5', '1.528535047e7']
```

##### IP addresses

```javascript
['192.168.0.100', '192.168.0.1', '192.168.1.1'].sort(naturalSort())
// ['192.168.0.1', '192.168.0.100', '192.168.1.1']
```

##### Filenames

```javascript
['car.mov', '01alpha.sgi', '001alpha.sgi', 'my.string_41299.tif'].sort(naturalSort())
// ['001alpha.sgi', '01alpha.sgi', 'car.mov', 'my.string_41299.tif']
```

##### Dates

```javascript
['10/12/2008', '10/11/2008', '10/11/2007', '10/12/2007'].sort(naturalSort())
// ['10/11/2007', '10/12/2007', '10/11/2008', '10/12/2008']

['Mon, 15 Jun 2009 20:45:30 GMT', 'Mon, 3 May 2010 17:45:30 GMT', 'Mon, 15 Jun 2009 17:45:30 GMT'].sort(naturalSort())
// ['Mon, 15 Jun 2009 17:45:30 GMT', 'Mon, 15 Jun 2009 20:45:30 GMT', 'Mon, 3 May 2010 17:45:30 GMT']
```

##### Money

```javascript
['$10002.00', '$10001.02', '$10001.01'].sort(naturalSort())
// ['$10001.01', '$10001.02', '$10002.00']
```

##### By default - case-sensitive sorting

```javascript
['A', 'b', 'C', 'd', 'E', 'f'].sort(naturalSort());
// ['A', 'C', 'E', 'b', 'd', 'f']
```

##### To enable case-insensitive sorting

```javascript
['A', 'C', 'E', 'b', 'd', 'f'].sort(naturalSort({caseSensitive: false}));
// ['A', 'b', 'C', 'd', 'E', 'f']
```

##### By default - ascending order

```javascript
['a', 'c', 'f', 'd', 'e', 'b'].sort(naturalSort());
// ['a', 'b', 'c', 'd', 'e', 'f']
```

##### To enable descending order

```javascript
['a', 'c', 'f', 'd', 'e', 'b'].sort(naturalSort({order: 'DESC'}));
// ['f', 'e', 'd', 'c', 'b', 'a']
```

## Development

The following gulp tasks are provided.

### Test

```
gulp test
```

Execute Mocha/Chai tests and process code coverage recording using Istanbul.

### TDD

```
gulp tdd
```

Watch changes, execute Mocha/Chai tests and process code coverage recording using Istanbul.

### Build (default task)

```
gulp
```

Transpile the source. (Run primarily by npm during the prepublish step)

##Credits

Based on [javascript-natural-sort](https://github.com/overset/javascript-natural-sort) by Jim Palmer.

## License

[MIT](LICENSE.md) © [Olaf Ennen](https://github.com/yobacca)

---
_Source: https://npm.io/package/node-natural-sort · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
