@galihrivanto/dict
v1.0.0
Published
Simple typescript dictionary type
Downloads
60
Maintainers
Readme
TypeScript Dictionary Utilities
I am tired writing this utility in every project.
Features
- Generic dictionary interface supporting any value type
- Core utility functions:
clone: Create shallow copies of dictionariesequal: Compare dictionaries for equalityisSubset: Check if one dictionary is contained within anothermerge: Combine multiple dictionaries into one
Installation
npm i @galihrivanto@dictUsage
import { Dictionary, clone, equal, isSubset, merge } from '@galihrivanto/dict';
// Create some sample dictionaries
const dict1: Dictionary<number> = { a: 1, b: 2 };
const dict2: Dictionary<number> = { c: 3, d: 4 };
// Clone a dictionary
const copied = clone(dict1); // { a: 1, b: 2 }
// Check equality
const areEqual = equal(dict1, copied); // true
// Check subset
const subset = { a: 1 };
const isContained = isSubset(subset, dict1); // true
// Merge dictionaries
const merged = merge(dict1, dict2); // { a: 1, b: 2, c: 3, d: 4 }