A lightweight and powerful library for performing advanced operations on JavaScript arrays. Whether you need intersections, unions, differences, or optimized processing of large datasets, taibeul
has you covered!
- β¨ Intersection, Union, Difference: Handle array set operations with ease.
- π Remove duplicates: Keep your arrays unique.
- β‘ Optimized for performance: Designed for large datasets.
- π Advanced search: Search with custom predicates.
- π Custom sorting: Flexible sorting with user-defined comparators.
- π οΈ Dependency-free: Lightweight and fast.
Install via npm
or yarn
:
npm install taibeul
Or:
yarn add taibeul
import {
intersection,
union,
difference,
unique,
customSort,
findBy,
smartConcat,
optimizedDifference
} from 'taibeul';
Find elements common to both arrays:
const arr1 = [1, 2, 3];
const arr2 = [2, 3, 4];
console.log(intersection(arr1, arr2)); // [2, 3]
Merge two arrays, keeping only unique values:
const arr1 = [1, 2, 3];
const arr2 = [3, 4, 5];
console.log(union(arr1, arr2)); // [1, 2, 3, 4, 5]
Find elements in one array but not the other:
const arr1 = [1, 2, 3];
const arr2 = [2, 3, 4];
console.log(difference(arr1, arr2)); // [1]
Clean up duplicates in an array:
const arr = [1, 1, 2, 3, 3];
console.log(unique(arr)); // [1, 2, 3]
Sort arrays with your own logic:
const arr = [5, 2, 9, 1];
console.log(customSort(arr, (a, b) => a - b)); // [1, 2, 5, 9]
Find an object in an array using a predicate:
const users = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' }
];
console.log(findBy(users, (user) => user.name === 'Alice')); // { id: 1, name: 'Alice' }
Merge multiple arrays, removing duplicates:
const arr1 = [1, 2];
const arr2 = [2, 3];
const arr3 = [3, 4];
console.log(smartConcat(arr1, arr2, arr3)); // [1, 2, 3, 4]
Handle huge datasets efficiently:
const largeArray1 = Array.from({ length: 1_000_000 }, (_, i) => i);
const largeArray2 = Array.from({ length: 500_000 }, (_, i) => i * 2);
console.log(optimizedDifference(largeArray1, largeArray2)); // [All odd numbers from 0 to 1,000,000]
Returns elements common to both arrays.
Returns unique elements from both arrays.
Returns elements in array1
that are not in array2
.
Returns a new array with duplicate values removed.
Sorts an array using a custom comparator function.
Returns the first element matching the predicate.
Merges multiple arrays into one, removing duplicates.
Finds the difference between two arrays using a Set
for efficiency.
MIT
Contributions are welcome! Feel free to open issues or submit pull requests.