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

@jharmelink/list

v1.0.35

Published

Array management using a list object

Readme

List


Index

Installation

Using Yarn

yarn add @jharmelink/list

Using npm

npm install @jharmelink/list

Usage

import { List } from '@jharmelink/list';

const myList = List.of(1, 2, 3);

Classes

AddableList

Create a new AddableList from an Array

import { AddableList } from '@jharmelink/list';

const addableList = AddableList.from([1, 2, 3]); // AddableList([1, 2, 3])
import { AddableList } from '@jharmelink/list';

const addableList = AddableList.of(1, 2, 3); // AddableList([1, 2, 3])
import { AddableList, List } from '@jharmelink/list';

const addableList = List.of({ n: 1 }, { n: 2 }, { n: 3 }).toAddableList(item => item.n); // AddableList([1, 2, 3])

add

Add custom Addable objects in a AddableList

import { Addable, AddableList } from '@jharmelink/list';

class Payment implements Addable<Payment> {
  constructor(readonly note: string, readonly amount: number) {
  }

  add(payment: Payment) {
    return new Payment(this.note, this.amount + payment.amount);
  }
}

const payments = AddableList.of(
  new Payment('first', 100),
  new Payment('second', 200),
  new Payment('third', 300),
);
const sum = payments.add(new Payment('sum', 0)); // Payment('sum', 600)

Add decimals in a AddableList using decimal.js

import { AddableList } from '@jharmelink/list';
import Decimal from 'decimal.js';

const decimals = AddableList.of(
  new Decimal(23.56457),
  new Decimal(12.34543),
  new Decimal(34.12345),
);
const sum = payments.add(new Decimal(0)); // Decimal(70.03345)

ComparableList

Create a new ComparableList from an Array using decimal.js

import { ComparableList } from '@jharmelink/list';
import Decimal from 'decimal.js';

const comparableList = ComparableList.from([new Decimal(1), new Decimal(2), new Decimal(3)]); // ComparableList([Decimal(1), Decimal(2), Decimal(3)])
import { ComparableList } from '@jharmelink/list';
import Decimal from 'decimal.js';

const comparableList = ComparableList.of(new Decimal(1), new Decimal(2), new Decimal(3)); // ComparableList([Decimal(1), Decimal(2), Decimal(3)])

Create a ComparableList from an List using decimal.js

import { ComparableList, List } from '@jharmelink/list';
import Decimal from 'decimal.js';

const comparableList = List.of({ n: new Decimal(1) }, { n: new Decimal(2) }, { n: new Decimal(3) }).toComparableList(item => item.n); // ComparableList([Decimal(1), Decimal(2), Decimal(3)])

equals

Check if two ComparableLists, containing custom comparable objects, are equal

import { type Comparable, ComparableList } from '@jharmelink/list';

class ComparableItem implements Comparable<ComparableItem> {
  constructor(readonly item: string) {
  }

  equals(comparableItem: ComparableItem) {
    return this.item === comparableItem.item;
  }
}

const comparableItems1 = ComparableList.of(new ComparableItem('a'), new ComparableItem('b'));
const comparableItems2 = ComparableList.of(new ComparableItem('b'), new ComparableItem('a'));
const areEqual = comparableItems1.equals(comparableItems2); // true

Check if two ComparableLists, containing decimals, are equal using decimal.js

import { ComparableList } from '@jharmelink/list';
import Decimal from 'decimal.js';

const decimals1 = ComparableList.from(
  new Decimal(23.56457),
  new Decimal(12.34543),
  new Decimal(34.12345),
);
const decimals2 = ComparableList.from(
  new Decimal(12.34543),
  new Decimal(23.56457),
  new Decimal(34.12345),
);
const areEqual = decimals1.equals(decimals2); // true

List

Create a new List from an Array

import { List } from '@jharmelink/list';

const list = List.from([1, 2, 3]); // List([1, 2, 3])
import { List } from '@jharmelink/list';

const list = List.of(1, 2, 3); // List([1, 2, 3])

distinctBy

Remove duplicates from a List using a key function

import { List } from '@jharmelink/list';

const usersWithDuplicates = List.of(
  { id: '1', gender: 'male', name: 'John' },
  { id: '2', gender: 'female', name: 'Jane' },
  { id: '1', gender: 'male', name: 'John' },
);
const usersWithoutDuplicates = usersWithDuplicates.distinctBy(user => user.id); // List([{ id: '1', gender: 'male', name: 'John' }, { id: '2', gender: 'female', name: 'Jane' }])

Remove duplicates from a List using a key function and a value function

import { List } from '@jharmelink/list';

const usersWithDuplicates = List.of(
  { id: '1', gender: 'male', name: 'John' },
  { id: '2', gender: 'female', name: 'Jane' },
  { id: '1', gender: 'male', name: 'John' },
);
const namesWithoutDuplicates = usersWithDuplicates.distinctBy(user => user.id, user => user.name); // List(['John', 'Jane'])

