lang.js
5.05 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var /** @type {?} */ globalScope;
if (typeof window === 'undefined') {
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
// TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
globalScope = (self);
}
else {
globalScope = (global);
}
}
else {
globalScope = (window);
}
/**
* @param {?} fn
* @return {?}
*/
export function scheduleMicroTask(fn) {
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
}
// Need to declare a new variable for global here since TypeScript
// exports the original value of the symbol.
var /** @type {?} */ _global = globalScope;
export { _global as global };
/**
* @param {?} type
* @return {?}
*/
export function getTypeNameForDebugging(type) {
return type['name'] || typeof type;
}
// TODO: remove calls to assert in production environment
// Note: Can't just export this and import in in other files
// as `assert` is a reserved keyword in Dart
_global.assert = function assert(condition) {
// TODO: to be fixed properly via #2830, noop for now
};
/**
* @param {?} obj
* @return {?}
*/
export function isPresent(obj) {
return obj != null;
}
/**
* @param {?} obj
* @return {?}
*/
export function isBlank(obj) {
return obj == null;
}
var /** @type {?} */ STRING_MAP_PROTO = Object.getPrototypeOf({});
/**
* @param {?} obj
* @return {?}
*/
export function isStrictStringMap(obj) {
return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
}
/**
* @param {?} obj
* @return {?}
*/
export function isDate(obj) {
return obj instanceof Date && !isNaN(obj.valueOf());
}
/**
* @param {?} token
* @return {?}
*/
export function stringify(token) {
if (typeof token === 'string') {
return token;
}
if (token == null) {
return '' + token;
}
if (token.overriddenName) {
return "" + token.overriddenName;
}
if (token.name) {
return "" + token.name;
}
var /** @type {?} */ res = token.toString();
var /** @type {?} */ newLineIndex = res.indexOf('\n');
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
}
export var NumberWrapper = (function () {
function NumberWrapper() {
}
/**
* @param {?} text
* @return {?}
*/
NumberWrapper.parseIntAutoRadix = function (text) {
var /** @type {?} */ result = parseInt(text);
if (isNaN(result)) {
throw new Error('Invalid integer literal when parsing ' + text);
}
return result;
};
/**
* @param {?} value
* @return {?}
*/
NumberWrapper.isNumeric = function (value) { return !isNaN(value - parseFloat(value)); };
return NumberWrapper;
}());
/**
* @param {?} a
* @param {?} b
* @return {?}
*/
export function looseIdentical(a, b) {
return a === b || typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b);
}
/**
* @param {?} o
* @return {?}
*/
export function isJsObject(o) {
return o !== null && (typeof o === 'function' || typeof o === 'object');
}
/**
* @param {?} obj
* @return {?}
*/
export function print(obj) {
// tslint:disable-next-line:no-console
console.log(obj);
}
/**
* @param {?} obj
* @return {?}
*/
export function warn(obj) {
console.warn(obj);
}
/**
* @param {?} global
* @param {?} path
* @param {?} value
* @return {?}
*/
export function setValueOnPath(global, path, value) {
var /** @type {?} */ parts = path.split('.');
var /** @type {?} */ obj = global;
while (parts.length > 1) {
var /** @type {?} */ name_1 = parts.shift();
if (obj.hasOwnProperty(name_1) && obj[name_1] != null) {
obj = obj[name_1];
}
else {
obj = obj[name_1] = {};
}
}
if (obj === undefined || obj === null) {
obj = {};
}
obj[parts.shift()] = value;
}
var /** @type {?} */ _symbolIterator = null;
/**
* @return {?}
*/
export function getSymbolIterator() {
if (!_symbolIterator) {
if (((globalScope)).Symbol && Symbol.iterator) {
_symbolIterator = Symbol.iterator;
}
else {
// es6-shim specific logic
var /** @type {?} */ keys = Object.getOwnPropertyNames(Map.prototype);
for (var /** @type {?} */ i = 0; i < keys.length; ++i) {
var /** @type {?} */ key = keys[i];
if (key !== 'entries' && key !== 'size' &&
((Map)).prototype[key] === Map.prototype['entries']) {
_symbolIterator = key;
}
}
}
}
return _symbolIterator;
}
/**
* @param {?} obj
* @return {?}
*/
export function isPrimitive(obj) {
return !isJsObject(obj);
}
/**
* @param {?} s
* @return {?}
*/
export function escapeRegExp(s) {
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
//# sourceMappingURL=lang.js.map