2023-03-30 15:49:57 +00:00
|
|
|
export const isString = (value: any): value is string => {
|
|
|
|
return typeof value === 'string';
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isArray = (value: any): value is Array<any> => {
|
|
|
|
return Array.isArray(value);
|
|
|
|
};
|
|
|
|
|
2023-03-20 09:40:16 +00:00
|
|
|
export const isEmpty = (value: unknown) => {
|
|
|
|
if (isPlainObject(value)) {
|
|
|
|
return Object.keys(value).length === 0;
|
|
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
return value.length === 0;
|
|
|
|
}
|
|
|
|
return !value;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isPlainObject = (value) => {
|
|
|
|
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const prototype = Object.getPrototypeOf(value);
|
|
|
|
return prototype === null || prototype === Object.prototype;
|
|
|
|
};
|
2023-03-30 15:49:57 +00:00
|
|
|
|
|
|
|
export const hasEmptyValue = (objOrArr: object | any[]) => {
|
|
|
|
let result = true;
|
|
|
|
for (const key in objOrArr) {
|
|
|
|
result = false;
|
|
|
|
if (isArray(objOrArr[key]) && objOrArr[key].length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!objOrArr[key]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (isPlainObject(objOrArr[key]) || isArray(objOrArr[key])) {
|
|
|
|
return hasEmptyValue(objOrArr[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
2023-11-14 06:15:47 +00:00
|
|
|
|
|
|
|
export const nextTick = (fn: () => void) => {
|
|
|
|
setTimeout(fn);
|
|
|
|
};
|