@vox1337/distinct
v0.1.1
Published
A utility library that provides functions to remove duplicate values from primitive and complex arrays.
Maintainers
Readme
distinct
A small TypeScript utility library for removing duplicates from arrays. It includes a docs site and a published package.
Package
distinct exports two helpers:
distinct(arr)removes duplicates from an array using deep equality for objects and arrays.distinctBy(arr, keyFn)removes duplicates based on a derived key, also using deep equality for complex keys.
import { distinct, distinctBy } from 'distinct';
const numbers = distinct([1, 2, 2, 3, 1]);
// [1, 2, 3]
const users = distinct([{ id: 1 }, { id: 2 }, { id: 1 }]);
// [{ id: 1 }, { id: 2 }]
const byId = distinctBy(
[
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 1, name: 'Charlie' },
],
(user) => user.id,
);
// [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]Repository layout
packages/distinctlibrary source and testsdocsdocumentation site (Next.js)
Setup
This repo uses Bun workspaces.
bun installCommon scripts
Run from the repo root:
bun run dev
bun run build:all
bun run test
bun run biomePackage-only commands:
bun run --cwd packages/distinct build
bun run --cwd packages/distinct testDocs site:
bun run --cwd docs devLicense
MIT
