nocobase/packages/core/utils/src/common.ts
被雨水过滤的空气-Rain c25f51d99b
fix: fix display association fields with subform (#3036)
* fix: fix display association fields with subform

* fix: transformVariableValue

* fix: should also to request data when value is null

* fix: better way to fix
2023-11-14 14:15:47 +08:00

48 lines
1.1 KiB
TypeScript

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);
};
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;
};
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;
};
export const nextTick = (fn: () => void) => {
setTimeout(fn);
};