server/src/Utils.ts

26 lines
829 B
TypeScript
Raw Normal View History

2020-07-16 15:43:18 +00:00
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
)
2020-07-19 13:26:57 +00:00
}
if (isStr) {
bool = bool && typeof explored === 'string' && explored.length > 0
2020-07-16 15:43:18 +00:00
}
return bool
}
}