UNPKG

15.8 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || function (d, b) {
3 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4 function __() { this.constructor = d; }
5 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6};
7var globalScope;
8if (typeof window === 'undefined') {
9 if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
10 // TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
11 globalScope = self;
12 }
13 else {
14 globalScope = global;
15 }
16}
17else {
18 globalScope = window;
19}
20function scheduleMicroTask(fn) {
21 Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
22}
23exports.scheduleMicroTask = scheduleMicroTask;
24exports.IS_DART = false;
25// Need to declare a new variable for global here since TypeScript
26// exports the original value of the symbol.
27var _global = globalScope;
28exports.global = _global;
29exports.Type = Function;
30function getTypeNameForDebugging(type) {
31 if (type['name']) {
32 return type['name'];
33 }
34 return typeof type;
35}
36exports.getTypeNameForDebugging = getTypeNameForDebugging;
37exports.Math = _global.Math;
38exports.Date = _global.Date;
39var _devMode = true;
40var _modeLocked = false;
41function lockMode() {
42 _modeLocked = true;
43}
44exports.lockMode = lockMode;
45/**
46 * Disable Angular's development mode, which turns off assertions and other
47 * checks within the framework.
48 *
49 * One important assertion this disables verifies that a change detection pass
50 * does not result in additional changes to any bindings (also known as
51 * unidirectional data flow).
52 * @stable
53 */
54function enableProdMode() {
55 if (_modeLocked) {
56 // Cannot use BaseException as that ends up importing from facade/lang.
57 throw 'Cannot enable prod mode after platform setup.';
58 }
59 _devMode = false;
60}
61exports.enableProdMode = enableProdMode;
62function assertionsEnabled() {
63 return _devMode;
64}
65exports.assertionsEnabled = assertionsEnabled;
66// TODO: remove calls to assert in production environment
67// Note: Can't just export this and import in in other files
68// as `assert` is a reserved keyword in Dart
69_global.assert = function assert(condition) {
70 // TODO: to be fixed properly via #2830, noop for now
71};
72function isPresent(obj) {
73 return obj !== undefined && obj !== null;
74}
75exports.isPresent = isPresent;
76function isBlank(obj) {
77 return obj === undefined || obj === null;
78}
79exports.isBlank = isBlank;
80function isBoolean(obj) {
81 return typeof obj === 'boolean';
82}
83exports.isBoolean = isBoolean;
84function isNumber(obj) {
85 return typeof obj === 'number';
86}
87exports.isNumber = isNumber;
88function isString(obj) {
89 return typeof obj === 'string';
90}
91exports.isString = isString;
92function isFunction(obj) {
93 return typeof obj === 'function';
94}
95exports.isFunction = isFunction;
96function isType(obj) {
97 return isFunction(obj);
98}
99exports.isType = isType;
100function isStringMap(obj) {
101 return typeof obj === 'object' && obj !== null;
102}
103exports.isStringMap = isStringMap;
104var STRING_MAP_PROTO = Object.getPrototypeOf({});
105function isStrictStringMap(obj) {
106 return isStringMap(obj) && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
107}
108exports.isStrictStringMap = isStrictStringMap;
109function isPromise(obj) {
110 return obj instanceof _global.Promise;
111}
112exports.isPromise = isPromise;
113function isArray(obj) {
114 return Array.isArray(obj);
115}
116exports.isArray = isArray;
117function isDate(obj) {
118 return obj instanceof exports.Date && !isNaN(obj.valueOf());
119}
120exports.isDate = isDate;
121function noop() { }
122exports.noop = noop;
123function stringify(token) {
124 if (typeof token === 'string') {
125 return token;
126 }
127 if (token === undefined || token === null) {
128 return '' + token;
129 }
130 if (token.name) {
131 return token.name;
132 }
133 if (token.overriddenName) {
134 return token.overriddenName;
135 }
136 var res = token.toString();
137 var newLineIndex = res.indexOf('\n');
138 return (newLineIndex === -1) ? res : res.substring(0, newLineIndex);
139}
140exports.stringify = stringify;
141// serialize / deserialize enum exist only for consistency with dart API
142// enums in typescript don't need to be serialized
143function serializeEnum(val) {
144 return val;
145}
146exports.serializeEnum = serializeEnum;
147function deserializeEnum(val, values) {
148 return val;
149}
150exports.deserializeEnum = deserializeEnum;
151function resolveEnumToken(enumValue, val) {
152 return enumValue[val];
153}
154exports.resolveEnumToken = resolveEnumToken;
155var StringWrapper = (function () {
156 function StringWrapper() {
157 }
158 StringWrapper.fromCharCode = function (code) { return String.fromCharCode(code); };
159 StringWrapper.charCodeAt = function (s, index) { return s.charCodeAt(index); };
160 StringWrapper.split = function (s, regExp) { return s.split(regExp); };
161 StringWrapper.equals = function (s, s2) { return s === s2; };
162 StringWrapper.stripLeft = function (s, charVal) {
163 if (s && s.length) {
164 var pos = 0;
165 for (var i = 0; i < s.length; i++) {
166 if (s[i] != charVal)
167 break;
168 pos++;
169 }
170 s = s.substring(pos);
171 }
172 return s;
173 };
174 StringWrapper.stripRight = function (s, charVal) {
175 if (s && s.length) {
176 var pos = s.length;
177 for (var i = s.length - 1; i >= 0; i--) {
178 if (s[i] != charVal)
179 break;
180 pos--;
181 }
182 s = s.substring(0, pos);
183 }
184 return s;
185 };
186 StringWrapper.replace = function (s, from, replace) {
187 return s.replace(from, replace);
188 };
189 StringWrapper.replaceAll = function (s, from, replace) {
190 return s.replace(from, replace);
191 };
192 StringWrapper.slice = function (s, from, to) {
193 if (from === void 0) { from = 0; }
194 if (to === void 0) { to = null; }
195 return s.slice(from, to === null ? undefined : to);
196 };
197 StringWrapper.replaceAllMapped = function (s, from, cb) {
198 return s.replace(from, function () {
199 var matches = [];
200 for (var _i = 0; _i < arguments.length; _i++) {
201 matches[_i - 0] = arguments[_i];
202 }
203 // Remove offset & string from the result array
204 matches.splice(-2, 2);
205 // The callback receives match, p1, ..., pn
206 return cb(matches);
207 });
208 };
209 StringWrapper.contains = function (s, substr) { return s.indexOf(substr) != -1; };
210 StringWrapper.compare = function (a, b) {
211 if (a < b) {
212 return -1;
213 }
214 else if (a > b) {
215 return 1;
216 }
217 else {
218 return 0;
219 }
220 };
221 return StringWrapper;
222}());
223exports.StringWrapper = StringWrapper;
224var StringJoiner = (function () {
225 function StringJoiner(parts) {
226 if (parts === void 0) { parts = []; }
227 this.parts = parts;
228 }
229 StringJoiner.prototype.add = function (part) { this.parts.push(part); };
230 StringJoiner.prototype.toString = function () { return this.parts.join(''); };
231 return StringJoiner;
232}());
233exports.StringJoiner = StringJoiner;
234var NumberParseError = (function (_super) {
235 __extends(NumberParseError, _super);
236 function NumberParseError(message) {
237 _super.call(this);
238 this.message = message;
239 }
240 NumberParseError.prototype.toString = function () { return this.message; };
241 return NumberParseError;
242}(Error));
243exports.NumberParseError = NumberParseError;
244var NumberWrapper = (function () {
245 function NumberWrapper() {
246 }
247 NumberWrapper.toFixed = function (n, fractionDigits) { return n.toFixed(fractionDigits); };
248 NumberWrapper.equal = function (a, b) { return a === b; };
249 NumberWrapper.parseIntAutoRadix = function (text) {
250 var result = parseInt(text);
251 if (isNaN(result)) {
252 throw new NumberParseError('Invalid integer literal when parsing ' + text);
253 }
254 return result;
255 };
256 NumberWrapper.parseInt = function (text, radix) {
257 if (radix == 10) {
258 if (/^(\-|\+)?[0-9]+$/.test(text)) {
259 return parseInt(text, radix);
260 }
261 }
262 else if (radix == 16) {
263 if (/^(\-|\+)?[0-9ABCDEFabcdef]+$/.test(text)) {
264 return parseInt(text, radix);
265 }
266 }
267 else {
268 var result = parseInt(text, radix);
269 if (!isNaN(result)) {
270 return result;
271 }
272 }
273 throw new NumberParseError('Invalid integer literal when parsing ' + text + ' in base ' + radix);
274 };
275 // TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
276 NumberWrapper.parseFloat = function (text) { return parseFloat(text); };
277 Object.defineProperty(NumberWrapper, "NaN", {
278 get: function () { return NaN; },
279 enumerable: true,
280 configurable: true
281 });
282 NumberWrapper.isNaN = function (value) { return isNaN(value); };
283 NumberWrapper.isInteger = function (value) { return Number.isInteger(value); };
284 return NumberWrapper;
285}());
286exports.NumberWrapper = NumberWrapper;
287exports.RegExp = _global.RegExp;
288var RegExpWrapper = (function () {
289 function RegExpWrapper() {
290 }
291 RegExpWrapper.create = function (regExpStr, flags) {
292 if (flags === void 0) { flags = ''; }
293 flags = flags.replace(/g/g, '');
294 return new _global.RegExp(regExpStr, flags + 'g');
295 };
296 RegExpWrapper.firstMatch = function (regExp, input) {
297 // Reset multimatch regex state
298 regExp.lastIndex = 0;
299 return regExp.exec(input);
300 };
301 RegExpWrapper.test = function (regExp, input) {
302 regExp.lastIndex = 0;
303 return regExp.test(input);
304 };
305 RegExpWrapper.matcher = function (regExp, input) {
306 // Reset regex state for the case
307 // someone did not loop over all matches
308 // last time.
309 regExp.lastIndex = 0;
310 return { re: regExp, input: input };
311 };
312 RegExpWrapper.replaceAll = function (regExp, input, replace) {
313 var c = regExp.exec(input);
314 var res = '';
315 regExp.lastIndex = 0;
316 var prev = 0;
317 while (c) {
318 res += input.substring(prev, c.index);
319 res += replace(c);
320 prev = c.index + c[0].length;
321 regExp.lastIndex = prev;
322 c = regExp.exec(input);
323 }
324 res += input.substring(prev);
325 return res;
326 };
327 return RegExpWrapper;
328}());
329exports.RegExpWrapper = RegExpWrapper;
330var RegExpMatcherWrapper = (function () {
331 function RegExpMatcherWrapper() {
332 }
333 RegExpMatcherWrapper.next = function (matcher) {
334 return matcher.re.exec(matcher.input);
335 };
336 return RegExpMatcherWrapper;
337}());
338exports.RegExpMatcherWrapper = RegExpMatcherWrapper;
339var FunctionWrapper = (function () {
340 function FunctionWrapper() {
341 }
342 FunctionWrapper.apply = function (fn, posArgs) { return fn.apply(null, posArgs); };
343 FunctionWrapper.bind = function (fn, scope) { return fn.bind(scope); };
344 return FunctionWrapper;
345}());
346exports.FunctionWrapper = FunctionWrapper;
347// JS has NaN !== NaN
348function looseIdentical(a, b) {
349 return a === b || typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b);
350}
351exports.looseIdentical = looseIdentical;
352// JS considers NaN is the same as NaN for map Key (while NaN !== NaN otherwise)
353// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
354function getMapKey(value) {
355 return value;
356}
357exports.getMapKey = getMapKey;
358function normalizeBlank(obj) {
359 return isBlank(obj) ? null : obj;
360}
361exports.normalizeBlank = normalizeBlank;
362function normalizeBool(obj) {
363 return isBlank(obj) ? false : obj;
364}
365exports.normalizeBool = normalizeBool;
366function isJsObject(o) {
367 return o !== null && (typeof o === 'function' || typeof o === 'object');
368}
369exports.isJsObject = isJsObject;
370function print(obj) {
371 console.log(obj);
372}
373exports.print = print;
374function warn(obj) {
375 console.warn(obj);
376}
377exports.warn = warn;
378// Can't be all uppercase as our transpiler would think it is a special directive...
379var Json = (function () {
380 function Json() {
381 }
382 Json.parse = function (s) { return _global.JSON.parse(s); };
383 Json.stringify = function (data) {
384 // Dart doesn't take 3 arguments
385 return _global.JSON.stringify(data, null, 2);
386 };
387 return Json;
388}());
389exports.Json = Json;
390var DateWrapper = (function () {
391 function DateWrapper() {
392 }
393 DateWrapper.create = function (year, month, day, hour, minutes, seconds, milliseconds) {
394 if (month === void 0) { month = 1; }
395 if (day === void 0) { day = 1; }
396 if (hour === void 0) { hour = 0; }
397 if (minutes === void 0) { minutes = 0; }
398 if (seconds === void 0) { seconds = 0; }
399 if (milliseconds === void 0) { milliseconds = 0; }
400 return new exports.Date(year, month - 1, day, hour, minutes, seconds, milliseconds);
401 };
402 DateWrapper.fromISOString = function (str) { return new exports.Date(str); };
403 DateWrapper.fromMillis = function (ms) { return new exports.Date(ms); };
404 DateWrapper.toMillis = function (date) { return date.getTime(); };
405 DateWrapper.now = function () { return new exports.Date(); };
406 DateWrapper.toJson = function (date) { return date.toJSON(); };
407 return DateWrapper;
408}());
409exports.DateWrapper = DateWrapper;
410function setValueOnPath(global, path, value) {
411 var parts = path.split('.');
412 var obj = global;
413 while (parts.length > 1) {
414 var name = parts.shift();
415 if (obj.hasOwnProperty(name) && isPresent(obj[name])) {
416 obj = obj[name];
417 }
418 else {
419 obj = obj[name] = {};
420 }
421 }
422 if (obj === undefined || obj === null) {
423 obj = {};
424 }
425 obj[parts.shift()] = value;
426}
427exports.setValueOnPath = setValueOnPath;
428var _symbolIterator = null;
429function getSymbolIterator() {
430 if (isBlank(_symbolIterator)) {
431 if (isPresent(globalScope.Symbol) && isPresent(Symbol.iterator)) {
432 _symbolIterator = Symbol.iterator;
433 }
434 else {
435 // es6-shim specific logic
436 var keys = Object.getOwnPropertyNames(Map.prototype);
437 for (var i = 0; i < keys.length; ++i) {
438 var key = keys[i];
439 if (key !== 'entries' && key !== 'size' &&
440 Map.prototype[key] === Map.prototype['entries']) {
441 _symbolIterator = key;
442 }
443 }
444 }
445 }
446 return _symbolIterator;
447}
448exports.getSymbolIterator = getSymbolIterator;
449function evalExpression(sourceUrl, expr, declarations, vars) {
450 var fnBody = declarations + "\nreturn " + expr + "\n//# sourceURL=" + sourceUrl;
451 var fnArgNames = [];
452 var fnArgValues = [];
453 for (var argName in vars) {
454 fnArgNames.push(argName);
455 fnArgValues.push(vars[argName]);
456 }
457 return new (Function.bind.apply(Function, [void 0].concat(fnArgNames.concat(fnBody))))().apply(void 0, fnArgValues);
458}
459exports.evalExpression = evalExpression;
460function isPrimitive(obj) {
461 return !isJsObject(obj);
462}
463exports.isPrimitive = isPrimitive;
464function hasConstructor(value, type) {
465 return value.constructor === type;
466}
467exports.hasConstructor = hasConstructor;
468function bitWiseOr(values) {
469 return values.reduce(function (a, b) { return a | b; });
470}
471exports.bitWiseOr = bitWiseOr;
472function bitWiseAnd(values) {
473 return values.reduce(function (a, b) { return a & b; });
474}
475exports.bitWiseAnd = bitWiseAnd;
476function escape(s) {
477 return _global.encodeURI(s);
478}
479exports.escape = escape;
480//# sourceMappingURL=lang.js.map
\No newline at end of file