groupBy

Group a List to a Map using a key function

import { List } from '@jharmelink/list';

const users = List.of(
  { id: '1', gender: 'male', name: 'John' },
  { id: '2', gender: 'female', name: 'Jane' },
  { id: '3', gender: 'male', name: 'Joe' },
);
const usersByGroup = users.groupBy(user => user.gender); // Map([['male', [{id: '1', gender: 'male', name: 'John'}, {id: '3', gender: 'male', name: 'Joe'}]], ['female', [{id: '2', gender: 'female, name: 'Jane'}]]])

Group a List to a map using a key function and a value function

import { List } from '@jharmelink/list';

const users = List.of(
  { id: '1', gender: 'male', name: 'John' },
  { id: '2', gender: 'female', name: 'Jane' },
  { id: '3', gender: 'male', name: 'Joe' },
);
const userNamesById = users.groupBy(user => user.gender, user => user.name); // Map([['male', ['John', 'Joe']], ['female', ['Jane']]])

mapBy

Map a List to a map using a key function

import { List } from '@jharmelink/list';

const users = List.of(
  { id: '1', name: 'John' },
  { id: '2', name: 'Jane' },
  { id: '3', name: 'Joe' },
);
const usersById = users.mapBy(user => user.id); // Map([['1', {id: '1', gender: 'male', name: 'John'}], ['2', {id: '2', gender: 'female, name: 'Jane'}], ['3', {id: '3', gender: 'male', name: 'Joe'}]])

Map a List to a map using a key function and a value function

import { List } from '@jharmelink/list';

const users = List.of(
  { id: '1', name: 'John' },
  { id: '2', name: 'Jane' },
  { id: '3', name: 'Joe' },
);
const userNamesById = users.mapBy(user => user.id, user => user.name); // Map([['1', 'John'], ['2', 'Jane'], ['3', 'Joe']])

MergeableList

Create a new MergeableList from an Array

import { MergeableList } from '@jharmelink/list';

const mergeableList = MergeableList.from([1, 2, 3]); // MergeableList([1, 2, 3])
import { MergeableList } from '@jharmelink/list';

const mergeableList = MergeableList.of(1, 2, 3); // MergeableList([1, 2, 3])

Create a MergeableList from an List

import { MergeableList, List } from '@jharmelink/list';

const mergeableList = List.of({ n: 1 }, { n: 2 }, { n: 3 }).toMergeableList(item => item.n); // MergeableList([1, 2, 3])

mergeBy

Merge custom Mergeable objects in an Array

class Drink implements Mergeable<Drink> {
  constructor(readonly name: string, readonly amount: number) {
  }

  merge(drink: Drink) {
    return new Drink(this.name, this.amount + drink.amount);
  }
}

const drinks = MergeableList.of(
  new Drink('beer', 5),
  new Drink('wine', 2),
  new Drink('beer', 3),
);
const sum = drinks.merge(drink => drink.name); // MergeableList([Drink('beer', 8), Drink('wine', 2)])

NumberList

Create a new NumberList from an Array

import { NumberList } from '@jharmelink/list';

const numberList = NumberList.from([1, 2, 3]); // NumberList([1, 2, 3])
import { NumberList } from '@jharmelink/list';

const numberList = NumberList.of(1, 2, 3); // NumberList([1, 2, 3])

Create a NumberList from an List

import { NumberList, List } from '@jharmelink/list';

const numberList = List.of({ n: 1 }, { n: 2 }, { n: 3 }).toNumberList(item => item.n); // NumberList([1, 2, 3])

max

Max number in a NumberList

import { NumberList } from '@jharmelink/list';

const numbers = NumberList.of(1, 2, 3).max(); // 3

min

Min number in a NumberList

import { NumberList } from '@jharmelink/list';

const numbers = NumberList.of(1, 2, 3).min(); // 1

sub

Subtract all numbers in a NumberList

import { NumberList } from '@jharmelink/list';

const numbers = NumberList.of(1, 2, 3).subtract(6); // 0

sum

Sum all numbers in a NumberList

import { NumberList } from '@jharmelink/list';

const numbers = NumberList.of(1, 2, 3).sum(); // 6

StringList

Create a new StringList from an Array

import { StringList } from '@jharmelink/list';

const stringList = StringList.from(['a', 'b', 'c']); // StringList(['a', 'b', 'c'])
import { StringList } from '@jharmelink/list';

const stringList = StringList.of('a', 'b', 'c'); // StringList(['a', 'b', 'c'])

Create a StringList from an List

import { StringList, List } from '@jharmelink/list';

const stringList = List.of({ n: 'a' }, { n: 'b' }, { n: 'c' }).toStringList(item => item.n); // StringList(['a', 'b', 'c'])

join

Join all strings in a StringList

import { StringList } from '@jharmelink/list';

const strings = StringList.of('a', 'b', 'c').join(); // 'abc'