forked from NativeScript/nativescript-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang-facade.ts
More file actions
67 lines (59 loc) · 1.81 KB
/
lang-facade.ts
File metadata and controls
67 lines (59 loc) · 1.81 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* tslint:disable */
//Copied unexported functions from @angular/core/src/facade/lang
var globalScope = global;
export var global = globalScope;
export function isPresent(obj: any): boolean {
return obj !== undefined && obj !== null;
}
export function isBlank(obj: any): boolean {
return obj === undefined || obj === null;
}
export function isDate(obj: any): obj is Date {
return obj instanceof Date && !isNaN(obj.valueOf());
}
export function print(obj: Error | Object) {
console.log(obj);
}
export function isJsObject(o: any): boolean {
return o !== null && (typeof o === 'function' || typeof o === 'object');
}
export function isArray(obj: any): boolean {
return Array.isArray(obj);
}
// When Symbol.iterator doesn't exist, retrieves the key used in es6-shim
declare var Symbol: any;
let _symbolIterator: any = null;
export function getSymbolIterator(): string|symbol {
if (isBlank(_symbolIterator)) {
if (isPresent((<any>globalScope).Symbol) && isPresent(Symbol.iterator)) {
_symbolIterator = Symbol.iterator;
} else {
// es6-shim specific logic
let keys = Object.getOwnPropertyNames(Map.prototype);
for (let i = 0; i < keys.length; ++i) {
let key = keys[i];
if (key !== 'entries' && key !== 'size' &&
(Map as any).prototype[key] === Map.prototype['entries']) {
_symbolIterator = key;
}
}
}
}
return _symbolIterator;
}
export function setValueOnPath(global: any, path: string, value: any) {
let parts = path.split('.');
let obj: any = global;
while (parts.length > 1) {
let name = parts.shift();
if (obj.hasOwnProperty(name) && isPresent(obj[name])) {
obj = obj[name];
} else {
obj = obj[name] = {};
}
}
if (obj === undefined || obj === null) {
obj = {};
}
obj[parts.shift()] = value;
}