@ts-utilkit/collection
v0.2.0
Published
Collection utilities for Sets, Maps, and conversions between different collection types
Maintainers
Readme
@ts-utilkit/collection
collection Functions - TypeScript utility functions for collection operations.
Installation
npm install @ts-utilkit/collectionFeatures
- 🚀 TypeScript-first with complete type definitions
- ✅ Comprehensive test coverage (>95%)
- 📦 Tree-shakeable ESM and CommonJS support
- 🔒 Type-safe with strict TypeScript configuration
- 📖 Extensive JSDoc documentation
Available Functions (17)
arrayToSet- Converts an array to a SetisDisjoint- Checks if two Sets have no common elementsisSubset- Checks if one Set is a subset of anotherisSuperset- Checks if one Set is a superset of anothermapFilter- Filters a Map based on a predicate functionmapInvert- Inverts keys and values in a MapmapMap- Transforms Map values using a mapping functionmapMerge- Merges multiple Maps into onemapReduce- Reduces Map values to a single valuemapToObject- Converts a Map to a plain objectobjectToMap- Converts a plain object to a MapsetDifference- Computes the difference between two SetssetEquals- Checks if two Sets are equalsetIntersection- Computes the intersection of two or more SetssetSymmetricDifference- Computes the symmetric difference of two SetssetToArray- Converts a Set to an arraysetUnion- Computes the union of two or more Sets
Quick Example
import { setUnion, setIntersection, mapToObject } from '@ts-utilkit/collection';
// Set operations
setUnion(new Set([1, 2]), new Set([2, 3])); // Set {1, 2, 3}
setIntersection(new Set([1, 2]), new Set([2, 3])); // Set {2}
// Map conversions
mapToObject(
new Map([
['a', 1],
['b', 2],
]),
); // {a: 1, b: 2}License
MIT © Mykyta Forofontov
