Skip to main content

Built and signed on GitHub Actions

Pure functions for common tasks related to collection types like arrays and objects

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (1.0.10)

Pure functions for common tasks around collection types like arrays and objects.

Inspired by Kotlin's Collections package and Lodash.

import { intersect, sample, pick } from "@std/collections";
import { assertEquals, assertArrayIncludes } from "@std/assert";

const lisaInterests = ["Cooking", "Music", "Hiking"];
const kimInterests = ["Music", "Tennis", "Cooking"];

assertEquals(intersect(lisaInterests, kimInterests), ["Cooking", "Music"]);

assertArrayIncludes(lisaInterests, [sample(lisaInterests)]);

const cat = { name: "Lulu", age: 3, breed: "Ragdoll" };

assertEquals(pick(cat, ["name", "breed"]), { name: "Lulu", breed: "Ragdoll"});
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@std/collections

Import symbol

import * as collections from "@std/collections";

---- OR ----

Import directly with a jsr specifier

import * as collections from "jsr:@std/collections";

Add Package

npx jsr add @std/collections

Import symbol

import * as collections from "@std/collections";

Add Package

yarn dlx jsr add @std/collections

Import symbol

import * as collections from "@std/collections";

Add Package

pnpm dlx jsr add @std/collections

Import symbol

import * as collections from "@std/collections";

Add Package

bunx jsr add @std/collections

Import symbol

import * as collections from "@std/collections";