forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.ts
More file actions
44 lines (44 loc) · 1.47 KB
/
Copy pathUtil.ts
File metadata and controls
44 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export class Util {
public static IsNullUndefinded(obj: any) {
if (obj === null || obj === undefined) { return true; }
return false;
}
public static IsNullEmpty(obj: any) {
if (obj === null || obj === undefined || obj === "") { return true; }
return false;
}
public static IsString(obj: any) {
if (typeof obj === 'string' || obj instanceof String) { return true; }
return false;
}
public static isObject(obj: any): boolean {
return obj === Object(obj);
}
static isNumeric(num) {
return !isNaN(num)
}
public static FetchFromObject(obj: any, prop: string): any {
if (typeof obj === 'undefined') {
return false;
}
var _index = prop.indexOf('.')
if (_index > -1) {
return Util.FetchFromObject(obj[prop.substring(0, _index)], prop.substr(_index + 1));
}
return obj[prop];
}
public static saveToObject(obj: any, path: string, value: any): any {
const pList = path.split('.');
const key = pList.pop();
const pointer = pList.reduce((accumulator, currentValue) => {
if (accumulator[currentValue] === undefined) accumulator[currentValue] = {};
return accumulator[currentValue];
}, obj);
if (Util.isObject(pointer)) {
pointer[key] = value;
} else {
throw new Error(path + ' is not an object!')
}
return obj;
}
}