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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jlhv/array-helper

v1.0.1

Published

A simple utility library for array manipulation.

Readme

Array Helper Library

Overview

The Array Helper Library provides a collection of utility functions for working with arrays, including searching, transformation, sorting, and validation.

Installation

To install the package, use:

npm install @jlhv/array-helper

Usage

Import the required functions from the library:

import { unique, flatten, shuffle, min, max } from "@jlhv/array-helper";

Functions and Examples

Basic Operations

isEmpty<T>(arr: T[]): boolean

Checks if an array is empty.

isEmpty([]); // true
isEmpty([1, 2, 3]); // false

first<T>(arr: T[]): T | undefined

Gets the first element of an array.

first([10, 20, 30]); // 10
first([]); // undefined

last<T>(arr: T[]): T | undefined

Gets the last element of an array.

last([10, 20, 30]); // 30
last([]); // undefined

unique<T>(arr: T[]): T[]

Removes duplicate values from an array.

unique([1, 2, 2, 3, 3, 4]); // [1, 2, 3, 4]

Searching & Counting

indexOf<T>(arr: T[], value: T): number

Finds the index of an element in an array without using indexOf.

indexOf([5, 10, 15], 10); // 1
indexOf([5, 10, 15], 20); // -1

contains<T>(arr: T[], value: T): boolean

Checks if an array contains a specific value.

contains([1, 2, 3], 2); // true
contains([1, 2, 3], 5); // false

countOccurrences<T>(arr: T[], value: T): number

Counts the occurrences of a value in an array.

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

Merging & Transforming

mergeUnique<T>(arr1: T[], arr2: T[]): T[]

Merges two arrays without duplicates.

mergeUnique([1, 2, 3], [3, 4, 5]); // [1, 2, 3, 4, 5]

flatten<T>(arr: (T | T[])[]): T[]

Flattens a nested array (single level).

flatten([1, [2, 3], 4]); // [1, 2, 3, 4]

Set Operations

intersection<T>(arr1: T[], arr2: T[]): T[]

Finds common elements between two arrays.

intersection([1, 2, 3], [2, 3, 4]); // [2, 3]

difference<T>(arr1: T[], arr2: T[]): T[]

Finds elements that are in the first array but not in the second.

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

Sorting & Shuffling

shuffle<T>(arr: T[]): T[]

Shuffles an array without using built-in functions.

shuffle([1, 2, 3, 4]); // Output may vary

reverse<T>(arr: T[]): T[]

Reverses an array without using reverse().

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

bubbleSort(arr: number[]): number[]

Sorts an array using bubble sort.

bubbleSort([5, 3, 8, 1]); // [1, 3, 5, 8]

Min & Max Functions

min(arr: number[]): number | undefined

Finds the minimum value in an array.

min([3, 1, 4, 1, 5]); // 1

max(arr: number[]): number | undefined

Finds the maximum value in an array.

max([3, 1, 4, 1, 5]); // 5

Grouping & Partitioning

groupBy<T, K>(arr: T[], callback: (item: T) => K): Record<K, T[]>

Groups elements based on a callback.

groupBy(["apple", "banana", "avocado"], (fruit) => fruit[0]);
// { a: ["apple", "avocado"], b: ["banana"] }

partition<T>(arr: T[], predicate: (item: T) => boolean): [T[], T[]]

Splits an array into two groups based on a condition.

partition([1, 2, 3, 4], (num) => num % 2 === 0);
// [[2, 4], [1, 3]]

Other Helpers

chunk<T>(arr: T[], size: number): T[][]

Breaks an array into chunks of a given size.

chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]

compact<T>(arr: T[]): T[]

Removes falsy values (false, null, 0, "", undefined, NaN).

compact([0, 1, false, 2, "", 3]); // [1, 2, 3]

rotate<T>(arr: T[], n: number): T[]

Rotates an array by n positions.

rotate([1, 2, 3, 4, 5], 2); // [3, 4, 5, 1, 2]
rotate([1, 2, 3, 4, 5], -2); // [4, 5, 1, 2, 3]

randomElement<T>(arr: T[]): T | undefined

Returns a random element from an array.

randomElement([10, 20, 30]); // Output may vary

nth<T>(arr: T[], index: number): T | undefined

Gets the nth element of an array (supports negative indexing).

nth([10, 20, 30], 1); // 20
nth([10, 20, 30], -1); // 30

uniqueMultiple<T>(...arrays: T[][]): T[]

Finds unique elements across multiple arrays.

uniqueMultiple([1, 2, 3], [2, 3, 4], [3, 4, 5]); // [1, 5]

License

ISC License.

Author

Vijayavel R