fix(utils): circular dependency
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
export function noop() {}
|
||||
|
||||
export const inBrowser = typeof window !== 'undefined';
|
||||
|
||||
export function isDef<T>(val: T): val is NonNullable<T> {
|
||||
return val !== undefined && val !== null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function isFunction(val: unknown): val is Function {
|
||||
return typeof val === 'function';
|
||||
}
|
||||
|
||||
export function isObject(val: unknown): val is Record<any, any> {
|
||||
return val !== null && typeof val === 'object';
|
||||
}
|
||||
|
||||
export function isPromise<T = any>(val: unknown): val is Promise<T> {
|
||||
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
||||
}
|
||||
|
||||
export function get(object: any, path: string): any {
|
||||
const keys = path.split('.');
|
||||
let result = object;
|
||||
|
||||
keys.forEach((key) => {
|
||||
result = result[key] ?? '';
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function pick(obj: Record<string, any>, keys: string[]) {
|
||||
return keys.reduce((ret, key) => {
|
||||
ret[key] = obj[key];
|
||||
return ret;
|
||||
}, {} as Record<string, any>);
|
||||
}
|
||||
Reference in New Issue
Block a user