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

@art-suite/art-core-arrays

v0.1.4

Published

The Standard Library for JavaScript that aught to be.

Readme

@art-suite/art-core-arrays

A high-performance utility library for working with arrays in a pure-functional way.

Features

  • Powerful operations for working with sparse arrays and nested arrays
  • Pure functional approach - most operations return new arrays rather than modifying existing ones
  • Optimized for performance while maintaining clean semantics
  • TypeScript definitions for complete type safety

Installation

npm install @art-suite/art-core-arrays

API Overview

Types

The library provides several useful TypeScript types:

  • SparseArray<T> - Arrays that may contain null/undefined values
  • NestedArray<T> - Arrays that may contain other arrays recursively
  • SparseNestedArray<T> - Recursive arrays that may contain null/undefined values

Array Transformation

Filtering and Flattening

// Remove null/undefined or items that don't pass the tester
compact<T>(inputArray: SparseArray<T>, keepTester?: (value: T) => boolean): T[]

// Flatten nested arrays into a single-level array
flatten<T>(...args: NestedArray<T>[]): T[]

// Flatten nested arrays and remove null/undefined values
compactFlatten<T>(inputArray: SparseNestedArrayOrSingleton<T>): T[]

// Flatten multiple arrays and remove null/undefined values
compactFlattenAll<T>(...args: SparseNestedArray<T>[]): T[]

// Custom filtering while flattening
customCompactFlatten<T>(inputArray: SparseNestedArray<T>, customKeepTester: (value: T) => boolean): T[]

Non-Mutating Operations (Pure Functional)

These functions create new arrays without modifying the original:

// Add an element to the end of an array
arrayWith<T>(inputArray: T[] | null | undefined, value: T): T[]

// Get part of an array before an index
arrayWithLeftOfIndex<T>(inputArray: T[] | null | undefined, index: number): T[]

// Get part of an array after an index
arrayWithRightOfIndex<T>(inputArray: T[] | null | undefined, index: number): T[]

// Get part of an array before a value
arrayWithLeftOf<T>(inputArray: T[], value: T): T[]

// Get part of an array after a value
arrayWithRightOf<T>(inputArray: T[], value: T): T[]

// Create a shuffled copy of an array
arrayWithRandomSort<T>(inputArray: T[] | null | undefined): T[]

// Insert an item at a specific index
arrayWithInsertedAt<T>(inputArray: T[], index: number, item: T): T[]

// Create a sorted copy
arrayWithSort<T>(inputArray?: T[], sortFunction?: (a: T, b: T) => number): T[]

// Remove element(s) at an index
arrayWithout<T>(inputArray: T[] | null | undefined, index?: number, amount?: number): T[]

// Remove a specific value
arrayWithoutValue<T>(inputArray: T[] | null | undefined, value: T): T[]

// Remove the last element(s)
arrayWithoutLast<T>(inputArray: T[] | null | undefined, amount?: number): T[]

// Add a value if it doesn't already exist
arrayWithExactlyOne<T>(inputArray: T[] | null | undefined, value: T): T[]

// Move an element by index
arrayWithElementMoved<T>(inputArray: T[], fromIndex: number, toIndex: number): T[]

// Move an element by value
arrayWithElementValueMoved<T>(inputArray: T[], value: T, toIndex: number): T[]

// Replace an element at an index
arrayWithElementReplaced<T>(inputArray: T[], value: T, index: number): T[]

// Truncate array and add a value
truncatedArrayWith<T>(inputArray: T[] | null | undefined, length: number, value: T): T[]

// Create array with only unique values
arrayWithUniqueValues<T>(sortedArray: T[], eqF?: (a: T, b: T) => boolean): T[]

Mutating Operations

These functions modify the original array:

// Remove and return the last element
pop<T>(inputArray: T[] | null | undefined): T | undefined

// Add element to the end
push<T>(inputArray: T[] | null | undefined, element: T): T[]

// Insert an item at an index
insertIntoArray<T>(inputArray: T[], index: number, item: T): T[]

// Move an element from one position to another
moveArrayElement<T>(inputArray: T[], fromIndex: number, toIndex: number): T[]

// Remove elements at an index
remove<T>(inputArray: T[], index: number, amount?: number): T[]

// Remove the first matching value
removeFirstMatch<T>(inputArray: T[], toMatchValue: T): T[]

// Randomly reorder array elements
shuffleArray<T>(inputArray: T[]): T[]

// Stable sort (maintains order of equal elements)
stableSort<T>(inputArray: T[], compareFunction?: (a: T, b: T) => number): T[]

Array Inspection

// Get the last element (or at offset from end) without modifying
peek<T>(inputArray: T[] | null | undefined, offset?: number): T | undefined

// Find index of element or array length if not found
getIndexOfOrLength<T>(inputArray: T[], value: T): number

// Find the smallest element according to compare function
findSortedFirst<T>(inputArray: T[] | null | undefined, compareFunction?: (a: T, b: T) => number): T | undefined

Iteration

// Recursively iterate over nested arrays
deepArrayEach<T>(inputArray: NestedArray<T>[], f: (value: T) => void): NestedArray<T>[]

Utilities

// Create a predicate function that returns true if not null/undefined
keepUnlessNullOrUndefined<T>(a: T): boolean

// Create array from strings, splitting on whitespace
w<T>(...args: SparseNestedArray<string | T>): (string | T)[]

Examples

import {
  compact,
  compactFlatten,
  arrayWith,
  arrayWithout,
  w,
} from "@art-suite/art-core-arrays";

// Remove null/undefined values
compact([1, null, 2, undefined, 3]); // [1, 2, 3]

// Custom filtering
compact([1, 2, 3, 4, 5], (x) => x % 2 === 0); // [2, 4]

// Flatten nested arrays and remove null/undefined
compactFlatten([1, [2, null], [[3, undefined], 4]]); // [1, 2, 3, 4]

// Add element to array without mutation
const originalArray = [1, 2, 3];
const newArray = arrayWith(originalArray, 4); // [1, 2, 3, 4]
// originalArray is still [1, 2, 3]

// Remove element from array without mutation
arrayWithout([1, 2, 3, 4], 1); // [1, 3, 4]

// String to array utility
w("hello world"); // ["hello", "world"]
w("one", "two three"); // ["one", "two", "three"]

License

MIT