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

@rcompat/array

v0.11.0

Published

Standard library arrays

Readme

@rcompat/array

Array utility functions for JavaScript runtimes.

What is @rcompat/array?

A cross-runtime module providing common array operations that work consistently across Node, Deno, and Bun. Includes functions for computing differences, checking emptiness, and normalizing values to arrays.

Installation

npm install @rcompat/array

Usage

difference

Returns elements from the first array that are not present in the second array (set difference).

import array from "@rcompat/array";

array.difference([1, 2, 3, 4], [2, 4]);
// [1, 3]

array.difference(["a", "b", "c"], ["b"]);
// ["a", "c"]

array.difference([1, 2], [1, 2]);
// []

empty

Checks if an array is empty.

import array from "@rcompat/array";

array.empty([]);
// true

array.empty(["foo"]);
// false

array.empty([[]]);
// false (contains one element, an empty array)

to

Normalizes a value to an array. If the value is already an array, it is returned as-is. Otherwise, the value is wrapped in an array.

import array from "@rcompat/array";

array.to("hello");
// ["hello"]

array.to(["hello"]);
// ["hello"]

array.to(42);
// [42]

to([1, 2, 3]);
// [1, 2, 3]

API Reference

difference(a, b)

declare function difference(a: unknown[], b: unknown[]): unknown[];

Returns elements in a that are not in b.

| Parameter | Type | Description | |-----------|-------------|--------------------------------| | a | unknown[] | The source array | | b | unknown[] | The array of elements to exclude |

Returns: A new array containing elements from a not found in b.

empty(array)

declare function empty(array: unknown[]): boolean;

Checks whether an array has no elements.

| Parameter | Type | Description | |-----------|-------------|----------------------| | array | unknown[] | The array to check |

Returns: true if the array is empty, false otherwise.

to(value)

declare function to<T>(value: T | T[]): T[];

Ensures a value is an array.

| Parameter | Type | Description | |-----------|-----------|----------------------------| | value | T \| T[] | A value or array of values |

Returns: The value wrapped in an array, or the original array if already an array.

Examples

Processing user input

import array from "@rcompat/array";

function processIds(ids) {
  const idArray = array.to(ids);

  if (array.empty(idArray)) {
    return "No IDs provided";
  }

  return `Processing ${idArray.length} ID(s)`;
}

processIds("user-1");        // "Processing 1 ID(s)"
processIds(["user-1", "user-2"]); // "Processing 2 ID(s)"
processIds([]);              // "No IDs provided"

Finding new items

import array from "@rcompat/array";

const previousTags = ["javascript", "typescript", "node"];
const currentTags = ["javascript", "typescript", "deno", "bun"];

const newTags = array.difference(currentTags, previousTags);
// ["deno", "bun"]

const removedTags = array.difference(previousTags, currentTags);
// ["node"]

Cross-Runtime Compatibility

| Runtime | Supported | |---------|-----------| | Node.js | ✓ | | Deno | ✓ | | Bun | ✓ |

No configuration required — just import and use.

License

MIT

Contributing

See CONTRIBUING.md in the repository root.