uniqs: Unique and Union Utility

2.0.0 · active · verified Sun Apr 19

uniqs is a lightweight JavaScript utility designed to create unique lists and unions of multiple lists, defining uniqueness based on strict object equality. Currently at version 2.0.0, this package distinguishes itself by prioritizing simplicity and a minimal footprint over raw performance, making it a suitable alternative to more comprehensive libraries like Lodash or Underscore for basic deduplication tasks. Its primary purpose is to provide a straightforward function for de-duplicating items and combining arrays without complex features or external dependencies, making it ideal for scenarios where bundle size and directness are critical. Items are maintained in their first-appearance order, reflecting their initial encounter in the input lists.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates deduplication of a single list, union of multiple lists, and handling of mixed individual items and lists.

const uniqs = require('uniqs');

// Example usage to deduplicate a list
const foo = { id: 23 };
const list = [3, 2, 2, 1, foo, foo];
const uniqueList = uniqs(list);
console.log('Unique list:', uniqueList);
// Expected: [3, 2, 1, { id: 23 }]

// Example usage to create a union of multiple lists
const listA = [2, 1, 1];
const listB = [2, 3, 3, 4];
const listC = [4, 3, 2];
const unionList = uniqs(listA, listB, listC);
console.log('Union list:', unionList);
// Expected: [2, 1, 3, 4]

// Example with individual items and a list
const mixedInput = uniqs(3, 2, 2, [1, 1, 2]);
console.log('Mixed input:', mixedInput);
// Expected: [3, 2, 1]

view raw JSON →