@altostra/core
Version:
Core library for shared types and logic
98 lines (97 loc) • 5.29 kB
TypeScript
import type { Key } from "../Types";
/**
* Returns a copy of the given object with any undefined value properties removed.
* Does not remove null or empty values, such as: '', []
*/
export declare function cleanObject<T extends object>(x: T): T;
export declare type Cleaned<T extends object> = {
[K in keyof T]: T[K] extends (object | '' | [] | null) ? T[K] | undefined : T[K];
};
/**
* Returns a copy of the given object with any undefined, null or empty properties removed.
*/
export declare function cleanObjectStrict<T extends object>(x: T): Cleaned<T>;
export declare function deepClone<T>(item: T): T;
export declare function isObject(val: unknown): val is Record<Key, unknown>;
export declare const isSimpleObject: (val: unknown) => val is object;
export declare type Entry<TValue, TKey extends Key = string> = [TKey, TValue];
export declare function fromEntries<TValue, TKey extends Key = string>(entries: Iterable<Entry<TValue, TKey>>): Record<TKey, TValue>;
export declare type EmptyObject = Record<never, never>;
declare type KeysIterable<T extends keyof any> = Iterable<T> & object;
/**
* Returns a new object that contains only the selected properties from the source object
* @param obj The object to pick properties from
* @param keys The keys to pick from the object
*/
export declare function pick<T extends object, TKey extends keyof T>(obj: T, keys: KeysIterable<TKey>): Pick<T, TKey>;
/**
* Returns a new object that contains only the selected properties from the source object
* @param obj The object to pick properties from
* @param predicate A function that returns a value which determines if a given property is included
* in the result object
*/
export declare function pick<T extends object>(obj: T, predicate: (key: Key) => boolean): Partial<T>;
/**
* Returns a new object that contains only the selected properties from the source object
* @param obj The object to pick properties from
* @param keys The keys to pick from the object
*/
export declare function pick<TKey extends Key, TValue, TPicked extends TKey>(obj: Record<TKey, TValue>, keys: KeysIterable<TPicked>): Record<TPicked, TValue>;
/**
* Returns a new object that contains only the selected properties from the source object
* @param obj The object to pick properties from
* @param predicate An iterable of keys to pick from the object, or a predicate
* that returns a value which determines if a given property is included
* in the result object
*/
export declare function pick<TKey extends Key, TValue>(obj: Record<TKey, TValue>, predicate: (key: TKey) => boolean): Partial<Record<TKey, TValue>>;
/**
* Returns a new object that contains only the selected properties from the source object
* @param obj The object to pick properties from
* @param keysOrPredicate An iterable of keys to pick from the object, or a predicate
* that returns a value which determines if a given property is included
* in the result object
*/
export declare function pick(obj: object, keysOrPredicate: KeysIterable<Key> | ((key: Key) => boolean)): object;
/**
* Returns a new object that contains only the properties that are not specified from the source object
* @param obj The object to omit properties from
* @param keys The keys to omit from the object
*/
export declare function omit<T extends object, TKey extends keyof T>(obj: T, keys: KeysIterable<TKey>): Omit<T, TKey>;
/**
* Returns a new object that contains only the properties that are not specified from the source object
* @param obj The object to omit properties from
* @param predicate A function that returns a value which determines if a given property is excluded
* from the result object
*/
export declare function omit<T extends object>(obj: T, predicate: (key: Key) => boolean): Partial<T>;
/**
* Returns a new object that contains only the properties that are not specified from the source object
* @param obj The object to omit properties from
* @param keys The keys to omit from the object
*/
export declare function omit<TKey extends Key, TValue, TOmitted extends TKey>(obj: Record<TKey, TValue>, keys: KeysIterable<TOmitted>): Record<Exclude<TKey, TOmitted>, TValue>;
/**
* Returns a new object that contains only the properties that are not specified from the source object
* @param obj The object to omit properties from
* @param predicate A function that returns a value which determines if a given property is excluded
* from the result object
*/
export declare function omit<TKey extends Key, TValue>(obj: Record<TKey, TValue>, predicate: (key: TKey) => boolean): Partial<Record<TKey, TValue>>;
/**
* Returns a new object that contains only the properties that are not specified from the source object
* @param obj The object to omit properties from
* @param keysOrPredicate An iterable of keys to omit from the object, or a predicate
* that returns a value which determines if a given property is excluded
* from the result object
*/
export declare function omit(obj: object, keysOrPredicate: KeysIterable<Key> | ((key: Key) => boolean)): object;
/**
* Add an index signature to a type
* */
export declare type IndexSigWrapper<T> = T & {
[K in string]: any;
};
export declare type Optional<T, Keys extends keyof T> = Omit<T, Keys> & Partial<Pick<T, Keys>>;
export {};