Update BaseComponent

pull/3841/head
mertsincan 2023-04-03 01:12:25 +01:00
parent 6cd41325d1
commit ea887fcea3
3 changed files with 13 additions and 2 deletions

View File

@ -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);
}
}
};

View File

@ -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);
},

View File

@ -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;