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

@bemoje/array

v4.0.0

Published

Array manipulation and table processing utilities for TypeScript.

Readme

@bemoje/array

Array manipulation and table processing utilities for TypeScript.

TypeScript Module

Exports

  • arrFindIndices: Returns an array of indices where the predicate function returns true for the corresponding element in the input array.
  • arrGetOrDefault: Get array element at index or create it using factory function if it doesn't exist.
  • arrHasDuplicates: Checks if an array has any duplicate elements.
  • arrIndicesOf: Returns all indexes at which an element is found.
  • arrMapMutable: This function takes an array and a callback function as arguments. It applies the callback function to each element of the array, mutating the original array in the process.
  • arrObjectsCommonKeys: Returns an array of keys that are common to all objects in the input array.
  • arrObjectsToTable: Convert an array of objects to a two-dimensional table.
  • arrObjectsUniqueKeys: Returns an array of all unique object keys found in an array of objects.
  • arrSortNumeric: Sorts an array of numbers, bigints, or booleans in ascending order.
  • arrSortedInsertionIndex: Returns an index in the sorted array where the specified value could be inserted while maintaining the sorted order of the array. If the element is already in the array, returns the index after the last instance of the element.
  • arrSwap: Swaps two elements in an array. This function takes an input array and swaps the elements at the specified indices.
  • arrTableAssertRowsSameLength: Asserts that all rows in a 2D array have the same length.
  • arrTableEachToString: Coerce each value of a 2D array table to string.
  • arrTableIterateAsObjects: Generator that iterates through a 2D array table, yielding objects with header keys and row values.
  • arrTableRemoveColumns: Removes specified columns from a 2D array table.
  • arrTableToCsv: Converts a 2D array to a CSV string.
  • arrTableToObjects: Converts a 2D array representing a table into an array of objects.

Installation

npm install @bemoje/array

Usage

Math & Aggregation

import { arrSum, arrAverage } from '@bemoje/array'

arrSum([1, 2, 3, 4, 5])
// => 15

arrAverage([10, 20, 30])
// => 20

Element Access

import { arrLast, arrGetOrDefault } from '@bemoje/array'

arrLast([1, 2, 3])
// => 3

const arr: string[] = []
arrGetOrDefault(arr, 0, () => 'fallback')
// => 'fallback'  (also sets arr[0])

Sorting & Shuffling

import { arrSortNumeric, arrSortedInsertionIndex, arrShuffle, arrSwap } from '@bemoje/array'

arrSortNumeric([5, 2, 10, 1])
// => [1, 2, 5, 10]

const sorted = [1, 3, 5, 7]
arrSortedInsertionIndex(sorted, 4, (a, b) => a - b)
// => 2

arrShuffle([1, 2, 3, 4, 5])
// => [3, 1, 5, 2, 4] (randomized in-place)

arrSwap([1, 2, 3], 0, 2)
// => [3, 2, 1]

Searching

import { arrIndicesOf, arrFindIndicesOf } from '@bemoje/array'

arrIndicesOf([1, 2, 3, 2, 4, 2], 2)
// => [1, 3, 5]

arrFindIndicesOf([10, 25, 30, 5], (v) => v > 20)
// => [1, 2]

Mutation & Mapping

import { arrMapMutable, arrRemoveMutable } from '@bemoje/array'

arrMapMutable([1, 2, 3], (v) => v * 2)
// => [2, 4, 6]  (modifies original array)

const arr = [1, 2, 3, 2]
arrRemoveMutable(arr, 2)
// arr is now [1, 3]

Deduplication & Removal

import { arrHasDuplicates, arrRemoveDuplicates, arrRemove } from '@bemoje/array'

arrHasDuplicates([1, 2, 2, 3])
// => true

arrRemoveDuplicates([1, 2, 2, 3, 3])
// => [1, 2, 3]

arrRemove([1, 2, 3, 4], 3)
// => [1, 2, 4]  (returns new array)

Conversion

import { arrayToString, arrEachToString } from '@bemoje/array'

arrayToString([1, [2, 3], 4])
// => '[1,[2,3],4]'

arrEachToString([1, true, null])
// => ['1', 'true', 'null']

Table (2D Array) Operations

import {
  arrObjectsToTable,
  arrTableToObjects,
  arrTableToCsv,
  arrTableRemoveColumns,
  arrTableAssertRowsSameLength,
} from '@bemoje/array'

// Convert objects to a 2D table
const table = arrObjectsToTable([
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 25 },
])
// => [['name', 'age'], ['Alice', 30], ['Bob', 25]]

// Convert back to objects
arrTableToObjects(table)
// => [{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]

// Export to CSV
arrTableToCsv(table)
// => 'name;age\nAlice;30\nBob;25'

// Remove columns by index
arrTableRemoveColumns(table, [1])
// => [['name'], ['Alice'], ['Bob']]

// Validate row lengths
arrTableAssertRowsSameLength(table) // throws if rows differ in length