# multiple-array-sorter

> Sort multpile arrays at once according to master sort

Latest version **2.0.0** (published 2026-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install multiple-array-sorter
pnpm add multiple-array-sorter
yarn add multiple-array-sorter
bun add multiple-array-sorter
```

## Health

**Score 70/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-09-23 |
| First published | 2020-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.12.0 |
| Dependencies | 1 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alberto Rico |
| Maintainers | alrico88 |
| Keywords | arrays, sort, multiple, index |

## Links

- npm: https://www.npmjs.com/package/multiple-array-sorter
- Repository: https://github.com/alrico88/multiple-array-sorter
- npm.io page: https://npm.io/package/multiple-array-sorter

## Dependencies (1)

- [es-toolkit](https://npm.io/package/es-toolkit.md) ^1.52.0

## Recent versions

- 2.0.0 (latest) — 2026-09-23
- 1.1.0 — 2020-10-29
- 1.0.0 — 2020-10-29
- 0.1.1 — 2020-06-29
- 0.1.0 — 2020-06-29

## README

# Multiple Array Sorter

Sort a master array and apply its ordering to related arrays.

## Installation

```sh
npm install multiple-array-sorter
```

The package ships both ES modules and CommonJS. `import` resolves to `dist/index.mjs`, `require` resolves to `dist/index.js`, and the same TypeScript declarations cover both.

```ts
// ESM
import { sortMultipleArrays } from 'multiple-array-sorter';
```

```js
// CommonJS
const { sortMultipleArrays } = require('multiple-array-sorter');
```

## Usage

```ts
import { sortMultipleArrays } from 'multiple-array-sorter';

const { masterArray, sortedArrays } = sortMultipleArrays(
  [
    { name: 'Ada', stats: { score: 10 } },
    { name: 'Linus', stats: { score: 30 } },
    { name: 'Grace', stats: { score: 20 } },
  ],
  { sortProp: 'stats.score', sortOrder: 'asc' },
  [['ada-row', 'linus-row', 'grace-row']],
);

// masterArray: Ada, Grace, Linus
// sortedArrays[0]: ['ada-row', 'grace-row', 'linus-row']
```

`sortOrder` defaults to `'desc'`. `sortProp` is optional; without it, values in the master array are compared directly. Nested properties use dot paths, such as `'stats.score'`. Every related array must have the same length as the master array or the function throws.

## Other exports

`getMoveMap` returns the sorted master array and the index map used to reorder related data:

```ts
import {
  getMoveMap,
  sortArrayBasedOnMoveMap,
} from 'multiple-array-sorter';

const { sortedMasterArray, moveMap } = getMoveMap([3, 1, 2], {
  sortOrder: 'asc',
});
// sortedMasterArray: [1, 2, 3]
// moveMap: [{ from: 1, to: 0 }, { from: 2, to: 1 }, { from: 0, to: 2 }]

sortArrayBasedOnMoveMap(['three', 'one', 'two'], moveMap);
// ['one', 'two', 'three']
```

All functions and the `SortParams`, `MoveMapItem`, and `SortResult` types are named exports. `sortMultipleArrays` is also the default export (`import sortMultipleArrays from 'multiple-array-sorter'`). TypeScript declarations are included.

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