npm.io
1.0.0 • Published 3d ago

tiny-array-utils

Licence
MIT
Version
1.0.0
Deps
0
Size
16 kB
Vulns
0
Weekly
0

tiny-array-utils

A lightweight, zero-dependency library for common array manipulations.

Installation

npm install tiny-array-utils

Usage

import { chunk, shuffle, unique, range, groupBy } from 'tiny-array-utils';

chunk([1,2,3,4,5], 2);    // [[1,2],[3,4],[5]]
unique([1,1,2,3,3]);       // [1,2,3]
range(0, 5);               // [0,1,2,3,4]

Available Functions

  • chunk(arr, size) — Split array into chunks
  • shuffle(arr) — Shuffle array (Fisher-Yates)
  • unique(arr) — Remove duplicates
  • flatten(arr, depth?) — Flatten nested arrays
  • last(arr) / first(arr) — Get last/first element
  • sample(arr) — Random element
  • zip(...arrays) — Zip arrays together
  • range(start, end, step?) — Generate number range
  • groupBy(arr, fn) — Group by key function
  • intersection(a, b) — Common elements
  • difference(a, b) — Elements in a but not in b

Keywords