From ea887fcea37b31d126799f111b42149b8a272b35 Mon Sep 17 00:00:00 2001 From: mertsincan Date: Mon, 3 Apr 2023 01:12:25 +0100 Subject: [PATCH] Update BaseComponent --- components/lib/basecomponent/BaseComponent.vue | 9 +++++++-- components/lib/utils/ObjectUtils.js | 5 +++++ components/lib/utils/Utils.d.ts | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/components/lib/basecomponent/BaseComponent.vue b/components/lib/basecomponent/BaseComponent.vue index 965c3b31f..ea592db41 100644 --- a/components/lib/basecomponent/BaseComponent.vue +++ b/components/lib/basecomponent/BaseComponent.vue @@ -10,11 +10,16 @@ export default { } }, methods: { + getPTItem(obj = {}, key = '') { + const fKey = ObjectUtils.convertToFlatCase(key); + + return obj[Object.keys(obj).find((k) => ObjectUtils.convertToFlatCase(k) === fKey) || '']; + }, ptm(key = '', params = {}) { - return ObjectUtils.getItemValue((this.pt || {})[key.toLowerCase()], { props: this.$props, state: this.$data, ...params }); + return ObjectUtils.getItemValue(this.getPTItem(this.pt, key), { props: this.$props, state: this.$data, ...params }); }, ptmo(obj = {}, key = '', params = {}) { - return ObjectUtils.getItemValue(obj[key.toLowerCase()], params); + return ObjectUtils.getItemValue(this.getPTItem(obj, key), params); } } }; diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index e637e6632..b72db6552 100755 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -205,6 +205,11 @@ export default { return null; }, + convertToFlatCase(str) { + // convert snake, kebab, camel and pascal cases to flat case + return this.isNotEmpty(str) ? str.replace(/(-|_)/g, '').toLowerCase() : str; + }, + 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); }, diff --git a/components/lib/utils/Utils.d.ts b/components/lib/utils/Utils.d.ts index 8f6195bb6..49ca3cfc3 100644 --- a/components/lib/utils/Utils.d.ts +++ b/components/lib/utils/Utils.d.ts @@ -68,6 +68,7 @@ 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 convertToFlatCase(str: string): string; static isEmpty(value: any): boolean; static isNotEmpty(value: any): boolean; static isPrintableCharacter(char: string): boolean;