From 605424d3c3b438aa8c3c838e03a7093e50b907cd Mon Sep 17 00:00:00 2001 From: mertsincan Date: Sun, 5 Dec 2021 20:21:16 +0300 Subject: [PATCH] Added isEmpty and isNotEmpty methods to ObjectUtils --- src/components/utils/ObjectUtils.js | 18 +++++++++++++++--- src/components/utils/Utils.d.ts | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index 495e76b67..3f153531d 100755 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -198,10 +198,22 @@ export default { let kebapProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); let propName = Object.prototype.hasOwnProperty.call(props, kebapProp) ? kebapProp : prop; - return ((vnode.type.props[prop].type === Boolean && props[propName] === '') ? true : props[propName]); + return ((vnode.type.props[prop].type === Boolean && props[propName] === '') ? true : props[propName]); } return null; - } + }, -} \ No newline at end of file + isEmpty(value) { + return ( + value === null || value === undefined || value === '' || + (Array.isArray(value) && value.length === 0) || + (!(value instanceof Date) && typeof value === 'object' && Object.keys(value).length === 0) + ); + }, + + isNotEmpty(value) { + return !this.isEmpty(value); + } + +} diff --git a/src/components/utils/Utils.d.ts b/src/components/utils/Utils.d.ts index 24534cc30..fff257f6c 100644 --- a/src/components/utils/Utils.d.ts +++ b/src/components/utils/Utils.d.ts @@ -62,6 +62,8 @@ export declare class ObjectUtils { static contains(value: any, list: any[]): boolean; static insertIntoOrderedArray(item: any, index: number, arr: any[], sourceArr: any[]): void; static removeAccents(str: any): string; + static isEmpty(value: any): boolean; + static isNotEmpty(value: any): boolean; } export declare namespace ZIndexUtils {