# @blakek/array-split

> 💔 Split and chunk arrays, strings, and more

Latest version **2.0.1** (published 2020-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blakek/array-split
pnpm add @blakek/array-split
yarn add @blakek/array-split
bun add @blakek/array-split
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2020-06-18 |
| First published | 2020-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 100.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Blake Knight |
| Maintainers | blakek |
| Keywords | function, pipeline, promise |

## Links

- npm: https://www.npmjs.com/package/@blakek/array-split
- Repository: https://github.com/blakek/array-split
- Issues: https://github.com/blakek/array-split/issues
- npm.io page: https://npm.io/package/@blakek/array-split

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2020-06-18
- 2.0.0 — 2020-06-18
- 1.0.0 — 2020-06-07

## README

# array-split

> 💔 Split and chunk arrays, strings, and more

Functions to help split an array at an index and chunk an array into pieces.

## Install

Using [Yarn]:

```bash
$ yarn add @blakek/array-split
```

…or using [npm]:

```bash
$ npm i --save @blakek/array-split
```

## API

### `chunk`

```ts
function chunk<T extends Sliceable>(chunkSize: number, array: T): T[];
```

Chunks an array into pieces of a given size.

```js
import { chunk } from '@blakek/array-split';

chunk(2, [1, 2, 3, 4]);
//» [[1, 2], [3, 4]]

chunk(3, 'abcdefghij');
//» ['abc', 'def', 'ghi', 'j']

chunk(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
//» [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11]]
```

### `splitAtIndex`

```ts
function splitAtIndex<T extends Sliceable>(index: number, array: T): T[];
```

Splits an array into two pieces at the given index. Anything below the index is
in the first array, the index and above are the second array.

Note, you may pass a negative index to split at the end of the array.

```js
import { splitAtIndex } from '@blakek/array-split';

splitAtIndex(0, [1, 2, 3, 4]);
//» [[], [1, 2, 3, 4]]

splitAtIndex(1, [1, 2, 3, 4]);
//» [[ 1 ], [2, 3, 4]]

splitAtIndex(-1, ['a', 'b', 'c']);
//» [[ 'a', 'b' ], ['c']]

splitAtIndex(3, ['a', 'b', 'c', 'd', 'e']);
//» [['a', 'b', 'c'], ['d', 'e']]

splitAtIndex(1, 'abc');
//» ['a', 'bc']
```

### `splitAtIndices`

```ts
function splitAtIndices<T extends Sliceable>(
  [index, nextIndex, ...indices]: number[],
  array: T
): T[];
```

Similar to `splitAtIndex` but slices an array at multiple indices.

```js
import { splitAtIndices } from '@blakek/array-split';

splitAtIndices([1, 3], ['a', 'b', 'c', 'd', 'e']);
//» [['a'], ['b', 'c'], ['d', 'e']]

splitAtIndices([2, 5], 'blakek');
//» ['bl', 'ake', 'k']

splitAtIndices([-4, -1], 'github');
//» ['gi', 'thu', 'b']
```

## Contributing

[Node.js] and [Yarn] are required to work with this project.

To install all dependencies, run:

```bash
yarn
```

### Useful Commands

|                     |                                                 |
| ------------------- | ----------------------------------------------- |
| `yarn build`        | Builds the project to `./dist`                  |
| `yarn format`       | Format the source following the Prettier styles |
| `yarn test`         | Run project tests                               |
| `yarn test --watch` | Run project tests, watching for file changes    |

## License

MIT

[node.js]: https://nodejs.org/
[npm]: https://npmjs.com/
[yarn]: https://yarnpkg.com/en/docs/

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