Skip to content

op-array

Functional utilities for JavaScript arrays. Tree-shakable, typed, ESM + CJS.

Install

Terminal window
npm install op-array

What’s in the box

Collections

Lookup, grouping, and projection over arrays of objects: findBy, where, pluck, keyBy, groupBy, countBy, partition. Read more →

Logical

Predicates over membership and presence: exists, existsAll, existsAny. Read more →

Numerical

Aggregations and statistics: sum, product, average, median, mode, subtract. Read more →

Positional

Index- and position-based selection: first, last, nth, minBy, maxBy. Read more →

Transformations

Pure shape changes and folds: unique, chunk, flatten, intersection, and friends. Read more →

Tree-shakable

Each category publishes a subpath (op-array/collections, op-array/numerical, …) so bundlers only ship what you import.

Why op-array

  • Standalone functions only. No Array.prototype mutation; nothing monkey-patched.
  • TypeScript-first. Every function ships with explicit types and JSDoc.
  • Predictable empty-input behaviour. Documented per category — see each API page for the exact contract.
  • Dot-path key access. Any function that takes a key resolves it as a dot-delimited path (e.g. 'user.name').

Quick taste

import { groupBy, pluck } from 'op-array/collections';
import { average } from 'op-array/numerical';
const orders = [
{ id: 1, customer: 'ana', total: 19 },
{ id: 2, customer: 'bo', total: 42 },
{ id: 3, customer: 'ana', total: 11 },
];
groupBy(orders, 'customer');
// { ana: [...], bo: [...] }
average(pluck(orders, 'total'));
// 24