| name | mongez-reinforcements-mixed |
| description | Cross-type utilities from @mongez/reinforcements — deep clone(), deep equality areEqual(), Fisher-Yates shuffle(), and null-safe coalesce().
|
Mixed
Deep clone, deep equality, shuffle, coalesce. Import from @mongez/reinforcements.
clone — deep copy
clone<T>(value: T): T
Handles Date, RegExp, Error (with own props), Map, Set, typed arrays, ArrayBuffer, and circular references via internal WeakMap. Non-plain class instances are returned by reference (cloning user constructors is out of scope — call your own .clone() if you have one).
const a: any = { name: "Ada" };
a.self = a;
const copy = clone(a);
copy.self === copy;
clone(new Date(0));
clone(/abc/gi);
clone(new Map([["k", 1]]));
const err = new TypeError("nope");
(err as any).meta = { detail: true };
clone(err).meta;
areEqual — deep value equality
areEqual(a: any, b: any): boolean
Non-mutating deep equality. Respects element order in arrays. Handles Date, RegExp, Map, Set, and circular references.
areEqual({ a: 1 }, { a: 1 });
areEqual([1, 2, 3], [1, 2, 3]);
areEqual([1, 2, 3], [3, 2, 1]);
areEqual(new Date(0), new Date(0));
areEqual(/abc/g, /abc/g);
areEqual(new Set([1, 2]), new Set([2, 1]));
const a: any = { x: 1 }; a.self = a;
const b: any = { x: 1 }; b.self = b;
areEqual(a, b);
This is a value comparator, not a type/shape predicate. For predicates like isEmpty / isPlainObject, use @mongez/supportive-is.
shuffle — Fisher–Yates
shuffle<T>(value: T[], options?: { mutate?: boolean }): T[]
shuffle(value: string, options?: { mutate?: boolean }): string
Non-mutating by default. Pass { mutate: true } to shuffle the array in place.
shuffle([1, 2, 3, 4]);
shuffle("hello");
shuffle(arr, { mutate: true });
coalesce — first non-nullish
coalesce<T>(...values: Array<T | null | undefined>): T | undefined
Returns the first value that isn't null or undefined. Falsy-but-defined values (0, "", false, NaN) pass through — unlike ||.
coalesce(null, undefined, "first");
coalesce(undefined, 0, "x");
coalesce(undefined, "", "x");
coalesce(null, undefined);