server/src/Utils.ts
2020-07-19 13:26:57 +00:00

26 lines
No EOL
829 B
TypeScript

export default class Utils {
public static isStrUsable(value: any, keys: string = '') {
return this.isUsable(value, keys, true)
}
public static isUsable(value: any, keys: string = '', isStr = false) {
let bool: boolean = value !== undefined && value !== null
if (keys === '') {
if (isStr) { bool = bool && typeof value === 'string' && value.length > 0 }
return bool
}
let parts: string[] = keys.split('.')
let levels: number = parts.length
let explored: any = null
for (var i = 0; i < levels + 1; i++) {
explored = explored === null ? value : explored[parts[i - 1]]
bool = bool && (
explored !== undefined && explored !== null
)
}
if (isStr) {
bool = bool && typeof explored === 'string' && explored.length > 0
}
return bool
}
}