npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

array-utils-ts

v1.1.0

Published

Zero-dependency TypeScript library for immutable array operations: filter nullables, upsert/toggle by key, deduplicate, enumerate, and more.

Readme

array-utils-ts

Array helpers for TypeScript that you keep writing by hand — filter nulls with real type narrowing, toggle and upsert objects by key, deduplicate. No lodash needed.

  • Tiny. 418 bytes (minified and brotli). Zero dependencies.
  • Typed. filterNullable actually narrows the return type — no more (T | null)[].
  • Immutable. Every function returns a new array, safe to use directly in React setState.
  • Fills the gap. The specific helpers lodash skips: upsertByKey, toggleByKey, filterNullable.

Install

npm i array-utils-ts

Usage

import {
  filterNullable,
  filterEmpty,
  hasEmpty,
  uniq,
  isUniq,
  toggleItem,
  updateByKey,
  upsertByKey,
  toggleByKey,
  isFirstByKey,
  isLastByKey,
  enumerate,
} from "array-utils-ts"

Filter & Clean

filterNullable — removes null and undefined, narrows the return type

filterNullable([1, null, 2, undefined]) // → [1, 2]  (typed as number[])

filterEmpty — also removes empty strings ""

filterEmpty([1, null, 2, undefined, 3, "", "a"]) // → [1, 2, 3, "a"]

hasEmpty — returns true if any element is null, undefined, or ""

hasEmpty(["a", "b", "c"]) // → false
hasEmpty(["a", "", "c"]) // → true
hasEmpty(["a", undefined, "c"]) // → true

Deduplicate

uniq — removes duplicates

uniq([1, 2, 1, 3]) // → [1, 2, 3]

isUniq — checks if all elements are unique

isUniq([1, 2, 3]) // → true
isUniq([1, 2, 1]) // → false

Toggle

toggleItem — adds an item if missing, removes it if present; useful in multi-select UI

toggleItem([1, 2, 3], 4) // → [1, 2, 3, 4]
toggleItem([1, 2, 3], 3) // → [1, 2]

Object Arrays (by key)

updateByKey — updates a matching object; returns the same reference if not found

const arr = [
  { id: 1, v: 1 },
  { id: 2, v: 1 },
]

updateByKey(arr, "id", { id: 1, v: 2 }) // → [{ id: 1, v: 2 }, { id: 2, v: 1 }]
updateByKey(arr, "id", { id: 3, v: 1 }) // → arr (same reference, not found)

upsertByKey — updates if found, appends if not

const arr = [
  { id: 1, v: 1 },
  { id: 2, v: 1 },
]

upsertByKey(arr, "id", { id: 1, v: 2 }) // → [{ id: 1, v: 2 }, { id: 2, v: 1 }]
upsertByKey(arr, "id", { id: 3, v: 1 }) // → [...arr, { id: 3, v: 1 }]

toggleByKey — removes an object if its key matches, appends it if not

const arr = [
  { id: 1, v: 1 },
  { id: 2, v: 1 },
]

toggleByKey(arr, "id", { id: 1, v: 2 }) // → [{ id: 2, v: 1 }]
toggleByKey(arr, "id", { id: 3, v: 1 }) // → [...arr, { id: 3, v: 1 }]

isFirstByKey / isLastByKey — check an object's position in the array

const arr = [{ id: 1 }, { id: 2 }, { id: 3 }]

isFirstByKey(arr, "id", { id: 1 }) // → true
isFirstByKey(arr, "id", { id: 3 }) // → false
isLastByKey(arr, "id", { id: 3 }) // → true
isLastByKey(arr, "id", { id: 1 }) // → false

Enumerate

enumerate — pairs each element with its index, like Python's enumerate()

const arr = ["a", "b", "c"]

enumerate(arr) // → [[0, "a"], [1, "b"], [2, "c"]]
enumerate(arr, 1) // → [[1, "a"], [2, "b"], [3, "c"]]