thorish
Version:
This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.
44 lines (43 loc) • 1.86 kB
TypeScript
/**
* Pass to {@link matchPartial} to match any value at a given node. This is {@link Symbol}, but
* returned as `any` for convenience.
*/
export declare const matchAny: any;
/**
* Deep partial type. Does not support {@link Function} or similar.
*/
export type DeepObjectPartial<T> = T extends object ? {
[P in keyof T]?: DeepObjectPartial<T[P]>;
} : T;
/**
* Match the passed object against the filter. This just checks for strict equality.
*/
export declare function matchPartial<T>(filter: DeepObjectPartial<T>, object: T): boolean;
/**
* Returns an {@link Array} of all values targeted by {@link matchAny} in a filter. Returns
* `undefined` if there are no {@link matchAny} values in the filter.
*
* This can be used to compare against matches, as the array will always have the same shape for
* the same filter.
*/
export declare function readMatchAny<T>(filter: DeepObjectPartial<T>, object: T): any[] | void;
/**
* Return the parts of a/b that are the same. Otherwise, returns `undefined`. If a/b are the same
* object, returns that object (same ref).
*/
export declare function intersectObjects<T>(a: T | DeepObjectPartial<T> | undefined, b: T | DeepObjectPartial<T> | undefined): DeepObjectPartial<T> | undefined;
/**
* Intersect many objects together (0-n objects). May return `undefined`. If only one unique object
* is passed, it will be directly returned (same ref).
*/
export declare function intersectManyObjects<T>(of: Iterable<T>): DeepObjectPartial<T> | undefined;
/**
* Call {@link Object.freeze} on this object as well as any of its child objects.
*/
export declare function deepFreeze(object: any): void;
/**
* Deletes and reassigns the given properties on the object.
*
* This is useful for upgraded Custom Elements.
*/
export declare function reassignOwnProperty(target: Object, props: Iterable<string>): void;