# @tonaljs/collection

> Utility functions to work with collections (arrays)

Latest version **4.9.1** (published 2026-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tonaljs/collection
pnpm add @tonaljs/collection
yarn add @tonaljs/collection
bun add @tonaljs/collection
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.9.1 |
| Published | 2026-10-14 |
| First published | 2020-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | danigb@gmail.com |
| Maintainers | danigb |
| Keywords | collection, music, theory |

## Links

- npm: https://www.npmjs.com/package/@tonaljs/collection
- npm.io page: https://npm.io/package/@tonaljs/collection

## Recent versions

- 4.9.1 (latest) — 2026-10-14
- 4.9.0 — 2024-07-23
- 4.8.1 — 2024-01-04
- 4.8.0 — 2022-11-29
- 4.7.3 — 2022-11-29
- 4.7.2 — 2022-11-29
- 4.7.1 — 2022-11-29
- 4.7.0 — 2022-11-28
- 4.6.10 — 2022-11-18
- 4.6.2 — 2021-07-12
- 4.5.1 — 2020-11-05
- 4.5.0 — 2020-11-04
- 3.5.3 — 2020-05-04
- 3.5.2 — 2020-04-27
- 3.5.1 — 2020-04-27
- … 1 more at https://npm.io/package/@tonaljs/collection/versions

## README

# @tonaljs/collection ![tonal](https://img.shields.io/badge/@tonaljs-collection-yellow.svg?style=flat-square) [![npm version](https://img.shields.io/npm/v/@tonaljs/collection.svg?style=flat-square)](https://www.npmjs.com/package/@tonaljs/collection)

> Functions to create and manipulate collections (collections)

## Usage

ES6:

```js
import { Collection } from "tonal";
```

node:

```js
const { Collection } = require("tonal");
```

## API

#### `range(from: number, to: number) => number[]`

Creates a numeric range:

```js
Collection.range(-2, 2); // => [-2, -1, 0, 1, 2]
Collection.range(2, -2); // => [2, 1, 0, -1, -2]
```

#### `rotate(times: number, collection: any[]) => any[]`

Rotate an collection a number of times:

```js
Collection.rotate(1, [1, 2, 3]); // => [2, 3, 1]
```

#### `shuffle(collection: any[]) => any[]`

Randomizes the order of the specified collection in-place, using the Fisher–Yates shuffle.

```js
Collection.shuffle(["a", "b", "c"]);
```

#### `permutations(collection: any[]) => any[][]`

Get all permutations of an collection

```js
Collection.permutations(["a", "b", "c"])) // =>
// =>
// [
//   ["a", "b", "c"],
//   ["b", "a", "c"],
//   ["b", "c", "a"],
//   ["a", "c", "b"],
//   ["c", "a", "b"],
//   ["c", "b", "a"]
// ]
```

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