/* eslint-disable @typescript-eslint/no-explicit-any */ export function noop(): void {} export const extend = Object.assign; export const inBrowser = typeof window !== "undefined"; export function isDef(val: T): val is NonNullable { 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 isPromise(val: unknown): val is Promise { return isObject(val) && isFunction(val.then) && isFunction(val.catch); } export function isObject(val: unknown): val is Record { return val !== null && typeof val === "object"; } export function get(object: any, path: string): any { const keys = path.split("."); let result = object; keys.forEach((key) => { result = result[key] ?? ""; }); return result; } export type Writeable = { -readonly [P in keyof T]: T[P] }; export function pick( obj: T, keys: ReadonlyArray, ignoreUndefined?: boolean, ) { return keys.reduce( (ret, key) => { if (!ignoreUndefined || obj[key] !== undefined) { ret[key] = obj[key]; } return ret; }, {} as Writeable>, ); } export function once( fn: ((...args: any) => void) | null, ): (...args: any) => void { return (...args: any) => { if (!fn) return; fn(...args); fn = null as any; }; }