chore: move utils

This commit is contained in:
chenjiahan
2020-07-05 08:32:49 +08:00
parent 0a4c6676ba
commit 12faaa2179
20 changed files with 776 additions and 2 deletions
+32
View File
@@ -0,0 +1,32 @@
export { addUnit } from './format/unit';
export { createNamespace } from './create';
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop() {}
export function isDef(val: unknown): boolean {
return val !== undefined && val !== null;
}
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 = isDef(result[key]) ? result[key] : '';
});
return result;
}