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

@art-suite/art-core-comprehensions

v1.2.4

Published

Simple, powerful iteration comprehensions for JavaScript.

Readme

@art-suite/art-core-comprehensions

A powerful and flexible comprehension library for JavaScript that provides a unified interface for working with arrays, objects, and other iterables. It offers a consistent way to perform common operations like mapping, filtering, and reducing across different data structures.

The biggest difference between this library and other comprehensions is each comprehension function can accept any input container as the source: objects, arrays or anything that is Iterable. The name of the comprehension function indicates the return type:

  • object returns an object
  • array returns an array
  • find returns the found value
  • inject

Features

  • Unified interface for working with arrays, objects, and other iterables
  • Consistent behavior across different data structures
  • Support for both synchronous and asynchronous operations
  • Type-safe operations with TypeScript support
  • Efficient implementations that maintain the original data structure's characteristics

Installation

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

API Overview

Core Functions

  • each(source, callback): Iterates over a source, executing the callback for each item. Returns the source unchanged.
  • array(source, callback): Creates a new array by applying the callback to each item in the source.
  • object(source, callback): Creates a new object by applying the callback to each item in the source.
  • reduce(source, callback, initialValue): Reduces the source to a single value using the callback.
  • inject(source, callback, initialValue): Alias for reduce with a more intuitive name for certain use cases.
  • find(source, callback): Returns the first item in the source that satisfies the callback.

Usage Examples

Basic Array Operations

import { array, each, find } from "@art-suite/art-core-comprehensions";

const numbers = [1, 2, 3, 4, 5];

// Map operation
const doubled = array(numbers, (x) => x * 2);
// Result: [2, 4, 6, 8, 10]

// ForEach operation
each(numbers, (x) => console.log(x));
// Logs each number

// Find operation
const firstEven = find(numbers, (x) => x % 2 === 0);
// Result: 2

Object Operations

import { object, each } from "@art-suite/art-core-comprehensions";

const data = {
  a: 1,
  b: 2,
  c: 3,
};

// Transform object values
const doubled = object(data, (value, key) => value * 2);
// Result: { a: 2, b: 4, c: 6 }

// Iterate over object
each(data, (value, key) => console.log(`${key}: ${value}`));
// Logs each key-value pair

Reduce Operations

import { reduce, inject } from "@art-suite/art-core-comprehensions";

const numbers = [1, 2, 3, 4, 5];

// Sum all numbers
const sum = reduce(numbers, (acc, x) => acc + x, 0);
// Result: 15

// Alternative syntax using inject
const product = inject(numbers, (acc, x) => acc * x, 1);
// Result: 120

Working with Different Data Structures

import { array, object } from "@art-suite/art-core-comprehensions";

// Array-like object
const arrayLike = { 0: "a", 1: "b", 2: "c", length: 3 };
const result1 = array(arrayLike, (x) => x.toUpperCase());
// Result: ['A', 'B', 'C']

// Set
const set = new Set([1, 2, 3]);
const result2 = array(set, (x) => x * 2);
// Result: [2, 4, 6]

// Map
const map = new Map([
  ["a", 1],
  ["b", 2],
]);
const result3 = object(map, (value, key) => value * 2);
// Result: { a: 2, b: 4 }

Key Concepts

Source Types

The library works with various source types:

  • Arrays
  • Objects
  • Sets
  • Maps
  • Array-like objects
  • Any object with a forEach method
  • Any object with a map method
  • Any object with a reduce method

Callback Functions

Each operation accepts a callback function that receives:

  • The current value
  • The current key/index
  • The source object
  • The current iteration index

Return Values

  • each: Returns the source unchanged
  • array: Returns a new array
  • object: Returns a new object
  • reduce/inject: Returns the accumulated value
  • find: Returns the first matching item or undefined

License

MIT