mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 21:50:07 +08:00
29 lines
1.5 KiB
TypeScript
29 lines
1.5 KiB
TypeScript
export const isClient = typeof window !== 'undefined';
|
|
export const isDef = <T = any>(val?: T): val is T => typeof val !== 'undefined';
|
|
export const assert = (condition: boolean, ...infos: any[]) => {
|
|
if (!condition) console.warn(...infos);
|
|
};
|
|
const toString = Object.prototype.toString;
|
|
export const isBoolean = (val: any): val is boolean => typeof val === 'boolean';
|
|
export const isFunction = <T extends Function>(val: any): val is T => typeof val === 'function';
|
|
export const isNumber = (val: any): val is number => typeof val === 'number';
|
|
export const isString = (val: unknown): val is string => typeof val === 'string';
|
|
export const isObject = (val: any): val is object => toString.call(val) === '[object Object]';
|
|
export const isWindow = (val: any): val is Window =>
|
|
typeof window !== 'undefined' && toString.call(val) === '[object Window]';
|
|
export const now = () => Date.now();
|
|
export const timestamp = () => +Date.now();
|
|
export const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n));
|
|
export const noop = () => {};
|
|
export const rand = (min: number, max: number) => {
|
|
min = Math.ceil(min);
|
|
max = Math.floor(max);
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
};
|
|
export const isIOS =
|
|
/* #__PURE__ */ isClient &&
|
|
window?.navigator?.userAgent &&
|
|
/iP(ad|hone|od)/.test(window.navigator.userAgent);
|
|
export const hasOwn = <T extends object, K extends keyof T>(val: T, key: K): key is K =>
|
|
Object.prototype.hasOwnProperty.call(val, key);
|