UNPKG

skip-event-bridge

Version:
74 lines (55 loc) 1.73 kB
/* eslint-disable vars-on-top */ /* eslint-disable-camelcase */ /* eslint-disable @typescript-eslint/camelcase */ /* eslint-disable @typescript-eslint/no-explicit-any */ export const days = { 0: 'Sunday', 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday' }; const getType = (value: any): string => { return Object.prototype.toString.call(value).replace(/\W/g, '').slice(6); }; export const isType = (value: any, type: string): boolean => { return getType(value).toLowerCase() === type.toLowerCase(); }; export const removeArrays = (obj: object): object => { const objCopy = { ...obj } as any; Object.keys(objCopy).forEach((key) => { if (Array.isArray(objCopy[key])) { delete objCopy[key]; } }); return objCopy; }; export const makeTrustworthy = (obj: any): any => { if (Array.isArray(obj)) { obj.forEach((element) => { makeTrustworthy(element); }); return obj; } const newObj = Object.keys(obj).reduce((prev: Record<string, any>, curr) => { const key = curr.replace(/_/g, ' '); let value = obj[curr]; if (Array.isArray(value) && !value.length) return prev; if (value === null || value === undefined) return prev; if (value instanceof Date) return prev; if (!isType(value, 'date') && typeof value === 'object') { value = makeTrustworthy(value); } return { ...prev, [key]: value }; }, {}); return newObj; }; export const camelCaseToNormalCase = (text: string): any => { if (!text) return null; var newText = text.replace(/([A-Z])/g, ' $1').replace(/^./, function (str: string) { return str.toUpperCase(); }); return newText.substring(1, newText.length); };