|
|
@ -34,7 +34,7 @@ import { |
|
|
} from '@shared/models/js-function.models'; |
|
|
} from '@shared/models/js-function.models'; |
|
|
import { DomSanitizer } from '@angular/platform-browser'; |
|
|
import { DomSanitizer } from '@angular/platform-browser'; |
|
|
import { SecurityContext } from '@angular/core'; |
|
|
import { SecurityContext } from '@angular/core'; |
|
|
import { AbstractControl, ValidationErrors, Validators } from '@angular/forms'; |
|
|
import { AbstractControl, ValidationErrors } from '@angular/forms'; |
|
|
|
|
|
|
|
|
const varsRegex = /\${([^}]*)}/g; |
|
|
const varsRegex = /\${([^}]*)}/g; |
|
|
const emailRegex = /^[A-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; |
|
|
const emailRegex = /^[A-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; |
|
|
@ -795,31 +795,72 @@ export function deepTrim<T>(obj: T): T { |
|
|
}, (Array.isArray(obj) ? [] : {}) as T); |
|
|
}, (Array.isArray(obj) ? [] : {}) as T); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const isValidValue = (value: any): boolean => { |
|
|
|
|
|
return ( |
|
|
|
|
|
value !== undefined && |
|
|
|
|
|
value !== null && |
|
|
|
|
|
value !== '' && |
|
|
|
|
|
!Number.isNaN(value) |
|
|
|
|
|
); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
export function deepClean<T extends Record<string, any> | any[]>(obj: T, { |
|
|
export function deepClean<T extends Record<string, any> | any[]>(obj: T, { |
|
|
cleanKeys = [] |
|
|
cleanKeys = [], |
|
|
|
|
|
cleanOnlyKey = false |
|
|
} = {}): T { |
|
|
} = {}): T { |
|
|
return _.transform(obj, (result, value, key) => { |
|
|
const keysToRemove = new Set(cleanKeys); |
|
|
if (cleanKeys.includes(key)) { |
|
|
|
|
|
return; |
|
|
const clean = (input: any): any => { |
|
|
} |
|
|
if (Array.isArray(input)) { |
|
|
if (Array.isArray(value) || isLiteralObject(value)) { |
|
|
const result: any[] = []; |
|
|
value = deepClean(value, {cleanKeys}); |
|
|
for (const item of input) { |
|
|
} |
|
|
const value = clean(item); |
|
|
if(isLiteralObject(value) && isEmpty(value)) { |
|
|
|
|
|
return; |
|
|
if (cleanOnlyKey) { |
|
|
} |
|
|
result.push(value); |
|
|
if (Array.isArray(value) && !value.length) { |
|
|
continue; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
if (value === undefined || value === null || value === '' || Number.isNaN(value)) { |
|
|
if (isValidValue(value)) { |
|
|
return; |
|
|
const isEmptyArray = Array.isArray(value) && value.length === 0; |
|
|
|
|
|
const isEmptyObj = isLiteralObject(value) && Object.keys(value).length === 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!isEmptyArray && !isEmptyObj) { |
|
|
|
|
|
result.push(value); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (Array.isArray(result)) { |
|
|
if (isLiteralObject(input)) { |
|
|
return result.push(value); |
|
|
const result: Record<string, any> = {}; |
|
|
|
|
|
|
|
|
|
|
|
for (const key in input) { |
|
|
|
|
|
if (keysToRemove.has(key)) continue; |
|
|
|
|
|
|
|
|
|
|
|
const value = clean(input[key]); |
|
|
|
|
|
|
|
|
|
|
|
if (cleanOnlyKey) { |
|
|
|
|
|
result[key] = value; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isValidValue(value)) { |
|
|
|
|
|
const isEmptyArray = Array.isArray(value) && value.length === 0; |
|
|
|
|
|
const isEmptyObj = isLiteralObject(value) && Object.keys(value).length === 0; |
|
|
|
|
|
|
|
|
|
|
|
if (!isEmptyArray && !isEmptyObj) { |
|
|
|
|
|
result[key] = value; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
result[key] = value; |
|
|
return input; |
|
|
}); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return clean(obj); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function generateSecret(length?: number): string { |
|
|
export function generateSecret(length?: number): string { |
|
|
|