# num-sort

> Sort an array of numbers

Latest version **4.0.0** (published 2025-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install num-sort
pnpm add num-sort
yarn add num-sort
bun add num-sort
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-09-18 |
| First published | 2015-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | sort, sorter, compare, comparator, number, numbers, order, asc, ascending, desc, descending |

## Links

- npm: https://www.npmjs.com/package/num-sort
- Repository: https://github.com/sindresorhus/num-sort
- Homepage: https://github.com/sindresorhus/num-sort#readme
- Issues: https://github.com/sindresorhus/num-sort/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/num-sort

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2025-09-18
- 3.0.0 — 2021-04-08
- 2.1.0 — 2020-06-01
- 2.0.0 — 2019-04-23
- 1.0.0 — 2015-05-31

## README

# num-sort

> Sort an array of numbers

## Install

```sh
npm install num-sort
```

## Usage

```js
import {numberSortAscending, numberSortDescending} from 'num-sort';

[9, -3, -Infinity, 24, NaN].sort(numberSortAscending);
//=> [NaN, -Infinity, -3, 9, 24]

[9n, 3n, 24n, -5n].sort(numberSortAscending);
//=> [-5n, 3n, 9n, 24n]

[9, -3, -Infinity, 24, NaN].sort(numberSortDescending);
//=> [24, 9, -3, -Infinity, NaN]

[9n, 3n, 24n, -5n].sort(numberSortDescending);
//=> [24n, 9n, 3n, -5n]
```

## API

### numberSortAscending

Ascending sort comparator.

Supports both `number` and `bigint` types.

### numberSortDescending

Descending sort comparator.

Supports both `number` and `bigint` types.

## Related

- [alpha-sort](https://github.com/sindresorhus/alpha-sort) - Alphabetically sort an array of strings

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