1 | /**
|
2 | * @license Angular v9.0.4
|
3 | * (c) 2010-2020 Google LLC. https://angular.io/
|
4 | * License: MIT
|
5 | */
|
6 |
|
7 | import { __decorate, __extends, __param, __metadata, __read, __values } from 'tslib';
|
8 | import { InjectionToken, ɵɵdefineInjectable, Injectable, ɵɵinject, Inject, Optional, EventEmitter, ɵfindLocaleData, ɵLocaleDataIndex, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase, LOCALE_ID, ɵregisterLocaleData, ɵisListLikeIterable, ɵstringify, Input, Directive, IterableDiffers, KeyValueDiffers, ElementRef, Renderer2, NgModuleRef, ComponentFactoryResolver, Type, Injector, NgModuleFactory, ViewContainerRef, isDevMode, TemplateRef, Host, Attribute, ɵlooseIdentical, WrappedValue, ɵisPromise, ɵisObservable, Pipe, ChangeDetectorRef, DEFAULT_CURRENCY_CODE, NgModule, Version, ErrorHandler } from '@angular/core';
|
9 |
|
10 | /**
|
11 | * @license
|
12 | * Copyright Google Inc. All Rights Reserved.
|
13 | *
|
14 | * Use of this source code is governed by an MIT-style license that can be
|
15 | * found in the LICENSE file at https://angular.io/license
|
16 | */
|
17 | var _DOM = null;
|
18 | function getDOM() {
|
19 | return _DOM;
|
20 | }
|
21 | function setDOM(adapter) {
|
22 | _DOM = adapter;
|
23 | }
|
24 | function setRootDomAdapter(adapter) {
|
25 | if (!_DOM) {
|
26 | _DOM = adapter;
|
27 | }
|
28 | }
|
29 | /* tslint:disable:requireParameterType */
|
30 | /**
|
31 | * Provides DOM operations in an environment-agnostic way.
|
32 | *
|
33 | * @security Tread carefully! Interacting with the DOM directly is dangerous and
|
34 | * can introduce XSS risks.
|
35 | */
|
36 | var DomAdapter = /** @class */ (function () {
|
37 | function DomAdapter() {
|
38 | }
|
39 | return DomAdapter;
|
40 | }());
|
41 |
|
42 | /**
|
43 | * @license
|
44 | * Copyright Google Inc. All Rights Reserved.
|
45 | *
|
46 | * Use of this source code is governed by an MIT-style license that can be
|
47 | * found in the LICENSE file at https://angular.io/license
|
48 | */
|
49 | /**
|
50 | * A DI Token representing the main rendering context. In a browser this is the DOM Document.
|
51 | *
|
52 | * Note: Document might not be available in the Application Context when Application and Rendering
|
53 | * Contexts are not the same (e.g. when running the application in a Web Worker).
|
54 | *
|
55 | * @publicApi
|
56 | */
|
57 | var DOCUMENT = new InjectionToken('DocumentToken');
|
58 |
|
59 | /**
|
60 | * This class should not be used directly by an application developer. Instead, use
|
61 | * {@link Location}.
|
62 | *
|
63 | * `PlatformLocation` encapsulates all calls to DOM apis, which allows the Router to be platform
|
64 | * agnostic.
|
65 | * This means that we can have different implementation of `PlatformLocation` for the different
|
66 | * platforms that angular supports. For example, `@angular/platform-browser` provides an
|
67 | * implementation specific to the browser environment, while `@angular/platform-webworker` provides
|
68 | * one suitable for use with web workers.
|
69 | *
|
70 | * The `PlatformLocation` class is used directly by all implementations of {@link LocationStrategy}
|
71 | * when they need to interact with the DOM apis like pushState, popState, etc...
|
72 | *
|
73 | * {@link LocationStrategy} in turn is used by the {@link Location} service which is used directly
|
74 | * by the {@link Router} in order to navigate between routes. Since all interactions between {@link
|
75 | * Router} /
|
76 | * {@link Location} / {@link LocationStrategy} and DOM apis flow through the `PlatformLocation`
|
77 | * class they are all platform independent.
|
78 | *
|
79 | * @publicApi
|
80 | */
|
81 | var PlatformLocation = /** @class */ (function () {
|
82 | function PlatformLocation() {
|
83 | }
|
84 | PlatformLocation.ɵprov = ɵɵdefineInjectable({ factory: useBrowserPlatformLocation, token: PlatformLocation, providedIn: "platform" });
|
85 | PlatformLocation = __decorate([
|
86 | Injectable({
|
87 | providedIn: 'platform',
|
88 | // See #23917
|
89 | useFactory: useBrowserPlatformLocation
|
90 | })
|
91 | ], PlatformLocation);
|
92 | return PlatformLocation;
|
93 | }());
|
94 | function useBrowserPlatformLocation() {
|
95 | return ɵɵinject(BrowserPlatformLocation);
|
96 | }
|
97 | /**
|
98 | * @description
|
99 | * Indicates when a location is initialized.
|
100 | *
|
101 | * @publicApi
|
102 | */
|
103 | var LOCATION_INITIALIZED = new InjectionToken('Location Initialized');
|
104 | /**
|
105 | * `PlatformLocation` encapsulates all of the direct calls to platform APIs.
|
106 | * This class should not be used directly by an application developer. Instead, use
|
107 | * {@link Location}.
|
108 | */
|
109 | var BrowserPlatformLocation = /** @class */ (function (_super) {
|
110 | __extends(BrowserPlatformLocation, _super);
|
111 | function BrowserPlatformLocation(_doc) {
|
112 | var _this = _super.call(this) || this;
|
113 | _this._doc = _doc;
|
114 | _this._init();
|
115 | return _this;
|
116 | }
|
117 | // This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
|
118 | /** @internal */
|
119 | BrowserPlatformLocation.prototype._init = function () {
|
120 | this.location = getDOM().getLocation();
|
121 | this._history = getDOM().getHistory();
|
122 | };
|
123 | BrowserPlatformLocation.prototype.getBaseHrefFromDOM = function () { return getDOM().getBaseHref(this._doc); };
|
124 | BrowserPlatformLocation.prototype.onPopState = function (fn) {
|
125 | getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('popstate', fn, false);
|
126 | };
|
127 | BrowserPlatformLocation.prototype.onHashChange = function (fn) {
|
128 | getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
|
129 | };
|
130 | Object.defineProperty(BrowserPlatformLocation.prototype, "href", {
|
131 | get: function () { return this.location.href; },
|
132 | enumerable: true,
|
133 | configurable: true
|
134 | });
|
135 | Object.defineProperty(BrowserPlatformLocation.prototype, "protocol", {
|
136 | get: function () { return this.location.protocol; },
|
137 | enumerable: true,
|
138 | configurable: true
|
139 | });
|
140 | Object.defineProperty(BrowserPlatformLocation.prototype, "hostname", {
|
141 | get: function () { return this.location.hostname; },
|
142 | enumerable: true,
|
143 | configurable: true
|
144 | });
|
145 | Object.defineProperty(BrowserPlatformLocation.prototype, "port", {
|
146 | get: function () { return this.location.port; },
|
147 | enumerable: true,
|
148 | configurable: true
|
149 | });
|
150 | Object.defineProperty(BrowserPlatformLocation.prototype, "pathname", {
|
151 | get: function () { return this.location.pathname; },
|
152 | set: function (newPath) { this.location.pathname = newPath; },
|
153 | enumerable: true,
|
154 | configurable: true
|
155 | });
|
156 | Object.defineProperty(BrowserPlatformLocation.prototype, "search", {
|
157 | get: function () { return this.location.search; },
|
158 | enumerable: true,
|
159 | configurable: true
|
160 | });
|
161 | Object.defineProperty(BrowserPlatformLocation.prototype, "hash", {
|
162 | get: function () { return this.location.hash; },
|
163 | enumerable: true,
|
164 | configurable: true
|
165 | });
|
166 | BrowserPlatformLocation.prototype.pushState = function (state, title, url) {
|
167 | if (supportsState()) {
|
168 | this._history.pushState(state, title, url);
|
169 | }
|
170 | else {
|
171 | this.location.hash = url;
|
172 | }
|
173 | };
|
174 | BrowserPlatformLocation.prototype.replaceState = function (state, title, url) {
|
175 | if (supportsState()) {
|
176 | this._history.replaceState(state, title, url);
|
177 | }
|
178 | else {
|
179 | this.location.hash = url;
|
180 | }
|
181 | };
|
182 | BrowserPlatformLocation.prototype.forward = function () { this._history.forward(); };
|
183 | BrowserPlatformLocation.prototype.back = function () { this._history.back(); };
|
184 | BrowserPlatformLocation.prototype.getState = function () { return this._history.state; };
|
185 | BrowserPlatformLocation.ɵprov = ɵɵdefineInjectable({ factory: createBrowserPlatformLocation, token: BrowserPlatformLocation, providedIn: "platform" });
|
186 | BrowserPlatformLocation = __decorate([
|
187 | Injectable({
|
188 | providedIn: 'platform',
|
189 | // See #23917
|
190 | useFactory: createBrowserPlatformLocation,
|
191 | }),
|
192 | __param(0, Inject(DOCUMENT)),
|
193 | __metadata("design:paramtypes", [Object])
|
194 | ], BrowserPlatformLocation);
|
195 | return BrowserPlatformLocation;
|
196 | }(PlatformLocation));
|
197 | function supportsState() {
|
198 | return !!window.history.pushState;
|
199 | }
|
200 | function createBrowserPlatformLocation() {
|
201 | return new BrowserPlatformLocation(ɵɵinject(DOCUMENT));
|
202 | }
|
203 |
|
204 | /**
|
205 | * @license
|
206 | * Copyright Google Inc. All Rights Reserved.
|
207 | *
|
208 | * Use of this source code is governed by an MIT-style license that can be
|
209 | * found in the LICENSE file at https://angular.io/license
|
210 | */
|
211 |
|
212 | /**
|
213 | * @license
|
214 | * Copyright Google Inc. All Rights Reserved.
|
215 | *
|
216 | * Use of this source code is governed by an MIT-style license that can be
|
217 | * found in the LICENSE file at https://angular.io/license
|
218 | */
|
219 | /**
|
220 | * Joins two parts of a URL with a slash if needed.
|
221 | *
|
222 | * @param start URL string
|
223 | * @param end URL string
|
224 | *
|
225 | *
|
226 | * @returns The joined URL string.
|
227 | */
|
228 | function joinWithSlash(start, end) {
|
229 | if (start.length == 0) {
|
230 | return end;
|
231 | }
|
232 | if (end.length == 0) {
|
233 | return start;
|
234 | }
|
235 | var slashes = 0;
|
236 | if (start.endsWith('/')) {
|
237 | slashes++;
|
238 | }
|
239 | if (end.startsWith('/')) {
|
240 | slashes++;
|
241 | }
|
242 | if (slashes == 2) {
|
243 | return start + end.substring(1);
|
244 | }
|
245 | if (slashes == 1) {
|
246 | return start + end;
|
247 | }
|
248 | return start + '/' + end;
|
249 | }
|
250 | /**
|
251 | * Removes a trailing slash from a URL string if needed.
|
252 | * Looks for the first occurrence of either `#`, `?`, or the end of the
|
253 | * line as `/` characters and removes the trailing slash if one exists.
|
254 | *
|
255 | * @param url URL string.
|
256 | *
|
257 | * @returns The URL string, modified if needed.
|
258 | */
|
259 | function stripTrailingSlash(url) {
|
260 | var match = url.match(/#|\?|$/);
|
261 | var pathEndIdx = match && match.index || url.length;
|
262 | var droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
|
263 | return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
|
264 | }
|
265 | /**
|
266 | * Normalizes URL parameters by prepending with `?` if needed.
|
267 | *
|
268 | * @param params String of URL parameters.
|
269 | *
|
270 | * @returns The normalized URL parameters string.
|
271 | */
|
272 | function normalizeQueryParams(params) {
|
273 | return params && params[0] !== '?' ? '?' + params : params;
|
274 | }
|
275 |
|
276 | /**
|
277 | * Enables the `Location` service to read route state from the browser's URL.
|
278 | * Angular provides two strategies:
|
279 | * `HashLocationStrategy` and `PathLocationStrategy`.
|
280 | *
|
281 | * Applications should use the `Router` or `Location` services to
|
282 | * interact with application route state.
|
283 | *
|
284 | * For instance, `HashLocationStrategy` produces URLs like
|
285 | * <code class="no-auto-link">http://example.com#/foo</code>,
|
286 | * and `PathLocationStrategy` produces
|
287 | * <code class="no-auto-link">http://example.com/foo</code> as an equivalent URL.
|
288 | *
|
289 | * See these two classes for more.
|
290 | *
|
291 | * @publicApi
|
292 | */
|
293 | var LocationStrategy = /** @class */ (function () {
|
294 | function LocationStrategy() {
|
295 | }
|
296 | LocationStrategy.ɵprov = ɵɵdefineInjectable({ factory: provideLocationStrategy, token: LocationStrategy, providedIn: "root" });
|
297 | LocationStrategy = __decorate([
|
298 | Injectable({ providedIn: 'root', useFactory: provideLocationStrategy })
|
299 | ], LocationStrategy);
|
300 | return LocationStrategy;
|
301 | }());
|
302 | function provideLocationStrategy(platformLocation) {
|
303 | // See #23917
|
304 | var location = ɵɵinject(DOCUMENT).location;
|
305 | return new PathLocationStrategy(ɵɵinject(PlatformLocation), location && location.origin || '');
|
306 | }
|
307 | /**
|
308 | * A predefined [DI token](guide/glossary#di-token) for the base href
|
309 | * to be used with the `PathLocationStrategy`.
|
310 | * The base href is the URL prefix that should be preserved when generating
|
311 | * and recognizing URLs.
|
312 | *
|
313 | * @usageNotes
|
314 | *
|
315 | * The following example shows how to use this token to configure the root app injector
|
316 | * with a base href value, so that the DI framework can supply the dependency anywhere in the app.
|
317 | *
|
318 | * ```typescript
|
319 | * import {Component, NgModule} from '@angular/core';
|
320 | * import {APP_BASE_HREF} from '@angular/common';
|
321 | *
|
322 | * @NgModule({
|
323 | * providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
|
324 | * })
|
325 | * class AppModule {}
|
326 | * ```
|
327 | *
|
328 | * @publicApi
|
329 | */
|
330 | var APP_BASE_HREF = new InjectionToken('appBaseHref');
|
331 | /**
|
332 | * @description
|
333 | * A {@link LocationStrategy} used to configure the {@link Location} service to
|
334 | * represent its state in the
|
335 | * [path](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax) of the
|
336 | * browser's URL.
|
337 | *
|
338 | * If you're using `PathLocationStrategy`, you must provide a {@link APP_BASE_HREF}
|
339 | * or add a base element to the document. This URL prefix that will be preserved
|
340 | * when generating and recognizing URLs.
|
341 | *
|
342 | * For instance, if you provide an `APP_BASE_HREF` of `'/my/app'` and call
|
343 | * `location.go('/foo')`, the browser's URL will become
|
344 | * `example.com/my/app/foo`.
|
345 | *
|
346 | * Similarly, if you add `<base href='/my/app'/>` to the document and call
|
347 | * `location.go('/foo')`, the browser's URL will become
|
348 | * `example.com/my/app/foo`.
|
349 | *
|
350 | * @usageNotes
|
351 | *
|
352 | * ### Example
|
353 | *
|
354 | * {@example common/location/ts/path_location_component.ts region='LocationComponent'}
|
355 | *
|
356 | * @publicApi
|
357 | */
|
358 | var PathLocationStrategy = /** @class */ (function (_super) {
|
359 | __extends(PathLocationStrategy, _super);
|
360 | function PathLocationStrategy(_platformLocation, href) {
|
361 | var _this = _super.call(this) || this;
|
362 | _this._platformLocation = _platformLocation;
|
363 | if (href == null) {
|
364 | href = _this._platformLocation.getBaseHrefFromDOM();
|
365 | }
|
366 | if (href == null) {
|
367 | throw new Error("No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.");
|
368 | }
|
369 | _this._baseHref = href;
|
370 | return _this;
|
371 | }
|
372 | PathLocationStrategy.prototype.onPopState = function (fn) {
|
373 | this._platformLocation.onPopState(fn);
|
374 | this._platformLocation.onHashChange(fn);
|
375 | };
|
376 | PathLocationStrategy.prototype.getBaseHref = function () { return this._baseHref; };
|
377 | PathLocationStrategy.prototype.prepareExternalUrl = function (internal) { return joinWithSlash(this._baseHref, internal); };
|
378 | PathLocationStrategy.prototype.path = function (includeHash) {
|
379 | if (includeHash === void 0) { includeHash = false; }
|
380 | var pathname = this._platformLocation.pathname + normalizeQueryParams(this._platformLocation.search);
|
381 | var hash = this._platformLocation.hash;
|
382 | return hash && includeHash ? "" + pathname + hash : pathname;
|
383 | };
|
384 | PathLocationStrategy.prototype.pushState = function (state, title, url, queryParams) {
|
385 | var externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
386 | this._platformLocation.pushState(state, title, externalUrl);
|
387 | };
|
388 | PathLocationStrategy.prototype.replaceState = function (state, title, url, queryParams) {
|
389 | var externalUrl = this.prepareExternalUrl(url + normalizeQueryParams(queryParams));
|
390 | this._platformLocation.replaceState(state, title, externalUrl);
|
391 | };
|
392 | PathLocationStrategy.prototype.forward = function () { this._platformLocation.forward(); };
|
393 | PathLocationStrategy.prototype.back = function () { this._platformLocation.back(); };
|
394 | PathLocationStrategy = __decorate([
|
395 | Injectable(),
|
396 | __param(1, Optional()), __param(1, Inject(APP_BASE_HREF)),
|
397 | __metadata("design:paramtypes", [PlatformLocation, String])
|
398 | ], PathLocationStrategy);
|
399 | return PathLocationStrategy;
|
400 | }(LocationStrategy));
|
401 |
|
402 | /**
|
403 | * @license
|
404 | * Copyright Google Inc. All Rights Reserved.
|
405 | *
|
406 | * Use of this source code is governed by an MIT-style license that can be
|
407 | * found in the LICENSE file at https://angular.io/license
|
408 | */
|
409 | /**
|
410 | * @description
|
411 | * A {@link LocationStrategy} used to configure the {@link Location} service to
|
412 | * represent its state in the
|
413 | * [hash fragment](https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax)
|
414 | * of the browser's URL.
|
415 | *
|
416 | * For instance, if you call `location.go('/foo')`, the browser's URL will become
|
417 | * `example.com#/foo`.
|
418 | *
|
419 | * @usageNotes
|
420 | *
|
421 | * ### Example
|
422 | *
|
423 | * {@example common/location/ts/hash_location_component.ts region='LocationComponent'}
|
424 | *
|
425 | * @publicApi
|
426 | */
|
427 | var HashLocationStrategy = /** @class */ (function (_super) {
|
428 | __extends(HashLocationStrategy, _super);
|
429 | function HashLocationStrategy(_platformLocation, _baseHref) {
|
430 | var _this = _super.call(this) || this;
|
431 | _this._platformLocation = _platformLocation;
|
432 | _this._baseHref = '';
|
433 | if (_baseHref != null) {
|
434 | _this._baseHref = _baseHref;
|
435 | }
|
436 | return _this;
|
437 | }
|
438 | HashLocationStrategy.prototype.onPopState = function (fn) {
|
439 | this._platformLocation.onPopState(fn);
|
440 | this._platformLocation.onHashChange(fn);
|
441 | };
|
442 | HashLocationStrategy.prototype.getBaseHref = function () { return this._baseHref; };
|
443 | HashLocationStrategy.prototype.path = function (includeHash) {
|
444 | if (includeHash === void 0) { includeHash = false; }
|
445 | // the hash value is always prefixed with a `#`
|
446 | // and if it is empty then it will stay empty
|
447 | var path = this._platformLocation.hash;
|
448 | if (path == null)
|
449 | path = '#';
|
450 | return path.length > 0 ? path.substring(1) : path;
|
451 | };
|
452 | HashLocationStrategy.prototype.prepareExternalUrl = function (internal) {
|
453 | var url = joinWithSlash(this._baseHref, internal);
|
454 | return url.length > 0 ? ('#' + url) : url;
|
455 | };
|
456 | HashLocationStrategy.prototype.pushState = function (state, title, path, queryParams) {
|
457 | var url = this.prepareExternalUrl(path + normalizeQueryParams(queryParams));
|
458 | if (url.length == 0) {
|
459 | url = this._platformLocation.pathname;
|
460 | }
|
461 | this._platformLocation.pushState(state, title, url);
|
462 | };
|
463 | HashLocationStrategy.prototype.replaceState = function (state, title, path, queryParams) {
|
464 | var url = this.prepareExternalUrl(path + normalizeQueryParams(queryParams));
|
465 | if (url.length == 0) {
|
466 | url = this._platformLocation.pathname;
|
467 | }
|
468 | this._platformLocation.replaceState(state, title, url);
|
469 | };
|
470 | HashLocationStrategy.prototype.forward = function () { this._platformLocation.forward(); };
|
471 | HashLocationStrategy.prototype.back = function () { this._platformLocation.back(); };
|
472 | HashLocationStrategy = __decorate([
|
473 | Injectable(),
|
474 | __param(1, Optional()), __param(1, Inject(APP_BASE_HREF)),
|
475 | __metadata("design:paramtypes", [PlatformLocation, String])
|
476 | ], HashLocationStrategy);
|
477 | return HashLocationStrategy;
|
478 | }(LocationStrategy));
|
479 |
|
480 | /**
|
481 | * @description
|
482 | *
|
483 | * A service that applications can use to interact with a browser's URL.
|
484 | *
|
485 | * Depending on the `LocationStrategy` used, `Location` persists
|
486 | * to the URL's path or the URL's hash segment.
|
487 | *
|
488 | * @usageNotes
|
489 | *
|
490 | * It's better to use the `Router#navigate` service to trigger route changes. Use
|
491 | * `Location` only if you need to interact with or create normalized URLs outside of
|
492 | * routing.
|
493 | *
|
494 | * `Location` is responsible for normalizing the URL against the application's base href.
|
495 | * A normalized URL is absolute from the URL host, includes the application's base href, and has no
|
496 | * trailing slash:
|
497 | * - `/my/app/user/123` is normalized
|
498 | * - `my/app/user/123` **is not** normalized
|
499 | * - `/my/app/user/123/` **is not** normalized
|
500 | *
|
501 | * ### Example
|
502 | *
|
503 | * <code-example path='common/location/ts/path_location_component.ts'
|
504 | * region='LocationComponent'></code-example>
|
505 | *
|
506 | * @publicApi
|
507 | */
|
508 | var Location = /** @class */ (function () {
|
509 | function Location(platformStrategy, platformLocation) {
|
510 | var _this = this;
|
511 | /** @internal */
|
512 | this._subject = new EventEmitter();
|
513 | /** @internal */
|
514 | this._urlChangeListeners = [];
|
515 | this._platformStrategy = platformStrategy;
|
516 | var browserBaseHref = this._platformStrategy.getBaseHref();
|
517 | this._platformLocation = platformLocation;
|
518 | this._baseHref = stripTrailingSlash(_stripIndexHtml(browserBaseHref));
|
519 | this._platformStrategy.onPopState(function (ev) {
|
520 | _this._subject.emit({
|
521 | 'url': _this.path(true),
|
522 | 'pop': true,
|
523 | 'state': ev.state,
|
524 | 'type': ev.type,
|
525 | });
|
526 | });
|
527 | }
|
528 | Location_1 = Location;
|
529 | /**
|
530 | * Normalizes the URL path for this location.
|
531 | *
|
532 | * @param includeHash True to include an anchor fragment in the path.
|
533 | *
|
534 | * @returns The normalized URL path.
|
535 | */
|
536 | // TODO: vsavkin. Remove the boolean flag and always include hash once the deprecated router is
|
537 | // removed.
|
538 | Location.prototype.path = function (includeHash) {
|
539 | if (includeHash === void 0) { includeHash = false; }
|
540 | return this.normalize(this._platformStrategy.path(includeHash));
|
541 | };
|
542 | /**
|
543 | * Reports the current state of the location history.
|
544 | * @returns The current value of the `history.state` object.
|
545 | */
|
546 | Location.prototype.getState = function () { return this._platformLocation.getState(); };
|
547 | /**
|
548 | * Normalizes the given path and compares to the current normalized path.
|
549 | *
|
550 | * @param path The given URL path.
|
551 | * @param query Query parameters.
|
552 | *
|
553 | * @returns True if the given URL path is equal to the current normalized path, false
|
554 | * otherwise.
|
555 | */
|
556 | Location.prototype.isCurrentPathEqualTo = function (path, query) {
|
557 | if (query === void 0) { query = ''; }
|
558 | return this.path() == this.normalize(path + normalizeQueryParams(query));
|
559 | };
|
560 | /**
|
561 | * Normalizes a URL path by stripping any trailing slashes.
|
562 | *
|
563 | * @param url String representing a URL.
|
564 | *
|
565 | * @returns The normalized URL string.
|
566 | */
|
567 | Location.prototype.normalize = function (url) {
|
568 | return Location_1.stripTrailingSlash(_stripBaseHref(this._baseHref, _stripIndexHtml(url)));
|
569 | };
|
570 | /**
|
571 | * Normalizes an external URL path.
|
572 | * If the given URL doesn't begin with a leading slash (`'/'`), adds one
|
573 | * before normalizing. Adds a hash if `HashLocationStrategy` is
|
574 | * in use, or the `APP_BASE_HREF` if the `PathLocationStrategy` is in use.
|
575 | *
|
576 | * @param url String representing a URL.
|
577 | *
|
578 | * @returns A normalized platform-specific URL.
|
579 | */
|
580 | Location.prototype.prepareExternalUrl = function (url) {
|
581 | if (url && url[0] !== '/') {
|
582 | url = '/' + url;
|
583 | }
|
584 | return this._platformStrategy.prepareExternalUrl(url);
|
585 | };
|
586 | // TODO: rename this method to pushState
|
587 | /**
|
588 | * Changes the browser's URL to a normalized version of a given URL, and pushes a
|
589 | * new item onto the platform's history.
|
590 | *
|
591 | * @param path URL path to normalize.
|
592 | * @param query Query parameters.
|
593 | * @param state Location history state.
|
594 | *
|
595 | */
|
596 | Location.prototype.go = function (path, query, state) {
|
597 | if (query === void 0) { query = ''; }
|
598 | if (state === void 0) { state = null; }
|
599 | this._platformStrategy.pushState(state, '', path, query);
|
600 | this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
601 | };
|
602 | /**
|
603 | * Changes the browser's URL to a normalized version of the given URL, and replaces
|
604 | * the top item on the platform's history stack.
|
605 | *
|
606 | * @param path URL path to normalize.
|
607 | * @param query Query parameters.
|
608 | * @param state Location history state.
|
609 | */
|
610 | Location.prototype.replaceState = function (path, query, state) {
|
611 | if (query === void 0) { query = ''; }
|
612 | if (state === void 0) { state = null; }
|
613 | this._platformStrategy.replaceState(state, '', path, query);
|
614 | this._notifyUrlChangeListeners(this.prepareExternalUrl(path + normalizeQueryParams(query)), state);
|
615 | };
|
616 | /**
|
617 | * Navigates forward in the platform's history.
|
618 | */
|
619 | Location.prototype.forward = function () { this._platformStrategy.forward(); };
|
620 | /**
|
621 | * Navigates back in the platform's history.
|
622 | */
|
623 | Location.prototype.back = function () { this._platformStrategy.back(); };
|
624 | /**
|
625 | * Registers a URL change listener. Use to catch updates performed by the Angular
|
626 | * framework that are not detectible through "popstate" or "hashchange" events.
|
627 | *
|
628 | * @param fn The change handler function, which take a URL and a location history state.
|
629 | */
|
630 | Location.prototype.onUrlChange = function (fn) {
|
631 | var _this = this;
|
632 | this._urlChangeListeners.push(fn);
|
633 | this.subscribe(function (v) { _this._notifyUrlChangeListeners(v.url, v.state); });
|
634 | };
|
635 | /** @internal */
|
636 | Location.prototype._notifyUrlChangeListeners = function (url, state) {
|
637 | if (url === void 0) { url = ''; }
|
638 | this._urlChangeListeners.forEach(function (fn) { return fn(url, state); });
|
639 | };
|
640 | /**
|
641 | * Subscribes to the platform's `popState` events.
|
642 | *
|
643 | * @param value Event that is triggered when the state history changes.
|
644 | * @param exception The exception to throw.
|
645 | *
|
646 | * @returns Subscribed events.
|
647 | */
|
648 | Location.prototype.subscribe = function (onNext, onThrow, onReturn) {
|
649 | return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn });
|
650 | };
|
651 | var Location_1;
|
652 | /**
|
653 | * Normalizes URL parameters by prepending with `?` if needed.
|
654 | *
|
655 | * @param params String of URL parameters.
|
656 | *
|
657 | * @returns The normalized URL parameters string.
|
658 | */
|
659 | Location.normalizeQueryParams = normalizeQueryParams;
|
660 | /**
|
661 | * Joins two parts of a URL with a slash if needed.
|
662 | *
|
663 | * @param start URL string
|
664 | * @param end URL string
|
665 | *
|
666 | *
|
667 | * @returns The joined URL string.
|
668 | */
|
669 | Location.joinWithSlash = joinWithSlash;
|
670 | /**
|
671 | * Removes a trailing slash from a URL string if needed.
|
672 | * Looks for the first occurrence of either `#`, `?`, or the end of the
|
673 | * line as `/` characters and removes the trailing slash if one exists.
|
674 | *
|
675 | * @param url URL string.
|
676 | *
|
677 | * @returns The URL string, modified if needed.
|
678 | */
|
679 | Location.stripTrailingSlash = stripTrailingSlash;
|
680 | Location.ɵprov = ɵɵdefineInjectable({ factory: createLocation, token: Location, providedIn: "root" });
|
681 | Location = Location_1 = __decorate([
|
682 | Injectable({
|
683 | providedIn: 'root',
|
684 | // See #23917
|
685 | useFactory: createLocation,
|
686 | }),
|
687 | __metadata("design:paramtypes", [LocationStrategy, PlatformLocation])
|
688 | ], Location);
|
689 | return Location;
|
690 | }());
|
691 | function createLocation() {
|
692 | return new Location(ɵɵinject(LocationStrategy), ɵɵinject(PlatformLocation));
|
693 | }
|
694 | function _stripBaseHref(baseHref, url) {
|
695 | return baseHref && url.startsWith(baseHref) ? url.substring(baseHref.length) : url;
|
696 | }
|
697 | function _stripIndexHtml(url) {
|
698 | return url.replace(/\/index.html$/, '');
|
699 | }
|
700 |
|
701 | /**
|
702 | * @license
|
703 | * Copyright Google Inc. All Rights Reserved.
|
704 | *
|
705 | * Use of this source code is governed by an MIT-style license that can be
|
706 | * found in the LICENSE file at https://angular.io/license
|
707 | */
|
708 |
|
709 | /**
|
710 | * @license
|
711 | * Copyright Google Inc. All Rights Reserved.
|
712 | *
|
713 | * Use of this source code is governed by an MIT-style license that can be
|
714 | * found in the LICENSE file at https://angular.io/license
|
715 | */
|
716 | /** @internal */
|
717 | var CURRENCIES_EN = {
|
718 | 'ADP': [undefined, undefined, 0],
|
719 | 'AFN': [undefined, undefined, 0],
|
720 | 'ALL': [undefined, undefined, 0],
|
721 | 'AMD': [undefined, undefined, 2],
|
722 | 'AOA': [undefined, 'Kz'],
|
723 | 'ARS': [undefined, '$'],
|
724 | 'AUD': ['A$', '$'],
|
725 | 'BAM': [undefined, 'KM'],
|
726 | 'BBD': [undefined, '$'],
|
727 | 'BDT': [undefined, '৳'],
|
728 | 'BHD': [undefined, undefined, 3],
|
729 | 'BIF': [undefined, undefined, 0],
|
730 | 'BMD': [undefined, '$'],
|
731 | 'BND': [undefined, '$'],
|
732 | 'BOB': [undefined, 'Bs'],
|
733 | 'BRL': ['R$'],
|
734 | 'BSD': [undefined, '$'],
|
735 | 'BWP': [undefined, 'P'],
|
736 | 'BYN': [undefined, 'р.', 2],
|
737 | 'BYR': [undefined, undefined, 0],
|
738 | 'BZD': [undefined, '$'],
|
739 | 'CAD': ['CA$', '$', 2],
|
740 | 'CHF': [undefined, undefined, 2],
|
741 | 'CLF': [undefined, undefined, 4],
|
742 | 'CLP': [undefined, '$', 0],
|
743 | 'CNY': ['CN¥', '¥'],
|
744 | 'COP': [undefined, '$', 2],
|
745 | 'CRC': [undefined, '₡', 2],
|
746 | 'CUC': [undefined, '$'],
|
747 | 'CUP': [undefined, '$'],
|
748 | 'CZK': [undefined, 'Kč', 2],
|
749 | 'DJF': [undefined, undefined, 0],
|
750 | 'DKK': [undefined, 'kr', 2],
|
751 | 'DOP': [undefined, '$'],
|
752 | 'EGP': [undefined, 'E£'],
|
753 | 'ESP': [undefined, '₧', 0],
|
754 | 'EUR': ['€'],
|
755 | 'FJD': [undefined, '$'],
|
756 | 'FKP': [undefined, '£'],
|
757 | 'GBP': ['£'],
|
758 | 'GEL': [undefined, '₾'],
|
759 | 'GIP': [undefined, '£'],
|
760 | 'GNF': [undefined, 'FG', 0],
|
761 | 'GTQ': [undefined, 'Q'],
|
762 | 'GYD': [undefined, '$', 2],
|
763 | 'HKD': ['HK$', '$'],
|
764 | 'HNL': [undefined, 'L'],
|
765 | 'HRK': [undefined, 'kn'],
|
766 | 'HUF': [undefined, 'Ft', 2],
|
767 | 'IDR': [undefined, 'Rp', 2],
|
768 | 'ILS': ['₪'],
|
769 | 'INR': ['₹'],
|
770 | 'IQD': [undefined, undefined, 0],
|
771 | 'IRR': [undefined, undefined, 0],
|
772 | 'ISK': [undefined, 'kr', 0],
|
773 | 'ITL': [undefined, undefined, 0],
|
774 | 'JMD': [undefined, '$'],
|
775 | 'JOD': [undefined, undefined, 3],
|
776 | 'JPY': ['¥', undefined, 0],
|
777 | 'KHR': [undefined, '៛'],
|
778 | 'KMF': [undefined, 'CF', 0],
|
779 | 'KPW': [undefined, '₩', 0],
|
780 | 'KRW': ['₩', undefined, 0],
|
781 | 'KWD': [undefined, undefined, 3],
|
782 | 'KYD': [undefined, '$'],
|
783 | 'KZT': [undefined, '₸'],
|
784 | 'LAK': [undefined, '₭', 0],
|
785 | 'LBP': [undefined, 'L£', 0],
|
786 | 'LKR': [undefined, 'Rs'],
|
787 | 'LRD': [undefined, '$'],
|
788 | 'LTL': [undefined, 'Lt'],
|
789 | 'LUF': [undefined, undefined, 0],
|
790 | 'LVL': [undefined, 'Ls'],
|
791 | 'LYD': [undefined, undefined, 3],
|
792 | 'MGA': [undefined, 'Ar', 0],
|
793 | 'MGF': [undefined, undefined, 0],
|
794 | 'MMK': [undefined, 'K', 0],
|
795 | 'MNT': [undefined, '₮', 2],
|
796 | 'MRO': [undefined, undefined, 0],
|
797 | 'MUR': [undefined, 'Rs', 2],
|
798 | 'MXN': ['MX$', '$'],
|
799 | 'MYR': [undefined, 'RM'],
|
800 | 'NAD': [undefined, '$'],
|
801 | 'NGN': [undefined, '₦'],
|
802 | 'NIO': [undefined, 'C$'],
|
803 | 'NOK': [undefined, 'kr', 2],
|
804 | 'NPR': [undefined, 'Rs'],
|
805 | 'NZD': ['NZ$', '$'],
|
806 | 'OMR': [undefined, undefined, 3],
|
807 | 'PHP': [undefined, '₱'],
|
808 | 'PKR': [undefined, 'Rs', 2],
|
809 | 'PLN': [undefined, 'zł'],
|
810 | 'PYG': [undefined, '₲', 0],
|
811 | 'RON': [undefined, 'lei'],
|
812 | 'RSD': [undefined, undefined, 0],
|
813 | 'RUB': [undefined, '₽'],
|
814 | 'RUR': [undefined, 'р.'],
|
815 | 'RWF': [undefined, 'RF', 0],
|
816 | 'SBD': [undefined, '$'],
|
817 | 'SEK': [undefined, 'kr', 2],
|
818 | 'SGD': [undefined, '$'],
|
819 | 'SHP': [undefined, '£'],
|
820 | 'SLL': [undefined, undefined, 0],
|
821 | 'SOS': [undefined, undefined, 0],
|
822 | 'SRD': [undefined, '$'],
|
823 | 'SSP': [undefined, '£'],
|
824 | 'STD': [undefined, undefined, 0],
|
825 | 'STN': [undefined, 'Db'],
|
826 | 'SYP': [undefined, '£', 0],
|
827 | 'THB': [undefined, '฿'],
|
828 | 'TMM': [undefined, undefined, 0],
|
829 | 'TND': [undefined, undefined, 3],
|
830 | 'TOP': [undefined, 'T$'],
|
831 | 'TRL': [undefined, undefined, 0],
|
832 | 'TRY': [undefined, '₺'],
|
833 | 'TTD': [undefined, '$'],
|
834 | 'TWD': ['NT$', '$', 2],
|
835 | 'TZS': [undefined, undefined, 2],
|
836 | 'UAH': [undefined, '₴'],
|
837 | 'UGX': [undefined, undefined, 0],
|
838 | 'USD': ['$'],
|
839 | 'UYI': [undefined, undefined, 0],
|
840 | 'UYU': [undefined, '$'],
|
841 | 'UYW': [undefined, undefined, 4],
|
842 | 'UZS': [undefined, undefined, 2],
|
843 | 'VEF': [undefined, 'Bs', 2],
|
844 | 'VND': ['₫', undefined, 0],
|
845 | 'VUV': [undefined, undefined, 0],
|
846 | 'XAF': ['FCFA', undefined, 0],
|
847 | 'XCD': ['EC$', '$'],
|
848 | 'XOF': ['CFA', undefined, 0],
|
849 | 'XPF': ['CFPF', undefined, 0],
|
850 | 'XXX': ['¤'],
|
851 | 'YER': [undefined, undefined, 0],
|
852 | 'ZAR': [undefined, 'R'],
|
853 | 'ZMK': [undefined, undefined, 0],
|
854 | 'ZMW': [undefined, 'ZK'],
|
855 | 'ZWD': [undefined, undefined, 0]
|
856 | };
|
857 |
|
858 | /**
|
859 | * @license
|
860 | * Copyright Google Inc. All Rights Reserved.
|
861 | *
|
862 | * Use of this source code is governed by an MIT-style license that can be
|
863 | * found in the LICENSE file at https://angular.io/license
|
864 | */
|
865 | /**
|
866 | * Format styles that can be used to represent numbers.
|
867 | * @see `getLocaleNumberFormat()`.
|
868 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
869 | *
|
870 | * @publicApi
|
871 | */
|
872 | var NumberFormatStyle;
|
873 | (function (NumberFormatStyle) {
|
874 | NumberFormatStyle[NumberFormatStyle["Decimal"] = 0] = "Decimal";
|
875 | NumberFormatStyle[NumberFormatStyle["Percent"] = 1] = "Percent";
|
876 | NumberFormatStyle[NumberFormatStyle["Currency"] = 2] = "Currency";
|
877 | NumberFormatStyle[NumberFormatStyle["Scientific"] = 3] = "Scientific";
|
878 | })(NumberFormatStyle || (NumberFormatStyle = {}));
|
879 | /**
|
880 | * Plurality cases used for translating plurals to different languages.
|
881 | *
|
882 | * @see `NgPlural`
|
883 | * @see `NgPluralCase`
|
884 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
885 | *
|
886 | * @publicApi
|
887 | */
|
888 | var Plural;
|
889 | (function (Plural) {
|
890 | Plural[Plural["Zero"] = 0] = "Zero";
|
891 | Plural[Plural["One"] = 1] = "One";
|
892 | Plural[Plural["Two"] = 2] = "Two";
|
893 | Plural[Plural["Few"] = 3] = "Few";
|
894 | Plural[Plural["Many"] = 4] = "Many";
|
895 | Plural[Plural["Other"] = 5] = "Other";
|
896 | })(Plural || (Plural = {}));
|
897 | /**
|
898 | * Context-dependant translation forms for strings.
|
899 | * Typically the standalone version is for the nominative form of the word,
|
900 | * and the format version is used for the genitive case.
|
901 | * @see [CLDR website](http://cldr.unicode.org/translation/date-time#TOC-Stand-Alone-vs.-Format-Styles)
|
902 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
903 | *
|
904 | * @publicApi
|
905 | */
|
906 | var FormStyle;
|
907 | (function (FormStyle) {
|
908 | FormStyle[FormStyle["Format"] = 0] = "Format";
|
909 | FormStyle[FormStyle["Standalone"] = 1] = "Standalone";
|
910 | })(FormStyle || (FormStyle = {}));
|
911 | /**
|
912 | * String widths available for translations.
|
913 | * The specific character widths are locale-specific.
|
914 | * Examples are given for the word "Sunday" in English.
|
915 | *
|
916 | * @publicApi
|
917 | */
|
918 | var TranslationWidth;
|
919 | (function (TranslationWidth) {
|
920 | /** 1 character for `en-US`. For example: 'S' */
|
921 | TranslationWidth[TranslationWidth["Narrow"] = 0] = "Narrow";
|
922 | /** 3 characters for `en-US`. For example: 'Sun' */
|
923 | TranslationWidth[TranslationWidth["Abbreviated"] = 1] = "Abbreviated";
|
924 | /** Full length for `en-US`. For example: "Sunday" */
|
925 | TranslationWidth[TranslationWidth["Wide"] = 2] = "Wide";
|
926 | /** 2 characters for `en-US`, For example: "Su" */
|
927 | TranslationWidth[TranslationWidth["Short"] = 3] = "Short";
|
928 | })(TranslationWidth || (TranslationWidth = {}));
|
929 | /**
|
930 | * String widths available for date-time formats.
|
931 | * The specific character widths are locale-specific.
|
932 | * Examples are given for `en-US`.
|
933 | *
|
934 | * @see `getLocaleDateFormat()`
|
935 | * @see `getLocaleTimeFormat()``
|
936 | * @see `getLocaleDateTimeFormat()`
|
937 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
938 | * @publicApi
|
939 | */
|
940 | var FormatWidth;
|
941 | (function (FormatWidth) {
|
942 | /**
|
943 | * For `en-US`, 'M/d/yy, h:mm a'`
|
944 | * (Example: `6/15/15, 9:03 AM`)
|
945 | */
|
946 | FormatWidth[FormatWidth["Short"] = 0] = "Short";
|
947 | /**
|
948 | * For `en-US`, `'MMM d, y, h:mm:ss a'`
|
949 | * (Example: `Jun 15, 2015, 9:03:01 AM`)
|
950 | */
|
951 | FormatWidth[FormatWidth["Medium"] = 1] = "Medium";
|
952 | /**
|
953 | * For `en-US`, `'MMMM d, y, h:mm:ss a z'`
|
954 | * (Example: `June 15, 2015 at 9:03:01 AM GMT+1`)
|
955 | */
|
956 | FormatWidth[FormatWidth["Long"] = 2] = "Long";
|
957 | /**
|
958 | * For `en-US`, `'EEEE, MMMM d, y, h:mm:ss a zzzz'`
|
959 | * (Example: `Monday, June 15, 2015 at 9:03:01 AM GMT+01:00`)
|
960 | */
|
961 | FormatWidth[FormatWidth["Full"] = 3] = "Full";
|
962 | })(FormatWidth || (FormatWidth = {}));
|
963 | /**
|
964 | * Symbols that can be used to replace placeholders in number patterns.
|
965 | * Examples are based on `en-US` values.
|
966 | *
|
967 | * @see `getLocaleNumberSymbol()`
|
968 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
969 | *
|
970 | * @publicApi
|
971 | */
|
972 | var NumberSymbol;
|
973 | (function (NumberSymbol) {
|
974 | /**
|
975 | * Decimal separator.
|
976 | * For `en-US`, the dot character.
|
977 | * Example : 2,345`.`67
|
978 | */
|
979 | NumberSymbol[NumberSymbol["Decimal"] = 0] = "Decimal";
|
980 | /**
|
981 | * Grouping separator, typically for thousands.
|
982 | * For `en-US`, the comma character.
|
983 | * Example: 2`,`345.67
|
984 | */
|
985 | NumberSymbol[NumberSymbol["Group"] = 1] = "Group";
|
986 | /**
|
987 | * List-item separator.
|
988 | * Example: "one, two, and three"
|
989 | */
|
990 | NumberSymbol[NumberSymbol["List"] = 2] = "List";
|
991 | /**
|
992 | * Sign for percentage (out of 100).
|
993 | * Example: 23.4%
|
994 | */
|
995 | NumberSymbol[NumberSymbol["PercentSign"] = 3] = "PercentSign";
|
996 | /**
|
997 | * Sign for positive numbers.
|
998 | * Example: +23
|
999 | */
|
1000 | NumberSymbol[NumberSymbol["PlusSign"] = 4] = "PlusSign";
|
1001 | /**
|
1002 | * Sign for negative numbers.
|
1003 | * Example: -23
|
1004 | */
|
1005 | NumberSymbol[NumberSymbol["MinusSign"] = 5] = "MinusSign";
|
1006 | /**
|
1007 | * Computer notation for exponential value (n times a power of 10).
|
1008 | * Example: 1.2E3
|
1009 | */
|
1010 | NumberSymbol[NumberSymbol["Exponential"] = 6] = "Exponential";
|
1011 | /**
|
1012 | * Human-readable format of exponential.
|
1013 | * Example: 1.2x103
|
1014 | */
|
1015 | NumberSymbol[NumberSymbol["SuperscriptingExponent"] = 7] = "SuperscriptingExponent";
|
1016 | /**
|
1017 | * Sign for permille (out of 1000).
|
1018 | * Example: 23.4‰
|
1019 | */
|
1020 | NumberSymbol[NumberSymbol["PerMille"] = 8] = "PerMille";
|
1021 | /**
|
1022 | * Infinity, can be used with plus and minus.
|
1023 | * Example: ∞, +∞, -∞
|
1024 | */
|
1025 | NumberSymbol[NumberSymbol["Infinity"] = 9] = "Infinity";
|
1026 | /**
|
1027 | * Not a number.
|
1028 | * Example: NaN
|
1029 | */
|
1030 | NumberSymbol[NumberSymbol["NaN"] = 10] = "NaN";
|
1031 | /**
|
1032 | * Symbol used between time units.
|
1033 | * Example: 10:52
|
1034 | */
|
1035 | NumberSymbol[NumberSymbol["TimeSeparator"] = 11] = "TimeSeparator";
|
1036 | /**
|
1037 | * Decimal separator for currency values (fallback to `Decimal`).
|
1038 | * Example: $2,345.67
|
1039 | */
|
1040 | NumberSymbol[NumberSymbol["CurrencyDecimal"] = 12] = "CurrencyDecimal";
|
1041 | /**
|
1042 | * Group separator for currency values (fallback to `Group`).
|
1043 | * Example: $2,345.67
|
1044 | */
|
1045 | NumberSymbol[NumberSymbol["CurrencyGroup"] = 13] = "CurrencyGroup";
|
1046 | })(NumberSymbol || (NumberSymbol = {}));
|
1047 | /**
|
1048 | * The value for each day of the week, based on the `en-US` locale
|
1049 | *
|
1050 | * @publicApi
|
1051 | */
|
1052 | var WeekDay;
|
1053 | (function (WeekDay) {
|
1054 | WeekDay[WeekDay["Sunday"] = 0] = "Sunday";
|
1055 | WeekDay[WeekDay["Monday"] = 1] = "Monday";
|
1056 | WeekDay[WeekDay["Tuesday"] = 2] = "Tuesday";
|
1057 | WeekDay[WeekDay["Wednesday"] = 3] = "Wednesday";
|
1058 | WeekDay[WeekDay["Thursday"] = 4] = "Thursday";
|
1059 | WeekDay[WeekDay["Friday"] = 5] = "Friday";
|
1060 | WeekDay[WeekDay["Saturday"] = 6] = "Saturday";
|
1061 | })(WeekDay || (WeekDay = {}));
|
1062 | /**
|
1063 | * Retrieves the locale ID from the currently loaded locale.
|
1064 | * The loaded locale could be, for example, a global one rather than a regional one.
|
1065 | * @param locale A locale code, such as `fr-FR`.
|
1066 | * @returns The locale code. For example, `fr`.
|
1067 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1068 | *
|
1069 | * @publicApi
|
1070 | */
|
1071 | function getLocaleId(locale) {
|
1072 | return ɵfindLocaleData(locale)[ɵLocaleDataIndex.LocaleId];
|
1073 | }
|
1074 | /**
|
1075 | * Retrieves day period strings for the given locale.
|
1076 | *
|
1077 | * @param locale A locale code for the locale format rules to use.
|
1078 | * @param formStyle The required grammatical form.
|
1079 | * @param width The required character width.
|
1080 | * @returns An array of localized period strings. For example, `[AM, PM]` for `en-US`.
|
1081 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1082 | *
|
1083 | * @publicApi
|
1084 | */
|
1085 | function getLocaleDayPeriods(locale, formStyle, width) {
|
1086 | var data = ɵfindLocaleData(locale);
|
1087 | var amPmData = [data[ɵLocaleDataIndex.DayPeriodsFormat], data[ɵLocaleDataIndex.DayPeriodsStandalone]];
|
1088 | var amPm = getLastDefinedValue(amPmData, formStyle);
|
1089 | return getLastDefinedValue(amPm, width);
|
1090 | }
|
1091 | /**
|
1092 | * Retrieves days of the week for the given locale, using the Gregorian calendar.
|
1093 | *
|
1094 | * @param locale A locale code for the locale format rules to use.
|
1095 | * @param formStyle The required grammatical form.
|
1096 | * @param width The required character width.
|
1097 | * @returns An array of localized name strings.
|
1098 | * For example,`[Sunday, Monday, ... Saturday]` for `en-US`.
|
1099 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1100 | *
|
1101 | * @publicApi
|
1102 | */
|
1103 | function getLocaleDayNames(locale, formStyle, width) {
|
1104 | var data = ɵfindLocaleData(locale);
|
1105 | var daysData = [data[ɵLocaleDataIndex.DaysFormat], data[ɵLocaleDataIndex.DaysStandalone]];
|
1106 | var days = getLastDefinedValue(daysData, formStyle);
|
1107 | return getLastDefinedValue(days, width);
|
1108 | }
|
1109 | /**
|
1110 | * Retrieves months of the year for the given locale, using the Gregorian calendar.
|
1111 | *
|
1112 | * @param locale A locale code for the locale format rules to use.
|
1113 | * @param formStyle The required grammatical form.
|
1114 | * @param width The required character width.
|
1115 | * @returns An array of localized name strings.
|
1116 | * For example, `[January, February, ...]` for `en-US`.
|
1117 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1118 | *
|
1119 | * @publicApi
|
1120 | */
|
1121 | function getLocaleMonthNames(locale, formStyle, width) {
|
1122 | var data = ɵfindLocaleData(locale);
|
1123 | var monthsData = [data[ɵLocaleDataIndex.MonthsFormat], data[ɵLocaleDataIndex.MonthsStandalone]];
|
1124 | var months = getLastDefinedValue(monthsData, formStyle);
|
1125 | return getLastDefinedValue(months, width);
|
1126 | }
|
1127 | /**
|
1128 | * Retrieves Gregorian-calendar eras for the given locale.
|
1129 | * @param locale A locale code for the locale format rules to use.
|
1130 | * @param formStyle The required grammatical form.
|
1131 | * @param width The required character width.
|
1132 |
|
1133 | * @returns An array of localized era strings.
|
1134 | * For example, `[AD, BC]` for `en-US`.
|
1135 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1136 | *
|
1137 | * @publicApi
|
1138 | */
|
1139 | function getLocaleEraNames(locale, width) {
|
1140 | var data = ɵfindLocaleData(locale);
|
1141 | var erasData = data[ɵLocaleDataIndex.Eras];
|
1142 | return getLastDefinedValue(erasData, width);
|
1143 | }
|
1144 | /**
|
1145 | * Retrieves the first day of the week for the given locale.
|
1146 | *
|
1147 | * @param locale A locale code for the locale format rules to use.
|
1148 | * @returns A day index number, using the 0-based week-day index for `en-US`
|
1149 | * (Sunday = 0, Monday = 1, ...).
|
1150 | * For example, for `fr-FR`, returns 1 to indicate that the first day is Monday.
|
1151 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1152 | *
|
1153 | * @publicApi
|
1154 | */
|
1155 | function getLocaleFirstDayOfWeek(locale) {
|
1156 | var data = ɵfindLocaleData(locale);
|
1157 | return data[ɵLocaleDataIndex.FirstDayOfWeek];
|
1158 | }
|
1159 | /**
|
1160 | * Range of week days that are considered the week-end for the given locale.
|
1161 | *
|
1162 | * @param locale A locale code for the locale format rules to use.
|
1163 | * @returns The range of day values, `[startDay, endDay]`.
|
1164 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1165 | *
|
1166 | * @publicApi
|
1167 | */
|
1168 | function getLocaleWeekEndRange(locale) {
|
1169 | var data = ɵfindLocaleData(locale);
|
1170 | return data[ɵLocaleDataIndex.WeekendRange];
|
1171 | }
|
1172 | /**
|
1173 | * Retrieves a localized date-value formating string.
|
1174 | *
|
1175 | * @param locale A locale code for the locale format rules to use.
|
1176 | * @param width The format type.
|
1177 | * @returns The localized formating string.
|
1178 | * @see `FormatWidth`
|
1179 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1180 | *
|
1181 | * @publicApi
|
1182 | */
|
1183 | function getLocaleDateFormat(locale, width) {
|
1184 | var data = ɵfindLocaleData(locale);
|
1185 | return getLastDefinedValue(data[ɵLocaleDataIndex.DateFormat], width);
|
1186 | }
|
1187 | /**
|
1188 | * Retrieves a localized time-value formatting string.
|
1189 | *
|
1190 | * @param locale A locale code for the locale format rules to use.
|
1191 | * @param width The format type.
|
1192 | * @returns The localized formatting string.
|
1193 | * @see `FormatWidth`
|
1194 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1195 |
|
1196 | * @publicApi
|
1197 | */
|
1198 | function getLocaleTimeFormat(locale, width) {
|
1199 | var data = ɵfindLocaleData(locale);
|
1200 | return getLastDefinedValue(data[ɵLocaleDataIndex.TimeFormat], width);
|
1201 | }
|
1202 | /**
|
1203 | * Retrieves a localized date-time formatting string.
|
1204 | *
|
1205 | * @param locale A locale code for the locale format rules to use.
|
1206 | * @param width The format type.
|
1207 | * @returns The localized formatting string.
|
1208 | * @see `FormatWidth`
|
1209 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1210 | *
|
1211 | * @publicApi
|
1212 | */
|
1213 | function getLocaleDateTimeFormat(locale, width) {
|
1214 | var data = ɵfindLocaleData(locale);
|
1215 | var dateTimeFormatData = data[ɵLocaleDataIndex.DateTimeFormat];
|
1216 | return getLastDefinedValue(dateTimeFormatData, width);
|
1217 | }
|
1218 | /**
|
1219 | * Retrieves a localized number symbol that can be used to replace placeholders in number formats.
|
1220 | * @param locale The locale code.
|
1221 | * @param symbol The symbol to localize.
|
1222 | * @returns The character for the localized symbol.
|
1223 | * @see `NumberSymbol`
|
1224 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1225 | *
|
1226 | * @publicApi
|
1227 | */
|
1228 | function getLocaleNumberSymbol(locale, symbol) {
|
1229 | var data = ɵfindLocaleData(locale);
|
1230 | var res = data[ɵLocaleDataIndex.NumberSymbols][symbol];
|
1231 | if (typeof res === 'undefined') {
|
1232 | if (symbol === NumberSymbol.CurrencyDecimal) {
|
1233 | return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Decimal];
|
1234 | }
|
1235 | else if (symbol === NumberSymbol.CurrencyGroup) {
|
1236 | return data[ɵLocaleDataIndex.NumberSymbols][NumberSymbol.Group];
|
1237 | }
|
1238 | }
|
1239 | return res;
|
1240 | }
|
1241 | /**
|
1242 | * Retrieves a number format for a given locale.
|
1243 | *
|
1244 | * Numbers are formatted using patterns, like `#,###.00`. For example, the pattern `#,###.00`
|
1245 | * when used to format the number 12345.678 could result in "12'345,678". That would happen if the
|
1246 | * grouping separator for your language is an apostrophe, and the decimal separator is a comma.
|
1247 | *
|
1248 | * <b>Important:</b> The characters `.` `,` `0` `#` (and others below) are special placeholders
|
1249 | * that stand for the decimal separator, and so on, and are NOT real characters.
|
1250 | * You must NOT "translate" the placeholders. For example, don't change `.` to `,` even though in
|
1251 | * your language the decimal point is written with a comma. The symbols should be replaced by the
|
1252 | * local equivalents, using the appropriate `NumberSymbol` for your language.
|
1253 | *
|
1254 | * Here are the special characters used in number patterns:
|
1255 | *
|
1256 | * | Symbol | Meaning |
|
1257 | * |--------|---------|
|
1258 | * | . | Replaced automatically by the character used for the decimal point. |
|
1259 | * | , | Replaced by the "grouping" (thousands) separator. |
|
1260 | * | 0 | Replaced by a digit (or zero if there aren't enough digits). |
|
1261 | * | # | Replaced by a digit (or nothing if there aren't enough). |
|
1262 | * | ¤ | Replaced by a currency symbol, such as $ or USD. |
|
1263 | * | % | Marks a percent format. The % symbol may change position, but must be retained. |
|
1264 | * | E | Marks a scientific format. The E symbol may change position, but must be retained. |
|
1265 | * | ' | Special characters used as literal characters are quoted with ASCII single quotes. |
|
1266 | *
|
1267 | * @param locale A locale code for the locale format rules to use.
|
1268 | * @param type The type of numeric value to be formatted (such as `Decimal` or `Currency`.)
|
1269 | * @returns The localized format string.
|
1270 | * @see `NumberFormatStyle`
|
1271 | * @see [CLDR website](http://cldr.unicode.org/translation/number-patterns)
|
1272 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1273 | *
|
1274 | * @publicApi
|
1275 | */
|
1276 | function getLocaleNumberFormat(locale, type) {
|
1277 | var data = ɵfindLocaleData(locale);
|
1278 | return data[ɵLocaleDataIndex.NumberFormats][type];
|
1279 | }
|
1280 | /**
|
1281 | * Retrieves the symbol used to represent the currency for the main country
|
1282 | * corresponding to a given locale. For example, '$' for `en-US`.
|
1283 | *
|
1284 | * @param locale A locale code for the locale format rules to use.
|
1285 | * @returns The localized symbol character,
|
1286 | * or `null` if the main country cannot be determined.
|
1287 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1288 | *
|
1289 | * @publicApi
|
1290 | */
|
1291 | function getLocaleCurrencySymbol(locale) {
|
1292 | var data = ɵfindLocaleData(locale);
|
1293 | return data[ɵLocaleDataIndex.CurrencySymbol] || null;
|
1294 | }
|
1295 | /**
|
1296 | * Retrieves the name of the currency for the main country corresponding
|
1297 | * to a given locale. For example, 'US Dollar' for `en-US`.
|
1298 | * @param locale A locale code for the locale format rules to use.
|
1299 | * @returns The currency name,
|
1300 | * or `null` if the main country cannot be determined.
|
1301 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1302 | *
|
1303 | * @publicApi
|
1304 | */
|
1305 | function getLocaleCurrencyName(locale) {
|
1306 | var data = ɵfindLocaleData(locale);
|
1307 | return data[ɵLocaleDataIndex.CurrencyName] || null;
|
1308 | }
|
1309 | /**
|
1310 | * Retrieves the default currency code for the given locale.
|
1311 | *
|
1312 | * The default is defined as the first currency which is still in use.
|
1313 | *
|
1314 | * @param locale The code of the locale whose currency code we want.
|
1315 | * @returns The code of the default currency for the given locale.
|
1316 | *
|
1317 | * @publicApi
|
1318 | */
|
1319 | function getLocaleCurrencyCode(locale) {
|
1320 | return ɵgetLocaleCurrencyCode(locale);
|
1321 | }
|
1322 | /**
|
1323 | * Retrieves the currency values for a given locale.
|
1324 | * @param locale A locale code for the locale format rules to use.
|
1325 | * @returns The currency values.
|
1326 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1327 | */
|
1328 | function getLocaleCurrencies(locale) {
|
1329 | var data = ɵfindLocaleData(locale);
|
1330 | return data[ɵLocaleDataIndex.Currencies];
|
1331 | }
|
1332 | /**
|
1333 | * @alias core/ɵgetLocalePluralCase
|
1334 | * @publicApi
|
1335 | */
|
1336 | var getLocalePluralCase = ɵgetLocalePluralCase;
|
1337 | function checkFullData(data) {
|
1338 | if (!data[ɵLocaleDataIndex.ExtraData]) {
|
1339 | throw new Error("Missing extra locale data for the locale \"" + data[ɵLocaleDataIndex.LocaleId] + "\". Use \"registerLocaleData\" to load new data. See the \"I18n guide\" on angular.io to know more.");
|
1340 | }
|
1341 | }
|
1342 | /**
|
1343 | * Retrieves locale-specific rules used to determine which day period to use
|
1344 | * when more than one period is defined for a locale.
|
1345 | *
|
1346 | * There is a rule for each defined day period. The
|
1347 | * first rule is applied to the first day period and so on.
|
1348 | * Fall back to AM/PM when no rules are available.
|
1349 | *
|
1350 | * A rule can specify a period as time range, or as a single time value.
|
1351 | *
|
1352 | * This functionality is only available when you have loaded the full locale data.
|
1353 | * See the ["I18n guide"](guide/i18n#i18n-pipes).
|
1354 | *
|
1355 | * @param locale A locale code for the locale format rules to use.
|
1356 | * @returns The rules for the locale, a single time value or array of *from-time, to-time*,
|
1357 | * or null if no periods are available.
|
1358 | *
|
1359 | * @see `getLocaleExtraDayPeriods()`
|
1360 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1361 | *
|
1362 | * @publicApi
|
1363 | */
|
1364 | function getLocaleExtraDayPeriodRules(locale) {
|
1365 | var data = ɵfindLocaleData(locale);
|
1366 | checkFullData(data);
|
1367 | var rules = data[ɵLocaleDataIndex.ExtraData][2 /* ExtraDayPeriodsRules */] || [];
|
1368 | return rules.map(function (rule) {
|
1369 | if (typeof rule === 'string') {
|
1370 | return extractTime(rule);
|
1371 | }
|
1372 | return [extractTime(rule[0]), extractTime(rule[1])];
|
1373 | });
|
1374 | }
|
1375 | /**
|
1376 | * Retrieves locale-specific day periods, which indicate roughly how a day is broken up
|
1377 | * in different languages.
|
1378 | * For example, for `en-US`, periods are morning, noon, afternoon, evening, and midnight.
|
1379 | *
|
1380 | * This functionality is only available when you have loaded the full locale data.
|
1381 | * See the ["I18n guide"](guide/i18n#i18n-pipes).
|
1382 | *
|
1383 | * @param locale A locale code for the locale format rules to use.
|
1384 | * @param formStyle The required grammatical form.
|
1385 | * @param width The required character width.
|
1386 | * @returns The translated day-period strings.
|
1387 | * @see `getLocaleExtraDayPeriodRules()`
|
1388 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1389 | *
|
1390 | * @publicApi
|
1391 | */
|
1392 | function getLocaleExtraDayPeriods(locale, formStyle, width) {
|
1393 | var data = ɵfindLocaleData(locale);
|
1394 | checkFullData(data);
|
1395 | var dayPeriodsData = [
|
1396 | data[ɵLocaleDataIndex.ExtraData][0 /* ExtraDayPeriodFormats */],
|
1397 | data[ɵLocaleDataIndex.ExtraData][1 /* ExtraDayPeriodStandalone */]
|
1398 | ];
|
1399 | var dayPeriods = getLastDefinedValue(dayPeriodsData, formStyle) || [];
|
1400 | return getLastDefinedValue(dayPeriods, width) || [];
|
1401 | }
|
1402 | /**
|
1403 | * Retrieves the first value that is defined in an array, going backwards from an index position.
|
1404 | *
|
1405 | * To avoid repeating the same data (as when the "format" and "standalone" forms are the same)
|
1406 | * add the first value to the locale data arrays, and add other values only if they are different.
|
1407 | *
|
1408 | * @param data The data array to retrieve from.
|
1409 | * @param index A 0-based index into the array to start from.
|
1410 | * @returns The value immediately before the given index position.
|
1411 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1412 | *
|
1413 | * @publicApi
|
1414 | */
|
1415 | function getLastDefinedValue(data, index) {
|
1416 | for (var i = index; i > -1; i--) {
|
1417 | if (typeof data[i] !== 'undefined') {
|
1418 | return data[i];
|
1419 | }
|
1420 | }
|
1421 | throw new Error('Locale data API: locale data undefined');
|
1422 | }
|
1423 | /**
|
1424 | * Extracts the hours and minutes from a string like "15:45"
|
1425 | */
|
1426 | function extractTime(time) {
|
1427 | var _a = __read(time.split(':'), 2), h = _a[0], m = _a[1];
|
1428 | return { hours: +h, minutes: +m };
|
1429 | }
|
1430 | /**
|
1431 | * Retrieves the currency symbol for a given currency code.
|
1432 | *
|
1433 | * For example, for the default `en-US` locale, the code `USD` can
|
1434 | * be represented by the narrow symbol `$` or the wide symbol `US$`.
|
1435 | *
|
1436 | * @param code The currency code.
|
1437 | * @param format The format, `wide` or `narrow`.
|
1438 | * @param locale A locale code for the locale format rules to use.
|
1439 | *
|
1440 | * @returns The symbol, or the currency code if no symbol is available.
|
1441 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1442 | *
|
1443 | * @publicApi
|
1444 | */
|
1445 | function getCurrencySymbol(code, format, locale) {
|
1446 | if (locale === void 0) { locale = 'en'; }
|
1447 | var currency = getLocaleCurrencies(locale)[code] || CURRENCIES_EN[code] || [];
|
1448 | var symbolNarrow = currency[1 /* SymbolNarrow */];
|
1449 | if (format === 'narrow' && typeof symbolNarrow === 'string') {
|
1450 | return symbolNarrow;
|
1451 | }
|
1452 | return currency[0 /* Symbol */] || code;
|
1453 | }
|
1454 | // Most currencies have cents, that's why the default is 2
|
1455 | var DEFAULT_NB_OF_CURRENCY_DIGITS = 2;
|
1456 | /**
|
1457 | * Reports the number of decimal digits for a given currency.
|
1458 | * The value depends upon the presence of cents in that particular currency.
|
1459 | *
|
1460 | * @param code The currency code.
|
1461 | * @returns The number of decimal digits, typically 0 or 2.
|
1462 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1463 | *
|
1464 | * @publicApi
|
1465 | */
|
1466 | function getNumberOfCurrencyDigits(code) {
|
1467 | var digits;
|
1468 | var currency = CURRENCIES_EN[code];
|
1469 | if (currency) {
|
1470 | digits = currency[2 /* NbOfDigits */];
|
1471 | }
|
1472 | return typeof digits === 'number' ? digits : DEFAULT_NB_OF_CURRENCY_DIGITS;
|
1473 | }
|
1474 |
|
1475 | /**
|
1476 | * @license
|
1477 | * Copyright Google Inc. All Rights Reserved.
|
1478 | *
|
1479 | * Use of this source code is governed by an MIT-style license that can be
|
1480 | * found in the LICENSE file at https://angular.io/license
|
1481 | */
|
1482 | var ISO8601_DATE_REGEX = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
|
1483 | // 1 2 3 4 5 6 7 8 9 10 11
|
1484 | var NAMED_FORMATS = {};
|
1485 | var DATE_FORMATS_SPLIT = /((?:[^GyMLwWdEabBhHmsSzZO']+)|(?:'(?:[^']|'')*')|(?:G{1,5}|y{1,4}|M{1,5}|L{1,5}|w{1,2}|W{1}|d{1,2}|E{1,6}|a{1,5}|b{1,5}|B{1,5}|h{1,2}|H{1,2}|m{1,2}|s{1,2}|S{1,3}|z{1,4}|Z{1,5}|O{1,4}))([\s\S]*)/;
|
1486 | var ZoneWidth;
|
1487 | (function (ZoneWidth) {
|
1488 | ZoneWidth[ZoneWidth["Short"] = 0] = "Short";
|
1489 | ZoneWidth[ZoneWidth["ShortGMT"] = 1] = "ShortGMT";
|
1490 | ZoneWidth[ZoneWidth["Long"] = 2] = "Long";
|
1491 | ZoneWidth[ZoneWidth["Extended"] = 3] = "Extended";
|
1492 | })(ZoneWidth || (ZoneWidth = {}));
|
1493 | var DateType;
|
1494 | (function (DateType) {
|
1495 | DateType[DateType["FullYear"] = 0] = "FullYear";
|
1496 | DateType[DateType["Month"] = 1] = "Month";
|
1497 | DateType[DateType["Date"] = 2] = "Date";
|
1498 | DateType[DateType["Hours"] = 3] = "Hours";
|
1499 | DateType[DateType["Minutes"] = 4] = "Minutes";
|
1500 | DateType[DateType["Seconds"] = 5] = "Seconds";
|
1501 | DateType[DateType["FractionalSeconds"] = 6] = "FractionalSeconds";
|
1502 | DateType[DateType["Day"] = 7] = "Day";
|
1503 | })(DateType || (DateType = {}));
|
1504 | var TranslationType;
|
1505 | (function (TranslationType) {
|
1506 | TranslationType[TranslationType["DayPeriods"] = 0] = "DayPeriods";
|
1507 | TranslationType[TranslationType["Days"] = 1] = "Days";
|
1508 | TranslationType[TranslationType["Months"] = 2] = "Months";
|
1509 | TranslationType[TranslationType["Eras"] = 3] = "Eras";
|
1510 | })(TranslationType || (TranslationType = {}));
|
1511 | /**
|
1512 | * @ngModule CommonModule
|
1513 | * @description
|
1514 | *
|
1515 | * Formats a date according to locale rules.
|
1516 | *
|
1517 | * @param value The date to format, as a Date, or a number (milliseconds since UTC epoch)
|
1518 | * or an [ISO date-time string](https://www.w3.org/TR/NOTE-datetime).
|
1519 | * @param format The date-time components to include. See `DatePipe` for details.
|
1520 | * @param locale A locale code for the locale format rules to use.
|
1521 | * @param timezone The time zone. A time zone offset from GMT (such as `'+0430'`),
|
1522 | * or a standard UTC/GMT or continental US time zone abbreviation.
|
1523 | * If not specified, uses host system settings.
|
1524 | *
|
1525 | * @returns The formatted date string.
|
1526 | *
|
1527 | * @see `DatePipe`
|
1528 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
1529 | *
|
1530 | * @publicApi
|
1531 | */
|
1532 | function formatDate(value, format, locale, timezone) {
|
1533 | var date = toDate(value);
|
1534 | var namedFormat = getNamedFormat(locale, format);
|
1535 | format = namedFormat || format;
|
1536 | var parts = [];
|
1537 | var match;
|
1538 | while (format) {
|
1539 | match = DATE_FORMATS_SPLIT.exec(format);
|
1540 | if (match) {
|
1541 | parts = parts.concat(match.slice(1));
|
1542 | var part = parts.pop();
|
1543 | if (!part) {
|
1544 | break;
|
1545 | }
|
1546 | format = part;
|
1547 | }
|
1548 | else {
|
1549 | parts.push(format);
|
1550 | break;
|
1551 | }
|
1552 | }
|
1553 | var dateTimezoneOffset = date.getTimezoneOffset();
|
1554 | if (timezone) {
|
1555 | dateTimezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
1556 | date = convertTimezoneToLocal(date, timezone, true);
|
1557 | }
|
1558 | var text = '';
|
1559 | parts.forEach(function (value) {
|
1560 | var dateFormatter = getDateFormatter(value);
|
1561 | text += dateFormatter ?
|
1562 | dateFormatter(date, locale, dateTimezoneOffset) :
|
1563 | value === '\'\'' ? '\'' : value.replace(/(^'|'$)/g, '').replace(/''/g, '\'');
|
1564 | });
|
1565 | return text;
|
1566 | }
|
1567 | function getNamedFormat(locale, format) {
|
1568 | var localeId = getLocaleId(locale);
|
1569 | NAMED_FORMATS[localeId] = NAMED_FORMATS[localeId] || {};
|
1570 | if (NAMED_FORMATS[localeId][format]) {
|
1571 | return NAMED_FORMATS[localeId][format];
|
1572 | }
|
1573 | var formatValue = '';
|
1574 | switch (format) {
|
1575 | case 'shortDate':
|
1576 | formatValue = getLocaleDateFormat(locale, FormatWidth.Short);
|
1577 | break;
|
1578 | case 'mediumDate':
|
1579 | formatValue = getLocaleDateFormat(locale, FormatWidth.Medium);
|
1580 | break;
|
1581 | case 'longDate':
|
1582 | formatValue = getLocaleDateFormat(locale, FormatWidth.Long);
|
1583 | break;
|
1584 | case 'fullDate':
|
1585 | formatValue = getLocaleDateFormat(locale, FormatWidth.Full);
|
1586 | break;
|
1587 | case 'shortTime':
|
1588 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Short);
|
1589 | break;
|
1590 | case 'mediumTime':
|
1591 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Medium);
|
1592 | break;
|
1593 | case 'longTime':
|
1594 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Long);
|
1595 | break;
|
1596 | case 'fullTime':
|
1597 | formatValue = getLocaleTimeFormat(locale, FormatWidth.Full);
|
1598 | break;
|
1599 | case 'short':
|
1600 | var shortTime = getNamedFormat(locale, 'shortTime');
|
1601 | var shortDate = getNamedFormat(locale, 'shortDate');
|
1602 | formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Short), [shortTime, shortDate]);
|
1603 | break;
|
1604 | case 'medium':
|
1605 | var mediumTime = getNamedFormat(locale, 'mediumTime');
|
1606 | var mediumDate = getNamedFormat(locale, 'mediumDate');
|
1607 | formatValue = formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Medium), [mediumTime, mediumDate]);
|
1608 | break;
|
1609 | case 'long':
|
1610 | var longTime = getNamedFormat(locale, 'longTime');
|
1611 | var longDate = getNamedFormat(locale, 'longDate');
|
1612 | formatValue =
|
1613 | formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Long), [longTime, longDate]);
|
1614 | break;
|
1615 | case 'full':
|
1616 | var fullTime = getNamedFormat(locale, 'fullTime');
|
1617 | var fullDate = getNamedFormat(locale, 'fullDate');
|
1618 | formatValue =
|
1619 | formatDateTime(getLocaleDateTimeFormat(locale, FormatWidth.Full), [fullTime, fullDate]);
|
1620 | break;
|
1621 | }
|
1622 | if (formatValue) {
|
1623 | NAMED_FORMATS[localeId][format] = formatValue;
|
1624 | }
|
1625 | return formatValue;
|
1626 | }
|
1627 | function formatDateTime(str, opt_values) {
|
1628 | if (opt_values) {
|
1629 | str = str.replace(/\{([^}]+)}/g, function (match, key) {
|
1630 | return (opt_values != null && key in opt_values) ? opt_values[key] : match;
|
1631 | });
|
1632 | }
|
1633 | return str;
|
1634 | }
|
1635 | function padNumber(num, digits, minusSign, trim, negWrap) {
|
1636 | if (minusSign === void 0) { minusSign = '-'; }
|
1637 | var neg = '';
|
1638 | if (num < 0 || (negWrap && num <= 0)) {
|
1639 | if (negWrap) {
|
1640 | num = -num + 1;
|
1641 | }
|
1642 | else {
|
1643 | num = -num;
|
1644 | neg = minusSign;
|
1645 | }
|
1646 | }
|
1647 | var strNum = String(num);
|
1648 | while (strNum.length < digits) {
|
1649 | strNum = '0' + strNum;
|
1650 | }
|
1651 | if (trim) {
|
1652 | strNum = strNum.substr(strNum.length - digits);
|
1653 | }
|
1654 | return neg + strNum;
|
1655 | }
|
1656 | function formatFractionalSeconds(milliseconds, digits) {
|
1657 | var strMs = padNumber(milliseconds, 3);
|
1658 | return strMs.substr(0, digits);
|
1659 | }
|
1660 | /**
|
1661 | * Returns a date formatter that transforms a date into its locale digit representation
|
1662 | */
|
1663 | function dateGetter(name, size, offset, trim, negWrap) {
|
1664 | if (offset === void 0) { offset = 0; }
|
1665 | if (trim === void 0) { trim = false; }
|
1666 | if (negWrap === void 0) { negWrap = false; }
|
1667 | return function (date, locale) {
|
1668 | var part = getDatePart(name, date);
|
1669 | if (offset > 0 || part > -offset) {
|
1670 | part += offset;
|
1671 | }
|
1672 | if (name === DateType.Hours) {
|
1673 | if (part === 0 && offset === -12) {
|
1674 | part = 12;
|
1675 | }
|
1676 | }
|
1677 | else if (name === DateType.FractionalSeconds) {
|
1678 | return formatFractionalSeconds(part, size);
|
1679 | }
|
1680 | var localeMinus = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
|
1681 | return padNumber(part, size, localeMinus, trim, negWrap);
|
1682 | };
|
1683 | }
|
1684 | function getDatePart(part, date) {
|
1685 | switch (part) {
|
1686 | case DateType.FullYear:
|
1687 | return date.getFullYear();
|
1688 | case DateType.Month:
|
1689 | return date.getMonth();
|
1690 | case DateType.Date:
|
1691 | return date.getDate();
|
1692 | case DateType.Hours:
|
1693 | return date.getHours();
|
1694 | case DateType.Minutes:
|
1695 | return date.getMinutes();
|
1696 | case DateType.Seconds:
|
1697 | return date.getSeconds();
|
1698 | case DateType.FractionalSeconds:
|
1699 | return date.getMilliseconds();
|
1700 | case DateType.Day:
|
1701 | return date.getDay();
|
1702 | default:
|
1703 | throw new Error("Unknown DateType value \"" + part + "\".");
|
1704 | }
|
1705 | }
|
1706 | /**
|
1707 | * Returns a date formatter that transforms a date into its locale string representation
|
1708 | */
|
1709 | function dateStrGetter(name, width, form, extended) {
|
1710 | if (form === void 0) { form = FormStyle.Format; }
|
1711 | if (extended === void 0) { extended = false; }
|
1712 | return function (date, locale) {
|
1713 | return getDateTranslation(date, locale, name, width, form, extended);
|
1714 | };
|
1715 | }
|
1716 | /**
|
1717 | * Returns the locale translation of a date for a given form, type and width
|
1718 | */
|
1719 | function getDateTranslation(date, locale, name, width, form, extended) {
|
1720 | switch (name) {
|
1721 | case TranslationType.Months:
|
1722 | return getLocaleMonthNames(locale, form, width)[date.getMonth()];
|
1723 | case TranslationType.Days:
|
1724 | return getLocaleDayNames(locale, form, width)[date.getDay()];
|
1725 | case TranslationType.DayPeriods:
|
1726 | var currentHours_1 = date.getHours();
|
1727 | var currentMinutes_1 = date.getMinutes();
|
1728 | if (extended) {
|
1729 | var rules = getLocaleExtraDayPeriodRules(locale);
|
1730 | var dayPeriods_1 = getLocaleExtraDayPeriods(locale, form, width);
|
1731 | var result_1;
|
1732 | rules.forEach(function (rule, index) {
|
1733 | if (Array.isArray(rule)) {
|
1734 | // morning, afternoon, evening, night
|
1735 | var _a = rule[0], hoursFrom = _a.hours, minutesFrom = _a.minutes;
|
1736 | var _b = rule[1], hoursTo = _b.hours, minutesTo = _b.minutes;
|
1737 | if (currentHours_1 >= hoursFrom && currentMinutes_1 >= minutesFrom &&
|
1738 | (currentHours_1 < hoursTo ||
|
1739 | (currentHours_1 === hoursTo && currentMinutes_1 < minutesTo))) {
|
1740 | result_1 = dayPeriods_1[index];
|
1741 | }
|
1742 | }
|
1743 | else { // noon or midnight
|
1744 | var hours = rule.hours, minutes = rule.minutes;
|
1745 | if (hours === currentHours_1 && minutes === currentMinutes_1) {
|
1746 | result_1 = dayPeriods_1[index];
|
1747 | }
|
1748 | }
|
1749 | });
|
1750 | if (result_1) {
|
1751 | return result_1;
|
1752 | }
|
1753 | }
|
1754 | // if no rules for the day periods, we use am/pm by default
|
1755 | return getLocaleDayPeriods(locale, form, width)[currentHours_1 < 12 ? 0 : 1];
|
1756 | case TranslationType.Eras:
|
1757 | return getLocaleEraNames(locale, width)[date.getFullYear() <= 0 ? 0 : 1];
|
1758 | default:
|
1759 | // This default case is not needed by TypeScript compiler, as the switch is exhaustive.
|
1760 | // However Closure Compiler does not understand that and reports an error in typed mode.
|
1761 | // The `throw new Error` below works around the problem, and the unexpected: never variable
|
1762 | // makes sure tsc still checks this code is unreachable.
|
1763 | var unexpected = name;
|
1764 | throw new Error("unexpected translation type " + unexpected);
|
1765 | }
|
1766 | }
|
1767 | /**
|
1768 | * Returns a date formatter that transforms a date and an offset into a timezone with ISO8601 or
|
1769 | * GMT format depending on the width (eg: short = +0430, short:GMT = GMT+4, long = GMT+04:30,
|
1770 | * extended = +04:30)
|
1771 | */
|
1772 | function timeZoneGetter(width) {
|
1773 | return function (date, locale, offset) {
|
1774 | var zone = -1 * offset;
|
1775 | var minusSign = getLocaleNumberSymbol(locale, NumberSymbol.MinusSign);
|
1776 | var hours = zone > 0 ? Math.floor(zone / 60) : Math.ceil(zone / 60);
|
1777 | switch (width) {
|
1778 | case ZoneWidth.Short:
|
1779 | return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) +
|
1780 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
1781 | case ZoneWidth.ShortGMT:
|
1782 | return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 1, minusSign);
|
1783 | case ZoneWidth.Long:
|
1784 | return 'GMT' + ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
|
1785 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
1786 | case ZoneWidth.Extended:
|
1787 | if (offset === 0) {
|
1788 | return 'Z';
|
1789 | }
|
1790 | else {
|
1791 | return ((zone >= 0) ? '+' : '') + padNumber(hours, 2, minusSign) + ':' +
|
1792 | padNumber(Math.abs(zone % 60), 2, minusSign);
|
1793 | }
|
1794 | default:
|
1795 | throw new Error("Unknown zone width \"" + width + "\"");
|
1796 | }
|
1797 | };
|
1798 | }
|
1799 | var JANUARY = 0;
|
1800 | var THURSDAY = 4;
|
1801 | function getFirstThursdayOfYear(year) {
|
1802 | var firstDayOfYear = (new Date(year, JANUARY, 1)).getDay();
|
1803 | return new Date(year, 0, 1 + ((firstDayOfYear <= THURSDAY) ? THURSDAY : THURSDAY + 7) - firstDayOfYear);
|
1804 | }
|
1805 | function getThursdayThisWeek(datetime) {
|
1806 | return new Date(datetime.getFullYear(), datetime.getMonth(), datetime.getDate() + (THURSDAY - datetime.getDay()));
|
1807 | }
|
1808 | function weekGetter(size, monthBased) {
|
1809 | if (monthBased === void 0) { monthBased = false; }
|
1810 | return function (date, locale) {
|
1811 | var result;
|
1812 | if (monthBased) {
|
1813 | var nbDaysBefore1stDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1).getDay() - 1;
|
1814 | var today = date.getDate();
|
1815 | result = 1 + Math.floor((today + nbDaysBefore1stDayOfMonth) / 7);
|
1816 | }
|
1817 | else {
|
1818 | var firstThurs = getFirstThursdayOfYear(date.getFullYear());
|
1819 | var thisThurs = getThursdayThisWeek(date);
|
1820 | var diff = thisThurs.getTime() - firstThurs.getTime();
|
1821 | result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week
|
1822 | }
|
1823 | return padNumber(result, size, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
1824 | };
|
1825 | }
|
1826 | var DATE_FORMATS = {};
|
1827 | // Based on CLDR formats:
|
1828 | // See complete list: http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
1829 | // See also explanations: http://cldr.unicode.org/translation/date-time
|
1830 | // TODO(ocombe): support all missing cldr formats: Y, U, Q, D, F, e, c, j, J, C, A, v, V, X, x
|
1831 | function getDateFormatter(format) {
|
1832 | if (DATE_FORMATS[format]) {
|
1833 | return DATE_FORMATS[format];
|
1834 | }
|
1835 | var formatter;
|
1836 | switch (format) {
|
1837 | // Era name (AD/BC)
|
1838 | case 'G':
|
1839 | case 'GG':
|
1840 | case 'GGG':
|
1841 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Abbreviated);
|
1842 | break;
|
1843 | case 'GGGG':
|
1844 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Wide);
|
1845 | break;
|
1846 | case 'GGGGG':
|
1847 | formatter = dateStrGetter(TranslationType.Eras, TranslationWidth.Narrow);
|
1848 | break;
|
1849 | // 1 digit representation of the year, e.g. (AD 1 => 1, AD 199 => 199)
|
1850 | case 'y':
|
1851 | formatter = dateGetter(DateType.FullYear, 1, 0, false, true);
|
1852 | break;
|
1853 | // 2 digit representation of the year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
|
1854 | case 'yy':
|
1855 | formatter = dateGetter(DateType.FullYear, 2, 0, true, true);
|
1856 | break;
|
1857 | // 3 digit representation of the year, padded (000-999). (e.g. AD 2001 => 01, AD 2010 => 10)
|
1858 | case 'yyy':
|
1859 | formatter = dateGetter(DateType.FullYear, 3, 0, false, true);
|
1860 | break;
|
1861 | // 4 digit representation of the year (e.g. AD 1 => 0001, AD 2010 => 2010)
|
1862 | case 'yyyy':
|
1863 | formatter = dateGetter(DateType.FullYear, 4, 0, false, true);
|
1864 | break;
|
1865 | // Month of the year (1-12), numeric
|
1866 | case 'M':
|
1867 | case 'L':
|
1868 | formatter = dateGetter(DateType.Month, 1, 1);
|
1869 | break;
|
1870 | case 'MM':
|
1871 | case 'LL':
|
1872 | formatter = dateGetter(DateType.Month, 2, 1);
|
1873 | break;
|
1874 | // Month of the year (January, ...), string, format
|
1875 | case 'MMM':
|
1876 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated);
|
1877 | break;
|
1878 | case 'MMMM':
|
1879 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Wide);
|
1880 | break;
|
1881 | case 'MMMMM':
|
1882 | formatter = dateStrGetter(TranslationType.Months, TranslationWidth.Narrow);
|
1883 | break;
|
1884 | // Month of the year (January, ...), string, standalone
|
1885 | case 'LLL':
|
1886 | formatter =
|
1887 | dateStrGetter(TranslationType.Months, TranslationWidth.Abbreviated, FormStyle.Standalone);
|
1888 | break;
|
1889 | case 'LLLL':
|
1890 | formatter =
|
1891 | dateStrGetter(TranslationType.Months, TranslationWidth.Wide, FormStyle.Standalone);
|
1892 | break;
|
1893 | case 'LLLLL':
|
1894 | formatter =
|
1895 | dateStrGetter(TranslationType.Months, TranslationWidth.Narrow, FormStyle.Standalone);
|
1896 | break;
|
1897 | // Week of the year (1, ... 52)
|
1898 | case 'w':
|
1899 | formatter = weekGetter(1);
|
1900 | break;
|
1901 | case 'ww':
|
1902 | formatter = weekGetter(2);
|
1903 | break;
|
1904 | // Week of the month (1, ...)
|
1905 | case 'W':
|
1906 | formatter = weekGetter(1, true);
|
1907 | break;
|
1908 | // Day of the month (1-31)
|
1909 | case 'd':
|
1910 | formatter = dateGetter(DateType.Date, 1);
|
1911 | break;
|
1912 | case 'dd':
|
1913 | formatter = dateGetter(DateType.Date, 2);
|
1914 | break;
|
1915 | // Day of the Week
|
1916 | case 'E':
|
1917 | case 'EE':
|
1918 | case 'EEE':
|
1919 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Abbreviated);
|
1920 | break;
|
1921 | case 'EEEE':
|
1922 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Wide);
|
1923 | break;
|
1924 | case 'EEEEE':
|
1925 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Narrow);
|
1926 | break;
|
1927 | case 'EEEEEE':
|
1928 | formatter = dateStrGetter(TranslationType.Days, TranslationWidth.Short);
|
1929 | break;
|
1930 | // Generic period of the day (am-pm)
|
1931 | case 'a':
|
1932 | case 'aa':
|
1933 | case 'aaa':
|
1934 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated);
|
1935 | break;
|
1936 | case 'aaaa':
|
1937 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide);
|
1938 | break;
|
1939 | case 'aaaaa':
|
1940 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow);
|
1941 | break;
|
1942 | // Extended period of the day (midnight, at night, ...), standalone
|
1943 | case 'b':
|
1944 | case 'bb':
|
1945 | case 'bbb':
|
1946 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Standalone, true);
|
1947 | break;
|
1948 | case 'bbbb':
|
1949 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Standalone, true);
|
1950 | break;
|
1951 | case 'bbbbb':
|
1952 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Standalone, true);
|
1953 | break;
|
1954 | // Extended period of the day (midnight, night, ...), standalone
|
1955 | case 'B':
|
1956 | case 'BB':
|
1957 | case 'BBB':
|
1958 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Abbreviated, FormStyle.Format, true);
|
1959 | break;
|
1960 | case 'BBBB':
|
1961 | formatter =
|
1962 | dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Wide, FormStyle.Format, true);
|
1963 | break;
|
1964 | case 'BBBBB':
|
1965 | formatter = dateStrGetter(TranslationType.DayPeriods, TranslationWidth.Narrow, FormStyle.Format, true);
|
1966 | break;
|
1967 | // Hour in AM/PM, (1-12)
|
1968 | case 'h':
|
1969 | formatter = dateGetter(DateType.Hours, 1, -12);
|
1970 | break;
|
1971 | case 'hh':
|
1972 | formatter = dateGetter(DateType.Hours, 2, -12);
|
1973 | break;
|
1974 | // Hour of the day (0-23)
|
1975 | case 'H':
|
1976 | formatter = dateGetter(DateType.Hours, 1);
|
1977 | break;
|
1978 | // Hour in day, padded (00-23)
|
1979 | case 'HH':
|
1980 | formatter = dateGetter(DateType.Hours, 2);
|
1981 | break;
|
1982 | // Minute of the hour (0-59)
|
1983 | case 'm':
|
1984 | formatter = dateGetter(DateType.Minutes, 1);
|
1985 | break;
|
1986 | case 'mm':
|
1987 | formatter = dateGetter(DateType.Minutes, 2);
|
1988 | break;
|
1989 | // Second of the minute (0-59)
|
1990 | case 's':
|
1991 | formatter = dateGetter(DateType.Seconds, 1);
|
1992 | break;
|
1993 | case 'ss':
|
1994 | formatter = dateGetter(DateType.Seconds, 2);
|
1995 | break;
|
1996 | // Fractional second
|
1997 | case 'S':
|
1998 | formatter = dateGetter(DateType.FractionalSeconds, 1);
|
1999 | break;
|
2000 | case 'SS':
|
2001 | formatter = dateGetter(DateType.FractionalSeconds, 2);
|
2002 | break;
|
2003 | case 'SSS':
|
2004 | formatter = dateGetter(DateType.FractionalSeconds, 3);
|
2005 | break;
|
2006 | // Timezone ISO8601 short format (-0430)
|
2007 | case 'Z':
|
2008 | case 'ZZ':
|
2009 | case 'ZZZ':
|
2010 | formatter = timeZoneGetter(ZoneWidth.Short);
|
2011 | break;
|
2012 | // Timezone ISO8601 extended format (-04:30)
|
2013 | case 'ZZZZZ':
|
2014 | formatter = timeZoneGetter(ZoneWidth.Extended);
|
2015 | break;
|
2016 | // Timezone GMT short format (GMT+4)
|
2017 | case 'O':
|
2018 | case 'OO':
|
2019 | case 'OOO':
|
2020 | // Should be location, but fallback to format O instead because we don't have the data yet
|
2021 | case 'z':
|
2022 | case 'zz':
|
2023 | case 'zzz':
|
2024 | formatter = timeZoneGetter(ZoneWidth.ShortGMT);
|
2025 | break;
|
2026 | // Timezone GMT long format (GMT+0430)
|
2027 | case 'OOOO':
|
2028 | case 'ZZZZ':
|
2029 | // Should be location, but fallback to format O instead because we don't have the data yet
|
2030 | case 'zzzz':
|
2031 | formatter = timeZoneGetter(ZoneWidth.Long);
|
2032 | break;
|
2033 | default:
|
2034 | return null;
|
2035 | }
|
2036 | DATE_FORMATS[format] = formatter;
|
2037 | return formatter;
|
2038 | }
|
2039 | function timezoneToOffset(timezone, fallback) {
|
2040 | // Support: IE 9-11 only, Edge 13-15+
|
2041 | // IE/Edge do not "understand" colon (`:`) in timezone
|
2042 | timezone = timezone.replace(/:/g, '');
|
2043 | var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
|
2044 | return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
|
2045 | }
|
2046 | function addDateMinutes(date, minutes) {
|
2047 | date = new Date(date.getTime());
|
2048 | date.setMinutes(date.getMinutes() + minutes);
|
2049 | return date;
|
2050 | }
|
2051 | function convertTimezoneToLocal(date, timezone, reverse) {
|
2052 | var reverseValue = reverse ? -1 : 1;
|
2053 | var dateTimezoneOffset = date.getTimezoneOffset();
|
2054 | var timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
2055 | return addDateMinutes(date, reverseValue * (timezoneOffset - dateTimezoneOffset));
|
2056 | }
|
2057 | /**
|
2058 | * Converts a value to date.
|
2059 | *
|
2060 | * Supported input formats:
|
2061 | * - `Date`
|
2062 | * - number: timestamp
|
2063 | * - string: numeric (e.g. "1234"), ISO and date strings in a format supported by
|
2064 | * [Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
|
2065 | * Note: ISO strings without time return a date without timeoffset.
|
2066 | *
|
2067 | * Throws if unable to convert to a date.
|
2068 | */
|
2069 | function toDate(value) {
|
2070 | if (isDate(value)) {
|
2071 | return value;
|
2072 | }
|
2073 | if (typeof value === 'number' && !isNaN(value)) {
|
2074 | return new Date(value);
|
2075 | }
|
2076 | if (typeof value === 'string') {
|
2077 | value = value.trim();
|
2078 | var parsedNb = parseFloat(value);
|
2079 | // any string that only contains numbers, like "1234" but not like "1234hello"
|
2080 | if (!isNaN(value - parsedNb)) {
|
2081 | return new Date(parsedNb);
|
2082 | }
|
2083 | if (/^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
|
2084 | /* For ISO Strings without time the day, month and year must be extracted from the ISO String
|
2085 | before Date creation to avoid time offset and errors in the new Date.
|
2086 | If we only replace '-' with ',' in the ISO String ("2015,01,01"), and try to create a new
|
2087 | date, some browsers (e.g. IE 9) will throw an invalid Date error.
|
2088 | If we leave the '-' ("2015-01-01") and try to create a new Date("2015-01-01") the timeoffset
|
2089 | is applied.
|
2090 | Note: ISO months are 0 for January, 1 for February, ... */
|
2091 | var _a = __read(value.split('-').map(function (val) { return +val; }), 3), y = _a[0], m = _a[1], d = _a[2];
|
2092 | return new Date(y, m - 1, d);
|
2093 | }
|
2094 | var match = void 0;
|
2095 | if (match = value.match(ISO8601_DATE_REGEX)) {
|
2096 | return isoStringToDate(match);
|
2097 | }
|
2098 | }
|
2099 | var date = new Date(value);
|
2100 | if (!isDate(date)) {
|
2101 | throw new Error("Unable to convert \"" + value + "\" into a date");
|
2102 | }
|
2103 | return date;
|
2104 | }
|
2105 | /**
|
2106 | * Converts a date in ISO8601 to a Date.
|
2107 | * Used instead of `Date.parse` because of browser discrepancies.
|
2108 | */
|
2109 | function isoStringToDate(match) {
|
2110 | var date = new Date(0);
|
2111 | var tzHour = 0;
|
2112 | var tzMin = 0;
|
2113 | // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100"
|
2114 | var dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear;
|
2115 | var timeSetter = match[8] ? date.setUTCHours : date.setHours;
|
2116 | // if there is a timezone defined like "+01:00" or "+0100"
|
2117 | if (match[9]) {
|
2118 | tzHour = Number(match[9] + match[10]);
|
2119 | tzMin = Number(match[9] + match[11]);
|
2120 | }
|
2121 | dateSetter.call(date, Number(match[1]), Number(match[2]) - 1, Number(match[3]));
|
2122 | var h = Number(match[4] || 0) - tzHour;
|
2123 | var m = Number(match[5] || 0) - tzMin;
|
2124 | var s = Number(match[6] || 0);
|
2125 | var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000);
|
2126 | timeSetter.call(date, h, m, s, ms);
|
2127 | return date;
|
2128 | }
|
2129 | function isDate(value) {
|
2130 | return value instanceof Date && !isNaN(value.valueOf());
|
2131 | }
|
2132 |
|
2133 | /**
|
2134 | * @license
|
2135 | * Copyright Google Inc. All Rights Reserved.
|
2136 | *
|
2137 | * Use of this source code is governed by an MIT-style license that can be
|
2138 | * found in the LICENSE file at https://angular.io/license
|
2139 | */
|
2140 | var NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/;
|
2141 | var MAX_DIGITS = 22;
|
2142 | var DECIMAL_SEP = '.';
|
2143 | var ZERO_CHAR = '0';
|
2144 | var PATTERN_SEP = ';';
|
2145 | var GROUP_SEP = ',';
|
2146 | var DIGIT_CHAR = '#';
|
2147 | var CURRENCY_CHAR = '¤';
|
2148 | var PERCENT_CHAR = '%';
|
2149 | /**
|
2150 | * Transforms a number to a locale string based on a style and a format.
|
2151 | */
|
2152 | function formatNumberToLocaleString(value, pattern, locale, groupSymbol, decimalSymbol, digitsInfo, isPercent) {
|
2153 | if (isPercent === void 0) { isPercent = false; }
|
2154 | var formattedText = '';
|
2155 | var isZero = false;
|
2156 | if (!isFinite(value)) {
|
2157 | formattedText = getLocaleNumberSymbol(locale, NumberSymbol.Infinity);
|
2158 | }
|
2159 | else {
|
2160 | var parsedNumber = parseNumber(value);
|
2161 | if (isPercent) {
|
2162 | parsedNumber = toPercent(parsedNumber);
|
2163 | }
|
2164 | var minInt = pattern.minInt;
|
2165 | var minFraction = pattern.minFrac;
|
2166 | var maxFraction = pattern.maxFrac;
|
2167 | if (digitsInfo) {
|
2168 | var parts = digitsInfo.match(NUMBER_FORMAT_REGEXP);
|
2169 | if (parts === null) {
|
2170 | throw new Error(digitsInfo + " is not a valid digit info");
|
2171 | }
|
2172 | var minIntPart = parts[1];
|
2173 | var minFractionPart = parts[3];
|
2174 | var maxFractionPart = parts[5];
|
2175 | if (minIntPart != null) {
|
2176 | minInt = parseIntAutoRadix(minIntPart);
|
2177 | }
|
2178 | if (minFractionPart != null) {
|
2179 | minFraction = parseIntAutoRadix(minFractionPart);
|
2180 | }
|
2181 | if (maxFractionPart != null) {
|
2182 | maxFraction = parseIntAutoRadix(maxFractionPart);
|
2183 | }
|
2184 | else if (minFractionPart != null && minFraction > maxFraction) {
|
2185 | maxFraction = minFraction;
|
2186 | }
|
2187 | }
|
2188 | roundNumber(parsedNumber, minFraction, maxFraction);
|
2189 | var digits = parsedNumber.digits;
|
2190 | var integerLen = parsedNumber.integerLen;
|
2191 | var exponent = parsedNumber.exponent;
|
2192 | var decimals = [];
|
2193 | isZero = digits.every(function (d) { return !d; });
|
2194 | // pad zeros for small numbers
|
2195 | for (; integerLen < minInt; integerLen++) {
|
2196 | digits.unshift(0);
|
2197 | }
|
2198 | // pad zeros for small numbers
|
2199 | for (; integerLen < 0; integerLen++) {
|
2200 | digits.unshift(0);
|
2201 | }
|
2202 | // extract decimals digits
|
2203 | if (integerLen > 0) {
|
2204 | decimals = digits.splice(integerLen, digits.length);
|
2205 | }
|
2206 | else {
|
2207 | decimals = digits;
|
2208 | digits = [0];
|
2209 | }
|
2210 | // format the integer digits with grouping separators
|
2211 | var groups = [];
|
2212 | if (digits.length >= pattern.lgSize) {
|
2213 | groups.unshift(digits.splice(-pattern.lgSize, digits.length).join(''));
|
2214 | }
|
2215 | while (digits.length > pattern.gSize) {
|
2216 | groups.unshift(digits.splice(-pattern.gSize, digits.length).join(''));
|
2217 | }
|
2218 | if (digits.length) {
|
2219 | groups.unshift(digits.join(''));
|
2220 | }
|
2221 | formattedText = groups.join(getLocaleNumberSymbol(locale, groupSymbol));
|
2222 | // append the decimal digits
|
2223 | if (decimals.length) {
|
2224 | formattedText += getLocaleNumberSymbol(locale, decimalSymbol) + decimals.join('');
|
2225 | }
|
2226 | if (exponent) {
|
2227 | formattedText += getLocaleNumberSymbol(locale, NumberSymbol.Exponential) + '+' + exponent;
|
2228 | }
|
2229 | }
|
2230 | if (value < 0 && !isZero) {
|
2231 | formattedText = pattern.negPre + formattedText + pattern.negSuf;
|
2232 | }
|
2233 | else {
|
2234 | formattedText = pattern.posPre + formattedText + pattern.posSuf;
|
2235 | }
|
2236 | return formattedText;
|
2237 | }
|
2238 | /**
|
2239 | * @ngModule CommonModule
|
2240 | * @description
|
2241 | *
|
2242 | * Formats a number as currency using locale rules.
|
2243 | *
|
2244 | * @param value The number to format.
|
2245 | * @param locale A locale code for the locale format rules to use.
|
2246 | * @param currency A string containing the currency symbol or its name,
|
2247 | * such as "$" or "Canadian Dollar". Used in output string, but does not affect the operation
|
2248 | * of the function.
|
2249 | * @param currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)
|
2250 | * currency code, such as `USD` for the US dollar and `EUR` for the euro.
|
2251 | * Used to determine the number of digits in the decimal part.
|
2252 | * @param digitInfo Decimal representation options, specified by a string in the following format:
|
2253 | * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details.
|
2254 | *
|
2255 | * @returns The formatted currency value.
|
2256 | *
|
2257 | * @see `formatNumber()`
|
2258 | * @see `DecimalPipe`
|
2259 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2260 | *
|
2261 | * @publicApi
|
2262 | */
|
2263 | function formatCurrency(value, locale, currency, currencyCode, digitsInfo) {
|
2264 | var format = getLocaleNumberFormat(locale, NumberFormatStyle.Currency);
|
2265 | var pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
2266 | pattern.minFrac = getNumberOfCurrencyDigits(currencyCode);
|
2267 | pattern.maxFrac = pattern.minFrac;
|
2268 | var res = formatNumberToLocaleString(value, pattern, locale, NumberSymbol.CurrencyGroup, NumberSymbol.CurrencyDecimal, digitsInfo);
|
2269 | return res
|
2270 | .replace(CURRENCY_CHAR, currency)
|
2271 | // if we have 2 time the currency character, the second one is ignored
|
2272 | .replace(CURRENCY_CHAR, '')
|
2273 | // If there is a spacing between currency character and the value and
|
2274 | // the currency character is supressed by passing an empty string, the
|
2275 | // spacing character would remain as part of the string. Then we
|
2276 | // should remove it.
|
2277 | .trim();
|
2278 | }
|
2279 | /**
|
2280 | * @ngModule CommonModule
|
2281 | * @description
|
2282 | *
|
2283 | * Formats a number as a percentage according to locale rules.
|
2284 | *
|
2285 | * @param value The number to format.
|
2286 | * @param locale A locale code for the locale format rules to use.
|
2287 | * @param digitInfo Decimal representation options, specified by a string in the following format:
|
2288 | * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details.
|
2289 | *
|
2290 | * @returns The formatted percentage value.
|
2291 | *
|
2292 | * @see `formatNumber()`
|
2293 | * @see `DecimalPipe`
|
2294 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2295 | * @publicApi
|
2296 | *
|
2297 | */
|
2298 | function formatPercent(value, locale, digitsInfo) {
|
2299 | var format = getLocaleNumberFormat(locale, NumberFormatStyle.Percent);
|
2300 | var pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
2301 | var res = formatNumberToLocaleString(value, pattern, locale, NumberSymbol.Group, NumberSymbol.Decimal, digitsInfo, true);
|
2302 | return res.replace(new RegExp(PERCENT_CHAR, 'g'), getLocaleNumberSymbol(locale, NumberSymbol.PercentSign));
|
2303 | }
|
2304 | /**
|
2305 | * @ngModule CommonModule
|
2306 | * @description
|
2307 | *
|
2308 | * Formats a number as text, with group sizing, separator, and other
|
2309 | * parameters based on the locale.
|
2310 | *
|
2311 | * @param value The number to format.
|
2312 | * @param locale A locale code for the locale format rules to use.
|
2313 | * @param digitInfo Decimal representation options, specified by a string in the following format:
|
2314 | * `{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}`. See `DecimalPipe` for more details.
|
2315 | *
|
2316 | * @returns The formatted text string.
|
2317 | * @see [Internationalization (i18n) Guide](https://angular.io/guide/i18n)
|
2318 | *
|
2319 | * @publicApi
|
2320 | */
|
2321 | function formatNumber(value, locale, digitsInfo) {
|
2322 | var format = getLocaleNumberFormat(locale, NumberFormatStyle.Decimal);
|
2323 | var pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
2324 | return formatNumberToLocaleString(value, pattern, locale, NumberSymbol.Group, NumberSymbol.Decimal, digitsInfo);
|
2325 | }
|
2326 | function parseNumberFormat(format, minusSign) {
|
2327 | if (minusSign === void 0) { minusSign = '-'; }
|
2328 | var p = {
|
2329 | minInt: 1,
|
2330 | minFrac: 0,
|
2331 | maxFrac: 0,
|
2332 | posPre: '',
|
2333 | posSuf: '',
|
2334 | negPre: '',
|
2335 | negSuf: '',
|
2336 | gSize: 0,
|
2337 | lgSize: 0
|
2338 | };
|
2339 | var patternParts = format.split(PATTERN_SEP);
|
2340 | var positive = patternParts[0];
|
2341 | var negative = patternParts[1];
|
2342 | var positiveParts = positive.indexOf(DECIMAL_SEP) !== -1 ?
|
2343 | positive.split(DECIMAL_SEP) :
|
2344 | [
|
2345 | positive.substring(0, positive.lastIndexOf(ZERO_CHAR) + 1),
|
2346 | positive.substring(positive.lastIndexOf(ZERO_CHAR) + 1)
|
2347 | ], integer = positiveParts[0], fraction = positiveParts[1] || '';
|
2348 | p.posPre = integer.substr(0, integer.indexOf(DIGIT_CHAR));
|
2349 | for (var i = 0; i < fraction.length; i++) {
|
2350 | var ch = fraction.charAt(i);
|
2351 | if (ch === ZERO_CHAR) {
|
2352 | p.minFrac = p.maxFrac = i + 1;
|
2353 | }
|
2354 | else if (ch === DIGIT_CHAR) {
|
2355 | p.maxFrac = i + 1;
|
2356 | }
|
2357 | else {
|
2358 | p.posSuf += ch;
|
2359 | }
|
2360 | }
|
2361 | var groups = integer.split(GROUP_SEP);
|
2362 | p.gSize = groups[1] ? groups[1].length : 0;
|
2363 | p.lgSize = (groups[2] || groups[1]) ? (groups[2] || groups[1]).length : 0;
|
2364 | if (negative) {
|
2365 | var trunkLen = positive.length - p.posPre.length - p.posSuf.length, pos = negative.indexOf(DIGIT_CHAR);
|
2366 | p.negPre = negative.substr(0, pos).replace(/'/g, '');
|
2367 | p.negSuf = negative.substr(pos + trunkLen).replace(/'/g, '');
|
2368 | }
|
2369 | else {
|
2370 | p.negPre = minusSign + p.posPre;
|
2371 | p.negSuf = p.posSuf;
|
2372 | }
|
2373 | return p;
|
2374 | }
|
2375 | // Transforms a parsed number into a percentage by multiplying it by 100
|
2376 | function toPercent(parsedNumber) {
|
2377 | // if the number is 0, don't do anything
|
2378 | if (parsedNumber.digits[0] === 0) {
|
2379 | return parsedNumber;
|
2380 | }
|
2381 | // Getting the current number of decimals
|
2382 | var fractionLen = parsedNumber.digits.length - parsedNumber.integerLen;
|
2383 | if (parsedNumber.exponent) {
|
2384 | parsedNumber.exponent += 2;
|
2385 | }
|
2386 | else {
|
2387 | if (fractionLen === 0) {
|
2388 | parsedNumber.digits.push(0, 0);
|
2389 | }
|
2390 | else if (fractionLen === 1) {
|
2391 | parsedNumber.digits.push(0);
|
2392 | }
|
2393 | parsedNumber.integerLen += 2;
|
2394 | }
|
2395 | return parsedNumber;
|
2396 | }
|
2397 | /**
|
2398 | * Parses a number.
|
2399 | * Significant bits of this parse algorithm came from https://github.com/MikeMcl/big.js/
|
2400 | */
|
2401 | function parseNumber(num) {
|
2402 | var numStr = Math.abs(num) + '';
|
2403 | var exponent = 0, digits, integerLen;
|
2404 | var i, j, zeros;
|
2405 | // Decimal point?
|
2406 | if ((integerLen = numStr.indexOf(DECIMAL_SEP)) > -1) {
|
2407 | numStr = numStr.replace(DECIMAL_SEP, '');
|
2408 | }
|
2409 | // Exponential form?
|
2410 | if ((i = numStr.search(/e/i)) > 0) {
|
2411 | // Work out the exponent.
|
2412 | if (integerLen < 0)
|
2413 | integerLen = i;
|
2414 | integerLen += +numStr.slice(i + 1);
|
2415 | numStr = numStr.substring(0, i);
|
2416 | }
|
2417 | else if (integerLen < 0) {
|
2418 | // There was no decimal point or exponent so it is an integer.
|
2419 | integerLen = numStr.length;
|
2420 | }
|
2421 | // Count the number of leading zeros.
|
2422 | for (i = 0; numStr.charAt(i) === ZERO_CHAR; i++) { /* empty */
|
2423 | }
|
2424 | if (i === (zeros = numStr.length)) {
|
2425 | // The digits are all zero.
|
2426 | digits = [0];
|
2427 | integerLen = 1;
|
2428 | }
|
2429 | else {
|
2430 | // Count the number of trailing zeros
|
2431 | zeros--;
|
2432 | while (numStr.charAt(zeros) === ZERO_CHAR)
|
2433 | zeros--;
|
2434 | // Trailing zeros are insignificant so ignore them
|
2435 | integerLen -= i;
|
2436 | digits = [];
|
2437 | // Convert string to array of digits without leading/trailing zeros.
|
2438 | for (j = 0; i <= zeros; i++, j++) {
|
2439 | digits[j] = Number(numStr.charAt(i));
|
2440 | }
|
2441 | }
|
2442 | // If the number overflows the maximum allowed digits then use an exponent.
|
2443 | if (integerLen > MAX_DIGITS) {
|
2444 | digits = digits.splice(0, MAX_DIGITS - 1);
|
2445 | exponent = integerLen - 1;
|
2446 | integerLen = 1;
|
2447 | }
|
2448 | return { digits: digits, exponent: exponent, integerLen: integerLen };
|
2449 | }
|
2450 | /**
|
2451 | * Round the parsed number to the specified number of decimal places
|
2452 | * This function changes the parsedNumber in-place
|
2453 | */
|
2454 | function roundNumber(parsedNumber, minFrac, maxFrac) {
|
2455 | if (minFrac > maxFrac) {
|
2456 | throw new Error("The minimum number of digits after fraction (" + minFrac + ") is higher than the maximum (" + maxFrac + ").");
|
2457 | }
|
2458 | var digits = parsedNumber.digits;
|
2459 | var fractionLen = digits.length - parsedNumber.integerLen;
|
2460 | var fractionSize = Math.min(Math.max(minFrac, fractionLen), maxFrac);
|
2461 | // The index of the digit to where rounding is to occur
|
2462 | var roundAt = fractionSize + parsedNumber.integerLen;
|
2463 | var digit = digits[roundAt];
|
2464 | if (roundAt > 0) {
|
2465 | // Drop fractional digits beyond `roundAt`
|
2466 | digits.splice(Math.max(parsedNumber.integerLen, roundAt));
|
2467 | // Set non-fractional digits beyond `roundAt` to 0
|
2468 | for (var j = roundAt; j < digits.length; j++) {
|
2469 | digits[j] = 0;
|
2470 | }
|
2471 | }
|
2472 | else {
|
2473 | // We rounded to zero so reset the parsedNumber
|
2474 | fractionLen = Math.max(0, fractionLen);
|
2475 | parsedNumber.integerLen = 1;
|
2476 | digits.length = Math.max(1, roundAt = fractionSize + 1);
|
2477 | digits[0] = 0;
|
2478 | for (var i = 1; i < roundAt; i++)
|
2479 | digits[i] = 0;
|
2480 | }
|
2481 | if (digit >= 5) {
|
2482 | if (roundAt - 1 < 0) {
|
2483 | for (var k = 0; k > roundAt; k--) {
|
2484 | digits.unshift(0);
|
2485 | parsedNumber.integerLen++;
|
2486 | }
|
2487 | digits.unshift(1);
|
2488 | parsedNumber.integerLen++;
|
2489 | }
|
2490 | else {
|
2491 | digits[roundAt - 1]++;
|
2492 | }
|
2493 | }
|
2494 | // Pad out with zeros to get the required fraction length
|
2495 | for (; fractionLen < Math.max(0, fractionSize); fractionLen++)
|
2496 | digits.push(0);
|
2497 | var dropTrailingZeros = fractionSize !== 0;
|
2498 | // Minimal length = nb of decimals required + current nb of integers
|
2499 | // Any number besides that is optional and can be removed if it's a trailing 0
|
2500 | var minLen = minFrac + parsedNumber.integerLen;
|
2501 | // Do any carrying, e.g. a digit was rounded up to 10
|
2502 | var carry = digits.reduceRight(function (carry, d, i, digits) {
|
2503 | d = d + carry;
|
2504 | digits[i] = d < 10 ? d : d - 10; // d % 10
|
2505 | if (dropTrailingZeros) {
|
2506 | // Do not keep meaningless fractional trailing zeros (e.g. 15.52000 --> 15.52)
|
2507 | if (digits[i] === 0 && i >= minLen) {
|
2508 | digits.pop();
|
2509 | }
|
2510 | else {
|
2511 | dropTrailingZeros = false;
|
2512 | }
|
2513 | }
|
2514 | return d >= 10 ? 1 : 0; // Math.floor(d / 10);
|
2515 | }, 0);
|
2516 | if (carry) {
|
2517 | digits.unshift(carry);
|
2518 | parsedNumber.integerLen++;
|
2519 | }
|
2520 | }
|
2521 | function parseIntAutoRadix(text) {
|
2522 | var result = parseInt(text);
|
2523 | if (isNaN(result)) {
|
2524 | throw new Error('Invalid integer literal when parsing ' + text);
|
2525 | }
|
2526 | return result;
|
2527 | }
|
2528 |
|
2529 | /**
|
2530 | * @license
|
2531 | * Copyright Google Inc. All Rights Reserved.
|
2532 | *
|
2533 | * Use of this source code is governed by an MIT-style license that can be
|
2534 | * found in the LICENSE file at https://angular.io/license
|
2535 | */
|
2536 | /**
|
2537 | * @publicApi
|
2538 | */
|
2539 | var NgLocalization = /** @class */ (function () {
|
2540 | function NgLocalization() {
|
2541 | }
|
2542 | return NgLocalization;
|
2543 | }());
|
2544 | /**
|
2545 | * Returns the plural category for a given value.
|
2546 | * - "=value" when the case exists,
|
2547 | * - the plural category otherwise
|
2548 | */
|
2549 | function getPluralCategory(value, cases, ngLocalization, locale) {
|
2550 | var key = "=" + value;
|
2551 | if (cases.indexOf(key) > -1) {
|
2552 | return key;
|
2553 | }
|
2554 | key = ngLocalization.getPluralCategory(value, locale);
|
2555 | if (cases.indexOf(key) > -1) {
|
2556 | return key;
|
2557 | }
|
2558 | if (cases.indexOf('other') > -1) {
|
2559 | return 'other';
|
2560 | }
|
2561 | throw new Error("No plural message found for value \"" + value + "\"");
|
2562 | }
|
2563 | /**
|
2564 | * Returns the plural case based on the locale
|
2565 | *
|
2566 | * @publicApi
|
2567 | */
|
2568 | var NgLocaleLocalization = /** @class */ (function (_super) {
|
2569 | __extends(NgLocaleLocalization, _super);
|
2570 | function NgLocaleLocalization(locale) {
|
2571 | var _this = _super.call(this) || this;
|
2572 | _this.locale = locale;
|
2573 | return _this;
|
2574 | }
|
2575 | NgLocaleLocalization.prototype.getPluralCategory = function (value, locale) {
|
2576 | var plural = getLocalePluralCase(locale || this.locale)(value);
|
2577 | switch (plural) {
|
2578 | case Plural.Zero:
|
2579 | return 'zero';
|
2580 | case Plural.One:
|
2581 | return 'one';
|
2582 | case Plural.Two:
|
2583 | return 'two';
|
2584 | case Plural.Few:
|
2585 | return 'few';
|
2586 | case Plural.Many:
|
2587 | return 'many';
|
2588 | default:
|
2589 | return 'other';
|
2590 | }
|
2591 | };
|
2592 | NgLocaleLocalization = __decorate([
|
2593 | Injectable(),
|
2594 | __param(0, Inject(LOCALE_ID)),
|
2595 | __metadata("design:paramtypes", [String])
|
2596 | ], NgLocaleLocalization);
|
2597 | return NgLocaleLocalization;
|
2598 | }(NgLocalization));
|
2599 |
|
2600 | /**
|
2601 | * @license
|
2602 | * Copyright Google Inc. All Rights Reserved.
|
2603 | *
|
2604 | * Use of this source code is governed by an MIT-style license that can be
|
2605 | * found in the LICENSE file at https://angular.io/license
|
2606 | */
|
2607 | /**
|
2608 | * Register global data to be used internally by Angular. See the
|
2609 | * ["I18n guide"](guide/i18n#i18n-pipes) to know how to import additional locale data.
|
2610 | *
|
2611 | * The signature registerLocaleData(data: any, extraData?: any) is deprecated since v5.1
|
2612 | *
|
2613 | * @publicApi
|
2614 | */
|
2615 | function registerLocaleData(data, localeId, extraData) {
|
2616 | return ɵregisterLocaleData(data, localeId, extraData);
|
2617 | }
|
2618 |
|
2619 | /**
|
2620 | * @license
|
2621 | * Copyright Google Inc. All Rights Reserved.
|
2622 | *
|
2623 | * Use of this source code is governed by an MIT-style license that can be
|
2624 | * found in the LICENSE file at https://angular.io/license
|
2625 | */
|
2626 | function parseCookieValue(cookieStr, name) {
|
2627 | var e_1, _a;
|
2628 | name = encodeURIComponent(name);
|
2629 | try {
|
2630 | for (var _b = __values(cookieStr.split(';')), _c = _b.next(); !_c.done; _c = _b.next()) {
|
2631 | var cookie = _c.value;
|
2632 | var eqIndex = cookie.indexOf('=');
|
2633 | var _d = __read(eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)], 2), cookieName = _d[0], cookieValue = _d[1];
|
2634 | if (cookieName.trim() === name) {
|
2635 | return decodeURIComponent(cookieValue);
|
2636 | }
|
2637 | }
|
2638 | }
|
2639 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
2640 | finally {
|
2641 | try {
|
2642 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
2643 | }
|
2644 | finally { if (e_1) throw e_1.error; }
|
2645 | }
|
2646 | return null;
|
2647 | }
|
2648 |
|
2649 | /**
|
2650 | * @ngModule CommonModule
|
2651 | *
|
2652 | * @usageNotes
|
2653 | * ```
|
2654 | * <some-element [ngClass]="'first second'">...</some-element>
|
2655 | *
|
2656 | * <some-element [ngClass]="['first', 'second']">...</some-element>
|
2657 | *
|
2658 | * <some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
|
2659 | *
|
2660 | * <some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>
|
2661 | *
|
2662 | * <some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>
|
2663 | * ```
|
2664 | *
|
2665 | * @description
|
2666 | *
|
2667 | * Adds and removes CSS classes on an HTML element.
|
2668 | *
|
2669 | * The CSS classes are updated as follows, depending on the type of the expression evaluation:
|
2670 | * - `string` - the CSS classes listed in the string (space delimited) are added,
|
2671 | * - `Array` - the CSS classes declared as Array elements are added,
|
2672 | * - `Object` - keys are CSS classes that get added when the expression given in the value
|
2673 | * evaluates to a truthy value, otherwise they are removed.
|
2674 | *
|
2675 | * @publicApi
|
2676 | */
|
2677 | var NgClass = /** @class */ (function () {
|
2678 | function NgClass(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) {
|
2679 | this._iterableDiffers = _iterableDiffers;
|
2680 | this._keyValueDiffers = _keyValueDiffers;
|
2681 | this._ngEl = _ngEl;
|
2682 | this._renderer = _renderer;
|
2683 | this._iterableDiffer = null;
|
2684 | this._keyValueDiffer = null;
|
2685 | this._initialClasses = [];
|
2686 | this._rawClass = null;
|
2687 | }
|
2688 | Object.defineProperty(NgClass.prototype, "klass", {
|
2689 | set: function (value) {
|
2690 | this._removeClasses(this._initialClasses);
|
2691 | this._initialClasses = typeof value === 'string' ? value.split(/\s+/) : [];
|
2692 | this._applyClasses(this._initialClasses);
|
2693 | this._applyClasses(this._rawClass);
|
2694 | },
|
2695 | enumerable: true,
|
2696 | configurable: true
|
2697 | });
|
2698 | Object.defineProperty(NgClass.prototype, "ngClass", {
|
2699 | set: function (value) {
|
2700 | this._removeClasses(this._rawClass);
|
2701 | this._applyClasses(this._initialClasses);
|
2702 | this._iterableDiffer = null;
|
2703 | this._keyValueDiffer = null;
|
2704 | this._rawClass = typeof value === 'string' ? value.split(/\s+/) : value;
|
2705 | if (this._rawClass) {
|
2706 | if (ɵisListLikeIterable(this._rawClass)) {
|
2707 | this._iterableDiffer = this._iterableDiffers.find(this._rawClass).create();
|
2708 | }
|
2709 | else {
|
2710 | this._keyValueDiffer = this._keyValueDiffers.find(this._rawClass).create();
|
2711 | }
|
2712 | }
|
2713 | },
|
2714 | enumerable: true,
|
2715 | configurable: true
|
2716 | });
|
2717 | NgClass.prototype.ngDoCheck = function () {
|
2718 | if (this._iterableDiffer) {
|
2719 | var iterableChanges = this._iterableDiffer.diff(this._rawClass);
|
2720 | if (iterableChanges) {
|
2721 | this._applyIterableChanges(iterableChanges);
|
2722 | }
|
2723 | }
|
2724 | else if (this._keyValueDiffer) {
|
2725 | var keyValueChanges = this._keyValueDiffer.diff(this._rawClass);
|
2726 | if (keyValueChanges) {
|
2727 | this._applyKeyValueChanges(keyValueChanges);
|
2728 | }
|
2729 | }
|
2730 | };
|
2731 | NgClass.prototype._applyKeyValueChanges = function (changes) {
|
2732 | var _this = this;
|
2733 | changes.forEachAddedItem(function (record) { return _this._toggleClass(record.key, record.currentValue); });
|
2734 | changes.forEachChangedItem(function (record) { return _this._toggleClass(record.key, record.currentValue); });
|
2735 | changes.forEachRemovedItem(function (record) {
|
2736 | if (record.previousValue) {
|
2737 | _this._toggleClass(record.key, false);
|
2738 | }
|
2739 | });
|
2740 | };
|
2741 | NgClass.prototype._applyIterableChanges = function (changes) {
|
2742 | var _this = this;
|
2743 | changes.forEachAddedItem(function (record) {
|
2744 | if (typeof record.item === 'string') {
|
2745 | _this._toggleClass(record.item, true);
|
2746 | }
|
2747 | else {
|
2748 | throw new Error("NgClass can only toggle CSS classes expressed as strings, got " + ɵstringify(record.item));
|
2749 | }
|
2750 | });
|
2751 | changes.forEachRemovedItem(function (record) { return _this._toggleClass(record.item, false); });
|
2752 | };
|
2753 | /**
|
2754 | * Applies a collection of CSS classes to the DOM element.
|
2755 | *
|
2756 | * For argument of type Set and Array CSS class names contained in those collections are always
|
2757 | * added.
|
2758 | * For argument of type Map CSS class name in the map's key is toggled based on the value (added
|
2759 | * for truthy and removed for falsy).
|
2760 | */
|
2761 | NgClass.prototype._applyClasses = function (rawClassVal) {
|
2762 | var _this = this;
|
2763 | if (rawClassVal) {
|
2764 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
2765 | rawClassVal.forEach(function (klass) { return _this._toggleClass(klass, true); });
|
2766 | }
|
2767 | else {
|
2768 | Object.keys(rawClassVal).forEach(function (klass) { return _this._toggleClass(klass, !!rawClassVal[klass]); });
|
2769 | }
|
2770 | }
|
2771 | };
|
2772 | /**
|
2773 | * Removes a collection of CSS classes from the DOM element. This is mostly useful for cleanup
|
2774 | * purposes.
|
2775 | */
|
2776 | NgClass.prototype._removeClasses = function (rawClassVal) {
|
2777 | var _this = this;
|
2778 | if (rawClassVal) {
|
2779 | if (Array.isArray(rawClassVal) || rawClassVal instanceof Set) {
|
2780 | rawClassVal.forEach(function (klass) { return _this._toggleClass(klass, false); });
|
2781 | }
|
2782 | else {
|
2783 | Object.keys(rawClassVal).forEach(function (klass) { return _this._toggleClass(klass, false); });
|
2784 | }
|
2785 | }
|
2786 | };
|
2787 | NgClass.prototype._toggleClass = function (klass, enabled) {
|
2788 | var _this = this;
|
2789 | klass = klass.trim();
|
2790 | if (klass) {
|
2791 | klass.split(/\s+/g).forEach(function (klass) {
|
2792 | if (enabled) {
|
2793 | _this._renderer.addClass(_this._ngEl.nativeElement, klass);
|
2794 | }
|
2795 | else {
|
2796 | _this._renderer.removeClass(_this._ngEl.nativeElement, klass);
|
2797 | }
|
2798 | });
|
2799 | }
|
2800 | };
|
2801 | __decorate([
|
2802 | Input('class'),
|
2803 | __metadata("design:type", String),
|
2804 | __metadata("design:paramtypes", [String])
|
2805 | ], NgClass.prototype, "klass", null);
|
2806 | __decorate([
|
2807 | Input('ngClass'),
|
2808 | __metadata("design:type", Object),
|
2809 | __metadata("design:paramtypes", [Object])
|
2810 | ], NgClass.prototype, "ngClass", null);
|
2811 | NgClass = __decorate([
|
2812 | Directive({ selector: '[ngClass]' }),
|
2813 | __metadata("design:paramtypes", [IterableDiffers, KeyValueDiffers,
|
2814 | ElementRef, Renderer2])
|
2815 | ], NgClass);
|
2816 | return NgClass;
|
2817 | }());
|
2818 |
|
2819 | /**
|
2820 | * @license
|
2821 | * Copyright Google Inc. All Rights Reserved.
|
2822 | *
|
2823 | * Use of this source code is governed by an MIT-style license that can be
|
2824 | * found in the LICENSE file at https://angular.io/license
|
2825 | */
|
2826 | /**
|
2827 | * Instantiates a single {@link Component} type and inserts its Host View into current View.
|
2828 | * `NgComponentOutlet` provides a declarative approach for dynamic component creation.
|
2829 | *
|
2830 | * `NgComponentOutlet` requires a component type, if a falsy value is set the view will clear and
|
2831 | * any existing component will get destroyed.
|
2832 | *
|
2833 | * @usageNotes
|
2834 | *
|
2835 | * ### Fine tune control
|
2836 | *
|
2837 | * You can control the component creation process by using the following optional attributes:
|
2838 | *
|
2839 | * * `ngComponentOutletInjector`: Optional custom {@link Injector} that will be used as parent for
|
2840 | * the Component. Defaults to the injector of the current view container.
|
2841 | *
|
2842 | * * `ngComponentOutletContent`: Optional list of projectable nodes to insert into the content
|
2843 | * section of the component, if exists.
|
2844 | *
|
2845 | * * `ngComponentOutletNgModuleFactory`: Optional module factory to allow dynamically loading other
|
2846 | * module, then load a component from that module.
|
2847 | *
|
2848 | * ### Syntax
|
2849 | *
|
2850 | * Simple
|
2851 | * ```
|
2852 | * <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container>
|
2853 | * ```
|
2854 | *
|
2855 | * Customized injector/content
|
2856 | * ```
|
2857 | * <ng-container *ngComponentOutlet="componentTypeExpression;
|
2858 | * injector: injectorExpression;
|
2859 | * content: contentNodesExpression;">
|
2860 | * </ng-container>
|
2861 | * ```
|
2862 | *
|
2863 | * Customized ngModuleFactory
|
2864 | * ```
|
2865 | * <ng-container *ngComponentOutlet="componentTypeExpression;
|
2866 | * ngModuleFactory: moduleFactory;">
|
2867 | * </ng-container>
|
2868 | * ```
|
2869 | *
|
2870 | * ### A simple example
|
2871 | *
|
2872 | * {@example common/ngComponentOutlet/ts/module.ts region='SimpleExample'}
|
2873 | *
|
2874 | * A more complete example with additional options:
|
2875 | *
|
2876 | * {@example common/ngComponentOutlet/ts/module.ts region='CompleteExample'}
|
2877 | *
|
2878 | * @publicApi
|
2879 | * @ngModule CommonModule
|
2880 | */
|
2881 | var NgComponentOutlet = /** @class */ (function () {
|
2882 | function NgComponentOutlet(_viewContainerRef) {
|
2883 | this._viewContainerRef = _viewContainerRef;
|
2884 | this._componentRef = null;
|
2885 | this._moduleRef = null;
|
2886 | }
|
2887 | NgComponentOutlet.prototype.ngOnChanges = function (changes) {
|
2888 | this._viewContainerRef.clear();
|
2889 | this._componentRef = null;
|
2890 | if (this.ngComponentOutlet) {
|
2891 | var elInjector = this.ngComponentOutletInjector || this._viewContainerRef.parentInjector;
|
2892 | if (changes['ngComponentOutletNgModuleFactory']) {
|
2893 | if (this._moduleRef)
|
2894 | this._moduleRef.destroy();
|
2895 | if (this.ngComponentOutletNgModuleFactory) {
|
2896 | var parentModule = elInjector.get(NgModuleRef);
|
2897 | this._moduleRef = this.ngComponentOutletNgModuleFactory.create(parentModule.injector);
|
2898 | }
|
2899 | else {
|
2900 | this._moduleRef = null;
|
2901 | }
|
2902 | }
|
2903 | var componentFactoryResolver = this._moduleRef ? this._moduleRef.componentFactoryResolver :
|
2904 | elInjector.get(ComponentFactoryResolver);
|
2905 | var componentFactory = componentFactoryResolver.resolveComponentFactory(this.ngComponentOutlet);
|
2906 | this._componentRef = this._viewContainerRef.createComponent(componentFactory, this._viewContainerRef.length, elInjector, this.ngComponentOutletContent);
|
2907 | }
|
2908 | };
|
2909 | NgComponentOutlet.prototype.ngOnDestroy = function () {
|
2910 | if (this._moduleRef)
|
2911 | this._moduleRef.destroy();
|
2912 | };
|
2913 | __decorate([
|
2914 | Input(),
|
2915 | __metadata("design:type", Type)
|
2916 | ], NgComponentOutlet.prototype, "ngComponentOutlet", void 0);
|
2917 | __decorate([
|
2918 | Input(),
|
2919 | __metadata("design:type", Injector)
|
2920 | ], NgComponentOutlet.prototype, "ngComponentOutletInjector", void 0);
|
2921 | __decorate([
|
2922 | Input(),
|
2923 | __metadata("design:type", Array)
|
2924 | ], NgComponentOutlet.prototype, "ngComponentOutletContent", void 0);
|
2925 | __decorate([
|
2926 | Input(),
|
2927 | __metadata("design:type", NgModuleFactory)
|
2928 | ], NgComponentOutlet.prototype, "ngComponentOutletNgModuleFactory", void 0);
|
2929 | NgComponentOutlet = __decorate([
|
2930 | Directive({ selector: '[ngComponentOutlet]' }),
|
2931 | __metadata("design:paramtypes", [ViewContainerRef])
|
2932 | ], NgComponentOutlet);
|
2933 | return NgComponentOutlet;
|
2934 | }());
|
2935 |
|
2936 | /**
|
2937 | * @license
|
2938 | * Copyright Google Inc. All Rights Reserved.
|
2939 | *
|
2940 | * Use of this source code is governed by an MIT-style license that can be
|
2941 | * found in the LICENSE file at https://angular.io/license
|
2942 | */
|
2943 | /**
|
2944 | * @publicApi
|
2945 | */
|
2946 | var NgForOfContext = /** @class */ (function () {
|
2947 | function NgForOfContext($implicit, ngForOf, index, count) {
|
2948 | this.$implicit = $implicit;
|
2949 | this.ngForOf = ngForOf;
|
2950 | this.index = index;
|
2951 | this.count = count;
|
2952 | }
|
2953 | Object.defineProperty(NgForOfContext.prototype, "first", {
|
2954 | get: function () { return this.index === 0; },
|
2955 | enumerable: true,
|
2956 | configurable: true
|
2957 | });
|
2958 | Object.defineProperty(NgForOfContext.prototype, "last", {
|
2959 | get: function () { return this.index === this.count - 1; },
|
2960 | enumerable: true,
|
2961 | configurable: true
|
2962 | });
|
2963 | Object.defineProperty(NgForOfContext.prototype, "even", {
|
2964 | get: function () { return this.index % 2 === 0; },
|
2965 | enumerable: true,
|
2966 | configurable: true
|
2967 | });
|
2968 | Object.defineProperty(NgForOfContext.prototype, "odd", {
|
2969 | get: function () { return !this.even; },
|
2970 | enumerable: true,
|
2971 | configurable: true
|
2972 | });
|
2973 | return NgForOfContext;
|
2974 | }());
|
2975 | /**
|
2976 | * A [structural directive](guide/structural-directives) that renders
|
2977 | * a template for each item in a collection.
|
2978 | * The directive is placed on an element, which becomes the parent
|
2979 | * of the cloned templates.
|
2980 | *
|
2981 | * The `ngForOf` directive is generally used in the
|
2982 | * [shorthand form](guide/structural-directives#the-asterisk--prefix) `*ngFor`.
|
2983 | * In this form, the template to be rendered for each iteration is the content
|
2984 | * of an anchor element containing the directive.
|
2985 | *
|
2986 | * The following example shows the shorthand syntax with some options,
|
2987 | * contained in an `<li>` element.
|
2988 | *
|
2989 | * ```
|
2990 | * <li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>
|
2991 | * ```
|
2992 | *
|
2993 | * The shorthand form expands into a long form that uses the `ngForOf` selector
|
2994 | * on an `<ng-template>` element.
|
2995 | * The content of the `<ng-template>` element is the `<li>` element that held the
|
2996 | * short-form directive.
|
2997 | *
|
2998 | * Here is the expanded version of the short-form example.
|
2999 | *
|
3000 | * ```
|
3001 | * <ng-template ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
|
3002 | * <li>...</li>
|
3003 | * </ng-template>
|
3004 | * ```
|
3005 | *
|
3006 | * Angular automatically expands the shorthand syntax as it compiles the template.
|
3007 | * The context for each embedded view is logically merged to the current component
|
3008 | * context according to its lexical position.
|
3009 | *
|
3010 | * When using the shorthand syntax, Angular allows only [one structural directive
|
3011 | * on an element](guide/structural-directives#one-structural-directive-per-host-element).
|
3012 | * If you want to iterate conditionally, for example,
|
3013 | * put the `*ngIf` on a container element that wraps the `*ngFor` element.
|
3014 | * For futher discussion, see
|
3015 | * [Structural Directives](guide/structural-directives#one-per-element).
|
3016 | *
|
3017 | * @usageNotes
|
3018 | *
|
3019 | * ### Local variables
|
3020 | *
|
3021 | * `NgForOf` provides exported values that can be aliased to local variables.
|
3022 | * For example:
|
3023 | *
|
3024 | * ```
|
3025 | * <li *ngFor="let user of users; index as i; first as isFirst">
|
3026 | * {{i}}/{{users.length}}. {{user}} <span *ngIf="isFirst">default</span>
|
3027 | * </li>
|
3028 | * ```
|
3029 | *
|
3030 | * The following exported values can be aliased to local variables:
|
3031 | *
|
3032 | * - `$implicit: T`: The value of the individual items in the iterable (`ngForOf`).
|
3033 | * - `ngForOf: NgIterable<T>`: The value of the iterable expression. Useful when the expression is
|
3034 | * more complex then a property access, for example when using the async pipe (`userStreams |
|
3035 | * async`).
|
3036 | * - `index: number`: The index of the current item in the iterable.
|
3037 | * - `first: boolean`: True when the item is the first item in the iterable.
|
3038 | * - `last: boolean`: True when the item is the last item in the iterable.
|
3039 | * - `even: boolean`: True when the item has an even index in the iterable.
|
3040 | * - `odd: boolean`: True when the item has an odd index in the iterable.
|
3041 | *
|
3042 | * ### Change propagation
|
3043 | *
|
3044 | * When the contents of the iterator changes, `NgForOf` makes the corresponding changes to the DOM:
|
3045 | *
|
3046 | * * When an item is added, a new instance of the template is added to the DOM.
|
3047 | * * When an item is removed, its template instance is removed from the DOM.
|
3048 | * * When items are reordered, their respective templates are reordered in the DOM.
|
3049 | *
|
3050 | * Angular uses object identity to track insertions and deletions within the iterator and reproduce
|
3051 | * those changes in the DOM. This has important implications for animations and any stateful
|
3052 | * controls that are present, such as `<input>` elements that accept user input. Inserted rows can
|
3053 | * be animated in, deleted rows can be animated out, and unchanged rows retain any unsaved state
|
3054 | * such as user input.
|
3055 | * For more on animations, see [Transitions and Triggers](guide/transition-and-triggers).
|
3056 | *
|
3057 | * The identities of elements in the iterator can change while the data does not.
|
3058 | * This can happen, for example, if the iterator is produced from an RPC to the server, and that
|
3059 | * RPC is re-run. Even if the data hasn't changed, the second response produces objects with
|
3060 | * different identities, and Angular must tear down the entire DOM and rebuild it (as if all old
|
3061 | * elements were deleted and all new elements inserted).
|
3062 | *
|
3063 | * To avoid this expensive operation, you can customize the default tracking algorithm.
|
3064 | * by supplying the `trackBy` option to `NgForOf`.
|
3065 | * `trackBy` takes a function that has two arguments: `index` and `item`.
|
3066 | * If `trackBy` is given, Angular tracks changes by the return value of the function.
|
3067 | *
|
3068 | * @see [Structural Directives](guide/structural-directives)
|
3069 | * @ngModule CommonModule
|
3070 | * @publicApi
|
3071 | */
|
3072 | var NgForOf = /** @class */ (function () {
|
3073 | function NgForOf(_viewContainer, _template, _differs) {
|
3074 | this._viewContainer = _viewContainer;
|
3075 | this._template = _template;
|
3076 | this._differs = _differs;
|
3077 | this._ngForOf = null;
|
3078 | this._ngForOfDirty = true;
|
3079 | this._differ = null;
|
3080 | }
|
3081 | Object.defineProperty(NgForOf.prototype, "ngForOf", {
|
3082 | /**
|
3083 | * The value of the iterable expression, which can be used as a
|
3084 | * [template input variable](guide/structural-directives#template-input-variable).
|
3085 | */
|
3086 | set: function (ngForOf) {
|
3087 | this._ngForOf = ngForOf;
|
3088 | this._ngForOfDirty = true;
|
3089 | },
|
3090 | enumerable: true,
|
3091 | configurable: true
|
3092 | });
|
3093 | Object.defineProperty(NgForOf.prototype, "ngForTrackBy", {
|
3094 | get: function () { return this._trackByFn; },
|
3095 | /**
|
3096 | * A function that defines how to track changes for items in the iterable.
|
3097 | *
|
3098 | * When items are added, moved, or removed in the iterable,
|
3099 | * the directive must re-render the appropriate DOM nodes.
|
3100 | * To minimize churn in the DOM, only nodes that have changed
|
3101 | * are re-rendered.
|
3102 | *
|
3103 | * By default, the change detector assumes that
|
3104 | * the object instance identifies the node in the iterable.
|
3105 | * When this function is supplied, the directive uses
|
3106 | * the result of calling this function to identify the item node,
|
3107 | * rather than the identity of the object itself.
|
3108 | *
|
3109 | * The function receives two inputs,
|
3110 | * the iteration index and the node object ID.
|
3111 | */
|
3112 | set: function (fn) {
|
3113 | if (isDevMode() && fn != null && typeof fn !== 'function') {
|
3114 | // TODO(vicb): use a log service once there is a public one available
|
3115 | if (console && console.warn) {
|
3116 | console.warn("trackBy must be a function, but received " + JSON.stringify(fn) + ". " +
|
3117 | "See https://angular.io/api/common/NgForOf#change-propagation for more information.");
|
3118 | }
|
3119 | }
|
3120 | this._trackByFn = fn;
|
3121 | },
|
3122 | enumerable: true,
|
3123 | configurable: true
|
3124 | });
|
3125 | Object.defineProperty(NgForOf.prototype, "ngForTemplate", {
|
3126 | /**
|
3127 | * A reference to the template that is stamped out for each item in the iterable.
|
3128 | * @see [template reference variable](guide/template-syntax#template-reference-variables--var-)
|
3129 | */
|
3130 | set: function (value) {
|
3131 | // TODO(TS2.1): make TemplateRef<Partial<NgForRowOf<T>>> once we move to TS v2.1
|
3132 | // The current type is too restrictive; a template that just uses index, for example,
|
3133 | // should be acceptable.
|
3134 | if (value) {
|
3135 | this._template = value;
|
3136 | }
|
3137 | },
|
3138 | enumerable: true,
|
3139 | configurable: true
|
3140 | });
|
3141 | /**
|
3142 | * Applies the changes when needed.
|
3143 | */
|
3144 | NgForOf.prototype.ngDoCheck = function () {
|
3145 | if (this._ngForOfDirty) {
|
3146 | this._ngForOfDirty = false;
|
3147 | // React on ngForOf changes only once all inputs have been initialized
|
3148 | var value = this._ngForOf;
|
3149 | if (!this._differ && value) {
|
3150 | try {
|
3151 | this._differ = this._differs.find(value).create(this.ngForTrackBy);
|
3152 | }
|
3153 | catch (_a) {
|
3154 | throw new Error("Cannot find a differ supporting object '" + value + "' of type '" + getTypeName(value) + "'. NgFor only supports binding to Iterables such as Arrays.");
|
3155 | }
|
3156 | }
|
3157 | }
|
3158 | if (this._differ) {
|
3159 | var changes = this._differ.diff(this._ngForOf);
|
3160 | if (changes)
|
3161 | this._applyChanges(changes);
|
3162 | }
|
3163 | };
|
3164 | NgForOf.prototype._applyChanges = function (changes) {
|
3165 | var _this = this;
|
3166 | var insertTuples = [];
|
3167 | changes.forEachOperation(function (item, adjustedPreviousIndex, currentIndex) {
|
3168 | if (item.previousIndex == null) {
|
3169 | // NgForOf is never "null" or "undefined" here because the differ detected
|
3170 | // that a new item needs to be inserted from the iterable. This implies that
|
3171 | // there is an iterable value for "_ngForOf".
|
3172 | var view = _this._viewContainer.createEmbeddedView(_this._template, new NgForOfContext(null, _this._ngForOf, -1, -1), currentIndex === null ? undefined : currentIndex);
|
3173 | var tuple = new RecordViewTuple(item, view);
|
3174 | insertTuples.push(tuple);
|
3175 | }
|
3176 | else if (currentIndex == null) {
|
3177 | _this._viewContainer.remove(adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex);
|
3178 | }
|
3179 | else if (adjustedPreviousIndex !== null) {
|
3180 | var view = _this._viewContainer.get(adjustedPreviousIndex);
|
3181 | _this._viewContainer.move(view, currentIndex);
|
3182 | var tuple = new RecordViewTuple(item, view);
|
3183 | insertTuples.push(tuple);
|
3184 | }
|
3185 | });
|
3186 | for (var i = 0; i < insertTuples.length; i++) {
|
3187 | this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
3188 | }
|
3189 | for (var i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
|
3190 | var viewRef = this._viewContainer.get(i);
|
3191 | viewRef.context.index = i;
|
3192 | viewRef.context.count = ilen;
|
3193 | viewRef.context.ngForOf = this._ngForOf;
|
3194 | }
|
3195 | changes.forEachIdentityChange(function (record) {
|
3196 | var viewRef = _this._viewContainer.get(record.currentIndex);
|
3197 | viewRef.context.$implicit = record.item;
|
3198 | });
|
3199 | };
|
3200 | NgForOf.prototype._perViewChange = function (view, record) {
|
3201 | view.context.$implicit = record.item;
|
3202 | };
|
3203 | /**
|
3204 | * Asserts the correct type of the context for the template that `NgForOf` will render.
|
3205 | *
|
3206 | * The presence of this method is a signal to the Ivy template type-check compiler that the
|
3207 | * `NgForOf` structural directive renders its template with a specific context type.
|
3208 | */
|
3209 | NgForOf.ngTemplateContextGuard = function (dir, ctx) {
|
3210 | return true;
|
3211 | };
|
3212 | __decorate([
|
3213 | Input(),
|
3214 | __metadata("design:type", Object),
|
3215 | __metadata("design:paramtypes", [Object])
|
3216 | ], NgForOf.prototype, "ngForOf", null);
|
3217 | __decorate([
|
3218 | Input(),
|
3219 | __metadata("design:type", Function),
|
3220 | __metadata("design:paramtypes", [Function])
|
3221 | ], NgForOf.prototype, "ngForTrackBy", null);
|
3222 | __decorate([
|
3223 | Input(),
|
3224 | __metadata("design:type", TemplateRef),
|
3225 | __metadata("design:paramtypes", [TemplateRef])
|
3226 | ], NgForOf.prototype, "ngForTemplate", null);
|
3227 | NgForOf = __decorate([
|
3228 | Directive({ selector: '[ngFor][ngForOf]' }),
|
3229 | __metadata("design:paramtypes", [ViewContainerRef,
|
3230 | TemplateRef, IterableDiffers])
|
3231 | ], NgForOf);
|
3232 | return NgForOf;
|
3233 | }());
|
3234 | var RecordViewTuple = /** @class */ (function () {
|
3235 | function RecordViewTuple(record, view) {
|
3236 | this.record = record;
|
3237 | this.view = view;
|
3238 | }
|
3239 | return RecordViewTuple;
|
3240 | }());
|
3241 | function getTypeName(type) {
|
3242 | return type['name'] || typeof type;
|
3243 | }
|
3244 |
|
3245 | /**
|
3246 | * @license
|
3247 | * Copyright Google Inc. All Rights Reserved.
|
3248 | *
|
3249 | * Use of this source code is governed by an MIT-style license that can be
|
3250 | * found in the LICENSE file at https://angular.io/license
|
3251 | */
|
3252 | /**
|
3253 | * A structural directive that conditionally includes a template based on the value of
|
3254 | * an expression coerced to Boolean.
|
3255 | * When the expression evaluates to true, Angular renders the template
|
3256 | * provided in a `then` clause, and when false or null,
|
3257 | * Angular renders the template provided in an optional `else` clause. The default
|
3258 | * template for the `else` clause is blank.
|
3259 | *
|
3260 | * A [shorthand form](guide/structural-directives#the-asterisk--prefix) of the directive,
|
3261 | * `*ngIf="condition"`, is generally used, provided
|
3262 | * as an attribute of the anchor element for the inserted template.
|
3263 | * Angular expands this into a more explicit version, in which the anchor element
|
3264 | * is contained in an `<ng-template>` element.
|
3265 | *
|
3266 | * Simple form with shorthand syntax:
|
3267 | *
|
3268 | * ```
|
3269 | * <div *ngIf="condition">Content to render when condition is true.</div>
|
3270 | * ```
|
3271 | *
|
3272 | * Simple form with expanded syntax:
|
3273 | *
|
3274 | * ```
|
3275 | * <ng-template [ngIf]="condition"><div>Content to render when condition is
|
3276 | * true.</div></ng-template>
|
3277 | * ```
|
3278 | *
|
3279 | * Form with an "else" block:
|
3280 | *
|
3281 | * ```
|
3282 | * <div *ngIf="condition; else elseBlock">Content to render when condition is true.</div>
|
3283 | * <ng-template #elseBlock>Content to render when condition is false.</ng-template>
|
3284 | * ```
|
3285 | *
|
3286 | * Shorthand form with "then" and "else" blocks:
|
3287 | *
|
3288 | * ```
|
3289 | * <div *ngIf="condition; then thenBlock else elseBlock"></div>
|
3290 | * <ng-template #thenBlock>Content to render when condition is true.</ng-template>
|
3291 | * <ng-template #elseBlock>Content to render when condition is false.</ng-template>
|
3292 | * ```
|
3293 | *
|
3294 | * Form with storing the value locally:
|
3295 | *
|
3296 | * ```
|
3297 | * <div *ngIf="condition as value; else elseBlock">{{value}}</div>
|
3298 | * <ng-template #elseBlock>Content to render when value is null.</ng-template>
|
3299 | * ```
|
3300 | *
|
3301 | * @usageNotes
|
3302 | *
|
3303 | * The `*ngIf` directive is most commonly used to conditionally show an inline template,
|
3304 | * as seen in the following example.
|
3305 | * The default `else` template is blank.
|
3306 | *
|
3307 | * {@example common/ngIf/ts/module.ts region='NgIfSimple'}
|
3308 | *
|
3309 | * ### Showing an alternative template using `else`
|
3310 | *
|
3311 | * To display a template when `expression` evaluates to false, use an `else` template
|
3312 | * binding as shown in the following example.
|
3313 | * The `else` binding points to an `<ng-template>` element labeled `#elseBlock`.
|
3314 | * The template can be defined anywhere in the component view, but is typically placed right after
|
3315 | * `ngIf` for readability.
|
3316 | *
|
3317 | * {@example common/ngIf/ts/module.ts region='NgIfElse'}
|
3318 | *
|
3319 | * ### Using an external `then` template
|
3320 | *
|
3321 | * In the previous example, the then-clause template is specified inline, as the content of the
|
3322 | * tag that contains the `ngIf` directive. You can also specify a template that is defined
|
3323 | * externally, by referencing a labeled `<ng-template>` element. When you do this, you can
|
3324 | * change which template to use at runtime, as shown in the following example.
|
3325 | *
|
3326 | * {@example common/ngIf/ts/module.ts region='NgIfThenElse'}
|
3327 | *
|
3328 | * ### Storing a conditional result in a variable
|
3329 | *
|
3330 | * You might want to show a set of properties from the same object. If you are waiting
|
3331 | * for asynchronous data, the object can be undefined.
|
3332 | * In this case, you can use `ngIf` and store the result of the condition in a local
|
3333 | * variable as shown in the the following example.
|
3334 | *
|
3335 | * {@example common/ngIf/ts/module.ts region='NgIfAs'}
|
3336 | *
|
3337 | * This code uses only one `AsyncPipe`, so only one subscription is created.
|
3338 | * The conditional statement stores the result of `userStream|async` in the local variable `user`.
|
3339 | * You can then bind the local `user` repeatedly.
|
3340 | *
|
3341 | * The conditional displays the data only if `userStream` returns a value,
|
3342 | * so you don't need to use the
|
3343 | * [safe-navigation-operator](guide/template-syntax#safe-navigation-operator) (`?.`)
|
3344 | * to guard against null values when accessing properties.
|
3345 | * You can display an alternative template while waiting for the data.
|
3346 | *
|
3347 | * ### Shorthand syntax
|
3348 | *
|
3349 | * The shorthand syntax `*ngIf` expands into two separate template specifications
|
3350 | * for the "then" and "else" clauses. For example, consider the following shorthand statement,
|
3351 | * that is meant to show a loading page while waiting for data to be loaded.
|
3352 | *
|
3353 | * ```
|
3354 | * <div class="hero-list" *ngIf="heroes else loading">
|
3355 | * ...
|
3356 | * </div>
|
3357 | *
|
3358 | * <ng-template #loading>
|
3359 | * <div>Loading...</div>
|
3360 | * </ng-template>
|
3361 | * ```
|
3362 | *
|
3363 | * You can see that the "else" clause references the `<ng-template>`
|
3364 | * with the `#loading` label, and the template for the "then" clause
|
3365 | * is provided as the content of the anchor element.
|
3366 | *
|
3367 | * However, when Angular expands the shorthand syntax, it creates
|
3368 | * another `<ng-template>` tag, with `ngIf` and `ngIfElse` directives.
|
3369 | * The anchor element containing the template for the "then" clause becomes
|
3370 | * the content of this unlabeled `<ng-template>` tag.
|
3371 | *
|
3372 | * ```
|
3373 | * <ng-template [ngIf]="heroes" [ngIfElse]="loading">
|
3374 | * <div class="hero-list">
|
3375 | * ...
|
3376 | * </div>
|
3377 | * </ng-template>
|
3378 | *
|
3379 | * <ng-template #loading>
|
3380 | * <div>Loading...</div>
|
3381 | * </ng-template>
|
3382 | * ```
|
3383 | *
|
3384 | * The presence of the implicit template object has implications for the nesting of
|
3385 | * structural directives. For more on this subject, see
|
3386 | * [Structural Directives](https://angular.io/guide/structural-directives#one-per-element).
|
3387 | *
|
3388 | * @ngModule CommonModule
|
3389 | * @publicApi
|
3390 | */
|
3391 | var NgIf = /** @class */ (function () {
|
3392 | function NgIf(_viewContainer, templateRef) {
|
3393 | this._viewContainer = _viewContainer;
|
3394 | this._context = new NgIfContext();
|
3395 | this._thenTemplateRef = null;
|
3396 | this._elseTemplateRef = null;
|
3397 | this._thenViewRef = null;
|
3398 | this._elseViewRef = null;
|
3399 | this._thenTemplateRef = templateRef;
|
3400 | }
|
3401 | Object.defineProperty(NgIf.prototype, "ngIf", {
|
3402 | /**
|
3403 | * The Boolean expression to evaluate as the condition for showing a template.
|
3404 | */
|
3405 | set: function (condition) {
|
3406 | this._context.$implicit = this._context.ngIf = condition;
|
3407 | this._updateView();
|
3408 | },
|
3409 | enumerable: true,
|
3410 | configurable: true
|
3411 | });
|
3412 | Object.defineProperty(NgIf.prototype, "ngIfThen", {
|
3413 | /**
|
3414 | * A template to show if the condition expression evaluates to true.
|
3415 | */
|
3416 | set: function (templateRef) {
|
3417 | assertTemplate('ngIfThen', templateRef);
|
3418 | this._thenTemplateRef = templateRef;
|
3419 | this._thenViewRef = null; // clear previous view if any.
|
3420 | this._updateView();
|
3421 | },
|
3422 | enumerable: true,
|
3423 | configurable: true
|
3424 | });
|
3425 | Object.defineProperty(NgIf.prototype, "ngIfElse", {
|
3426 | /**
|
3427 | * A template to show if the condition expression evaluates to false.
|
3428 | */
|
3429 | set: function (templateRef) {
|
3430 | assertTemplate('ngIfElse', templateRef);
|
3431 | this._elseTemplateRef = templateRef;
|
3432 | this._elseViewRef = null; // clear previous view if any.
|
3433 | this._updateView();
|
3434 | },
|
3435 | enumerable: true,
|
3436 | configurable: true
|
3437 | });
|
3438 | NgIf.prototype._updateView = function () {
|
3439 | if (this._context.$implicit) {
|
3440 | if (!this._thenViewRef) {
|
3441 | this._viewContainer.clear();
|
3442 | this._elseViewRef = null;
|
3443 | if (this._thenTemplateRef) {
|
3444 | this._thenViewRef =
|
3445 | this._viewContainer.createEmbeddedView(this._thenTemplateRef, this._context);
|
3446 | }
|
3447 | }
|
3448 | }
|
3449 | else {
|
3450 | if (!this._elseViewRef) {
|
3451 | this._viewContainer.clear();
|
3452 | this._thenViewRef = null;
|
3453 | if (this._elseTemplateRef) {
|
3454 | this._elseViewRef =
|
3455 | this._viewContainer.createEmbeddedView(this._elseTemplateRef, this._context);
|
3456 | }
|
3457 | }
|
3458 | }
|
3459 | };
|
3460 | /**
|
3461 | * Asserts the correct type of the context for the template that `NgIf` will render.
|
3462 | *
|
3463 | * The presence of this method is a signal to the Ivy template type-check compiler that the
|
3464 | * `NgIf` structural directive renders its template with a specific context type.
|
3465 | */
|
3466 | NgIf.ngTemplateContextGuard = function (dir, ctx) { return true; };
|
3467 | __decorate([
|
3468 | Input(),
|
3469 | __metadata("design:type", Object),
|
3470 | __metadata("design:paramtypes", [Object])
|
3471 | ], NgIf.prototype, "ngIf", null);
|
3472 | __decorate([
|
3473 | Input(),
|
3474 | __metadata("design:type", Object),
|
3475 | __metadata("design:paramtypes", [Object])
|
3476 | ], NgIf.prototype, "ngIfThen", null);
|
3477 | __decorate([
|
3478 | Input(),
|
3479 | __metadata("design:type", Object),
|
3480 | __metadata("design:paramtypes", [Object])
|
3481 | ], NgIf.prototype, "ngIfElse", null);
|
3482 | NgIf = __decorate([
|
3483 | Directive({ selector: '[ngIf]' }),
|
3484 | __metadata("design:paramtypes", [ViewContainerRef, TemplateRef])
|
3485 | ], NgIf);
|
3486 | return NgIf;
|
3487 | }());
|
3488 | /**
|
3489 | * @publicApi
|
3490 | */
|
3491 | var NgIfContext = /** @class */ (function () {
|
3492 | function NgIfContext() {
|
3493 | this.$implicit = null;
|
3494 | this.ngIf = null;
|
3495 | }
|
3496 | return NgIfContext;
|
3497 | }());
|
3498 | function assertTemplate(property, templateRef) {
|
3499 | var isTemplateRefOrNull = !!(!templateRef || templateRef.createEmbeddedView);
|
3500 | if (!isTemplateRefOrNull) {
|
3501 | throw new Error(property + " must be a TemplateRef, but received '" + ɵstringify(templateRef) + "'.");
|
3502 | }
|
3503 | }
|
3504 |
|
3505 | /**
|
3506 | * @license
|
3507 | * Copyright Google Inc. All Rights Reserved.
|
3508 | *
|
3509 | * Use of this source code is governed by an MIT-style license that can be
|
3510 | * found in the LICENSE file at https://angular.io/license
|
3511 | */
|
3512 | var SwitchView = /** @class */ (function () {
|
3513 | function SwitchView(_viewContainerRef, _templateRef) {
|
3514 | this._viewContainerRef = _viewContainerRef;
|
3515 | this._templateRef = _templateRef;
|
3516 | this._created = false;
|
3517 | }
|
3518 | SwitchView.prototype.create = function () {
|
3519 | this._created = true;
|
3520 | this._viewContainerRef.createEmbeddedView(this._templateRef);
|
3521 | };
|
3522 | SwitchView.prototype.destroy = function () {
|
3523 | this._created = false;
|
3524 | this._viewContainerRef.clear();
|
3525 | };
|
3526 | SwitchView.prototype.enforceState = function (created) {
|
3527 | if (created && !this._created) {
|
3528 | this.create();
|
3529 | }
|
3530 | else if (!created && this._created) {
|
3531 | this.destroy();
|
3532 | }
|
3533 | };
|
3534 | return SwitchView;
|
3535 | }());
|
3536 | /**
|
3537 | * @ngModule CommonModule
|
3538 | *
|
3539 | * @description A structural directive that adds or removes templates (displaying or hiding views)
|
3540 | * when the next match expression matches the switch expression.
|
3541 | *
|
3542 | * The `[ngSwitch]` directive on a container specifies an expression to match against.
|
3543 | * The expressions to match are provided by `ngSwitchCase` directives on views within the container.
|
3544 | * - Every view that matches is rendered.
|
3545 | * - If there are no matches, a view with the `ngSwitchDefault` directive is rendered.
|
3546 | * - Elements within the `[NgSwitch]` statement but outside of any `NgSwitchCase`
|
3547 | * or `ngSwitchDefault` directive are preserved at the location.
|
3548 | *
|
3549 | * @usageNotes
|
3550 | * Define a container element for the directive, and specify the switch expression
|
3551 | * to match against as an attribute:
|
3552 | *
|
3553 | * ```
|
3554 | * <container-element [ngSwitch]="switch_expression">
|
3555 | * ```
|
3556 | *
|
3557 | * Within the container, `*ngSwitchCase` statements specify the match expressions
|
3558 | * as attributes. Include `*ngSwitchDefault` as the final case.
|
3559 | *
|
3560 | * ```
|
3561 | * <container-element [ngSwitch]="switch_expression">
|
3562 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
3563 | * ...
|
3564 | * <some-element *ngSwitchDefault>...</some-element>
|
3565 | * </container-element>
|
3566 | * ```
|
3567 | *
|
3568 | * ### Usage Examples
|
3569 | *
|
3570 | * The following example shows how to use more than one case to display the same view:
|
3571 | *
|
3572 | * ```
|
3573 | * <container-element [ngSwitch]="switch_expression">
|
3574 | * <!-- the same view can be shown in more than one case -->
|
3575 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
3576 | * <some-element *ngSwitchCase="match_expression_2">...</some-element>
|
3577 | * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
|
3578 | * <!--default case when there are no matches -->
|
3579 | * <some-element *ngSwitchDefault>...</some-element>
|
3580 | * </container-element>
|
3581 | * ```
|
3582 | *
|
3583 | * The following example shows how cases can be nested:
|
3584 | * ```
|
3585 | * <container-element [ngSwitch]="switch_expression">
|
3586 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
3587 | * <some-element *ngSwitchCase="match_expression_2">...</some-element>
|
3588 | * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
|
3589 | * <ng-container *ngSwitchCase="match_expression_3">
|
3590 | * <!-- use a ng-container to group multiple root nodes -->
|
3591 | * <inner-element></inner-element>
|
3592 | * <inner-other-element></inner-other-element>
|
3593 | * </ng-container>
|
3594 | * <some-element *ngSwitchDefault>...</some-element>
|
3595 | * </container-element>
|
3596 | * ```
|
3597 | *
|
3598 | * @publicApi
|
3599 | * @see `NgSwitchCase`
|
3600 | * @see `NgSwitchDefault`
|
3601 | * @see [Structural Directives](guide/structural-directives)
|
3602 | *
|
3603 | */
|
3604 | var NgSwitch = /** @class */ (function () {
|
3605 | function NgSwitch() {
|
3606 | this._defaultUsed = false;
|
3607 | this._caseCount = 0;
|
3608 | this._lastCaseCheckIndex = 0;
|
3609 | this._lastCasesMatched = false;
|
3610 | }
|
3611 | Object.defineProperty(NgSwitch.prototype, "ngSwitch", {
|
3612 | set: function (newValue) {
|
3613 | this._ngSwitch = newValue;
|
3614 | if (this._caseCount === 0) {
|
3615 | this._updateDefaultCases(true);
|
3616 | }
|
3617 | },
|
3618 | enumerable: true,
|
3619 | configurable: true
|
3620 | });
|
3621 | /** @internal */
|
3622 | NgSwitch.prototype._addCase = function () { return this._caseCount++; };
|
3623 | /** @internal */
|
3624 | NgSwitch.prototype._addDefault = function (view) {
|
3625 | if (!this._defaultViews) {
|
3626 | this._defaultViews = [];
|
3627 | }
|
3628 | this._defaultViews.push(view);
|
3629 | };
|
3630 | /** @internal */
|
3631 | NgSwitch.prototype._matchCase = function (value) {
|
3632 | var matched = value == this._ngSwitch;
|
3633 | this._lastCasesMatched = this._lastCasesMatched || matched;
|
3634 | this._lastCaseCheckIndex++;
|
3635 | if (this._lastCaseCheckIndex === this._caseCount) {
|
3636 | this._updateDefaultCases(!this._lastCasesMatched);
|
3637 | this._lastCaseCheckIndex = 0;
|
3638 | this._lastCasesMatched = false;
|
3639 | }
|
3640 | return matched;
|
3641 | };
|
3642 | NgSwitch.prototype._updateDefaultCases = function (useDefault) {
|
3643 | if (this._defaultViews && useDefault !== this._defaultUsed) {
|
3644 | this._defaultUsed = useDefault;
|
3645 | for (var i = 0; i < this._defaultViews.length; i++) {
|
3646 | var defaultView = this._defaultViews[i];
|
3647 | defaultView.enforceState(useDefault);
|
3648 | }
|
3649 | }
|
3650 | };
|
3651 | __decorate([
|
3652 | Input(),
|
3653 | __metadata("design:type", Object),
|
3654 | __metadata("design:paramtypes", [Object])
|
3655 | ], NgSwitch.prototype, "ngSwitch", null);
|
3656 | NgSwitch = __decorate([
|
3657 | Directive({ selector: '[ngSwitch]' })
|
3658 | ], NgSwitch);
|
3659 | return NgSwitch;
|
3660 | }());
|
3661 | /**
|
3662 | * @ngModule CommonModule
|
3663 | *
|
3664 | * @description
|
3665 | * Provides a switch case expression to match against an enclosing `ngSwitch` expression.
|
3666 | * When the expressions match, the given `NgSwitchCase` template is rendered.
|
3667 | * If multiple match expressions match the switch expression value, all of them are displayed.
|
3668 | *
|
3669 | * @usageNotes
|
3670 | *
|
3671 | * Within a switch container, `*ngSwitchCase` statements specify the match expressions
|
3672 | * as attributes. Include `*ngSwitchDefault` as the final case.
|
3673 | *
|
3674 | * ```
|
3675 | * <container-element [ngSwitch]="switch_expression">
|
3676 | * <some-element *ngSwitchCase="match_expression_1">...</some-element>
|
3677 | * ...
|
3678 | * <some-element *ngSwitchDefault>...</some-element>
|
3679 | * </container-element>
|
3680 | * ```
|
3681 | *
|
3682 | * Each switch-case statement contains an in-line HTML template or template reference
|
3683 | * that defines the subtree to be selected if the value of the match expression
|
3684 | * matches the value of the switch expression.
|
3685 | *
|
3686 | * Unlike JavaScript, which uses strict equality, Angular uses loose equality.
|
3687 | * This means that the empty string, `""` matches 0.
|
3688 | *
|
3689 | * @publicApi
|
3690 | * @see `NgSwitch`
|
3691 | * @see `NgSwitchDefault`
|
3692 | *
|
3693 | */
|
3694 | var NgSwitchCase = /** @class */ (function () {
|
3695 | function NgSwitchCase(viewContainer, templateRef, ngSwitch) {
|
3696 | this.ngSwitch = ngSwitch;
|
3697 | ngSwitch._addCase();
|
3698 | this._view = new SwitchView(viewContainer, templateRef);
|
3699 | }
|
3700 | /**
|
3701 | * Performs case matching. For internal use only.
|
3702 | */
|
3703 | NgSwitchCase.prototype.ngDoCheck = function () { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); };
|
3704 | __decorate([
|
3705 | Input(),
|
3706 | __metadata("design:type", Object)
|
3707 | ], NgSwitchCase.prototype, "ngSwitchCase", void 0);
|
3708 | NgSwitchCase = __decorate([
|
3709 | Directive({ selector: '[ngSwitchCase]' }),
|
3710 | __param(2, Host()),
|
3711 | __metadata("design:paramtypes", [ViewContainerRef, TemplateRef,
|
3712 | NgSwitch])
|
3713 | ], NgSwitchCase);
|
3714 | return NgSwitchCase;
|
3715 | }());
|
3716 | /**
|
3717 | * @ngModule CommonModule
|
3718 | *
|
3719 | * @description
|
3720 | *
|
3721 | * Creates a view that is rendered when no `NgSwitchCase` expressions
|
3722 | * match the `NgSwitch` expression.
|
3723 | * This statement should be the final case in an `NgSwitch`.
|
3724 | *
|
3725 | * @publicApi
|
3726 | * @see `NgSwitch`
|
3727 | * @see `NgSwitchCase`
|
3728 | *
|
3729 | */
|
3730 | var NgSwitchDefault = /** @class */ (function () {
|
3731 | function NgSwitchDefault(viewContainer, templateRef, ngSwitch) {
|
3732 | ngSwitch._addDefault(new SwitchView(viewContainer, templateRef));
|
3733 | }
|
3734 | NgSwitchDefault = __decorate([
|
3735 | Directive({ selector: '[ngSwitchDefault]' }),
|
3736 | __param(2, Host()),
|
3737 | __metadata("design:paramtypes", [ViewContainerRef, TemplateRef,
|
3738 | NgSwitch])
|
3739 | ], NgSwitchDefault);
|
3740 | return NgSwitchDefault;
|
3741 | }());
|
3742 |
|
3743 | /**
|
3744 | * @license
|
3745 | * Copyright Google Inc. All Rights Reserved.
|
3746 | *
|
3747 | * Use of this source code is governed by an MIT-style license that can be
|
3748 | * found in the LICENSE file at https://angular.io/license
|
3749 | */
|
3750 | /**
|
3751 | * @ngModule CommonModule
|
3752 | *
|
3753 | * @usageNotes
|
3754 | * ```
|
3755 | * <some-element [ngPlural]="value">
|
3756 | * <ng-template ngPluralCase="=0">there is nothing</ng-template>
|
3757 | * <ng-template ngPluralCase="=1">there is one</ng-template>
|
3758 | * <ng-template ngPluralCase="few">there are a few</ng-template>
|
3759 | * </some-element>
|
3760 | * ```
|
3761 | *
|
3762 | * @description
|
3763 | *
|
3764 | * Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization.
|
3765 | *
|
3766 | * Displays DOM sub-trees that match the switch expression value, or failing that, DOM sub-trees
|
3767 | * that match the switch expression's pluralization category.
|
3768 | *
|
3769 | * To use this directive you must provide a container element that sets the `[ngPlural]` attribute
|
3770 | * to a switch expression. Inner elements with a `[ngPluralCase]` will display based on their
|
3771 | * expression:
|
3772 | * - if `[ngPluralCase]` is set to a value starting with `=`, it will only display if the value
|
3773 | * matches the switch expression exactly,
|
3774 | * - otherwise, the view will be treated as a "category match", and will only display if exact
|
3775 | * value matches aren't found and the value maps to its category for the defined locale.
|
3776 | *
|
3777 | * See http://cldr.unicode.org/index/cldr-spec/plural-rules
|
3778 | *
|
3779 | * @publicApi
|
3780 | */
|
3781 | var NgPlural = /** @class */ (function () {
|
3782 | function NgPlural(_localization) {
|
3783 | this._localization = _localization;
|
3784 | this._caseViews = {};
|
3785 | }
|
3786 | Object.defineProperty(NgPlural.prototype, "ngPlural", {
|
3787 | set: function (value) {
|
3788 | this._switchValue = value;
|
3789 | this._updateView();
|
3790 | },
|
3791 | enumerable: true,
|
3792 | configurable: true
|
3793 | });
|
3794 | NgPlural.prototype.addCase = function (value, switchView) { this._caseViews[value] = switchView; };
|
3795 | NgPlural.prototype._updateView = function () {
|
3796 | this._clearViews();
|
3797 | var cases = Object.keys(this._caseViews);
|
3798 | var key = getPluralCategory(this._switchValue, cases, this._localization);
|
3799 | this._activateView(this._caseViews[key]);
|
3800 | };
|
3801 | NgPlural.prototype._clearViews = function () {
|
3802 | if (this._activeView)
|
3803 | this._activeView.destroy();
|
3804 | };
|
3805 | NgPlural.prototype._activateView = function (view) {
|
3806 | if (view) {
|
3807 | this._activeView = view;
|
3808 | this._activeView.create();
|
3809 | }
|
3810 | };
|
3811 | __decorate([
|
3812 | Input(),
|
3813 | __metadata("design:type", Number),
|
3814 | __metadata("design:paramtypes", [Number])
|
3815 | ], NgPlural.prototype, "ngPlural", null);
|
3816 | NgPlural = __decorate([
|
3817 | Directive({ selector: '[ngPlural]' }),
|
3818 | __metadata("design:paramtypes", [NgLocalization])
|
3819 | ], NgPlural);
|
3820 | return NgPlural;
|
3821 | }());
|
3822 | /**
|
3823 | * @ngModule CommonModule
|
3824 | *
|
3825 | * @description
|
3826 | *
|
3827 | * Creates a view that will be added/removed from the parent {@link NgPlural} when the
|
3828 | * given expression matches the plural expression according to CLDR rules.
|
3829 | *
|
3830 | * @usageNotes
|
3831 | * ```
|
3832 | * <some-element [ngPlural]="value">
|
3833 | * <ng-template ngPluralCase="=0">...</ng-template>
|
3834 | * <ng-template ngPluralCase="other">...</ng-template>
|
3835 | * </some-element>
|
3836 | *```
|
3837 | *
|
3838 | * See {@link NgPlural} for more details and example.
|
3839 | *
|
3840 | * @publicApi
|
3841 | */
|
3842 | var NgPluralCase = /** @class */ (function () {
|
3843 | function NgPluralCase(value, template, viewContainer, ngPlural) {
|
3844 | this.value = value;
|
3845 | var isANumber = !isNaN(Number(value));
|
3846 | ngPlural.addCase(isANumber ? "=" + value : value, new SwitchView(viewContainer, template));
|
3847 | }
|
3848 | NgPluralCase = __decorate([
|
3849 | Directive({ selector: '[ngPluralCase]' }),
|
3850 | __param(0, Attribute('ngPluralCase')),
|
3851 | __param(3, Host()),
|
3852 | __metadata("design:paramtypes", [String, TemplateRef,
|
3853 | ViewContainerRef, NgPlural])
|
3854 | ], NgPluralCase);
|
3855 | return NgPluralCase;
|
3856 | }());
|
3857 |
|
3858 | /**
|
3859 | * @ngModule CommonModule
|
3860 | *
|
3861 | * @usageNotes
|
3862 | *
|
3863 | * Set the font of the containing element to the result of an expression.
|
3864 | *
|
3865 | * ```
|
3866 | * <some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
|
3867 | * ```
|
3868 | *
|
3869 | * Set the width of the containing element to a pixel value returned by an expression.
|
3870 | *
|
3871 | * ```
|
3872 | * <some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
|
3873 | * ```
|
3874 | *
|
3875 | * Set a collection of style values using an expression that returns key-value pairs.
|
3876 | *
|
3877 | * ```
|
3878 | * <some-element [ngStyle]="objExp">...</some-element>
|
3879 | * ```
|
3880 | *
|
3881 | * @description
|
3882 | *
|
3883 | * An attribute directive that updates styles for the containing HTML element.
|
3884 | * Sets one or more style properties, specified as colon-separated key-value pairs.
|
3885 | * The key is a style name, with an optional `.<unit>` suffix
|
3886 | * (such as 'top.px', 'font-style.em').
|
3887 | * The value is an expression to be evaluated.
|
3888 | * The resulting non-null value, expressed in the given unit,
|
3889 | * is assigned to the given style property.
|
3890 | * If the result of evaluation is null, the corresponding style is removed.
|
3891 | *
|
3892 | * @publicApi
|
3893 | */
|
3894 | var NgStyle = /** @class */ (function () {
|
3895 | function NgStyle(_ngEl, _differs, _renderer) {
|
3896 | this._ngEl = _ngEl;
|
3897 | this._differs = _differs;
|
3898 | this._renderer = _renderer;
|
3899 | this._ngStyle = null;
|
3900 | this._differ = null;
|
3901 | }
|
3902 | Object.defineProperty(NgStyle.prototype, "ngStyle", {
|
3903 | set: function (values) {
|
3904 | this._ngStyle = values;
|
3905 | if (!this._differ && values) {
|
3906 | this._differ = this._differs.find(values).create();
|
3907 | }
|
3908 | },
|
3909 | enumerable: true,
|
3910 | configurable: true
|
3911 | });
|
3912 | NgStyle.prototype.ngDoCheck = function () {
|
3913 | if (this._differ) {
|
3914 | var changes = this._differ.diff(this._ngStyle);
|
3915 | if (changes) {
|
3916 | this._applyChanges(changes);
|
3917 | }
|
3918 | }
|
3919 | };
|
3920 | NgStyle.prototype._setStyle = function (nameAndUnit, value) {
|
3921 | var _a = __read(nameAndUnit.split('.'), 2), name = _a[0], unit = _a[1];
|
3922 | value = value != null && unit ? "" + value + unit : value;
|
3923 | if (value != null) {
|
3924 | this._renderer.setStyle(this._ngEl.nativeElement, name, value);
|
3925 | }
|
3926 | else {
|
3927 | this._renderer.removeStyle(this._ngEl.nativeElement, name);
|
3928 | }
|
3929 | };
|
3930 | NgStyle.prototype._applyChanges = function (changes) {
|
3931 | var _this = this;
|
3932 | changes.forEachRemovedItem(function (record) { return _this._setStyle(record.key, null); });
|
3933 | changes.forEachAddedItem(function (record) { return _this._setStyle(record.key, record.currentValue); });
|
3934 | changes.forEachChangedItem(function (record) { return _this._setStyle(record.key, record.currentValue); });
|
3935 | };
|
3936 | __decorate([
|
3937 | Input('ngStyle'),
|
3938 | __metadata("design:type", Object),
|
3939 | __metadata("design:paramtypes", [Object])
|
3940 | ], NgStyle.prototype, "ngStyle", null);
|
3941 | NgStyle = __decorate([
|
3942 | Directive({ selector: '[ngStyle]' }),
|
3943 | __metadata("design:paramtypes", [ElementRef, KeyValueDiffers, Renderer2])
|
3944 | ], NgStyle);
|
3945 | return NgStyle;
|
3946 | }());
|
3947 |
|
3948 | /**
|
3949 | * @license
|
3950 | * Copyright Google Inc. All Rights Reserved.
|
3951 | *
|
3952 | * Use of this source code is governed by an MIT-style license that can be
|
3953 | * found in the LICENSE file at https://angular.io/license
|
3954 | */
|
3955 | /**
|
3956 | * @ngModule CommonModule
|
3957 | *
|
3958 | * @description
|
3959 | *
|
3960 | * Inserts an embedded view from a prepared `TemplateRef`.
|
3961 | *
|
3962 | * You can attach a context object to the `EmbeddedViewRef` by setting `[ngTemplateOutletContext]`.
|
3963 | * `[ngTemplateOutletContext]` should be an object, the object's keys will be available for binding
|
3964 | * by the local template `let` declarations.
|
3965 | *
|
3966 | * @usageNotes
|
3967 | * ```
|
3968 | * <ng-container *ngTemplateOutlet="templateRefExp; context: contextExp"></ng-container>
|
3969 | * ```
|
3970 | *
|
3971 | * Using the key `$implicit` in the context object will set its value as default.
|
3972 | *
|
3973 | * ### Example
|
3974 | *
|
3975 | * {@example common/ngTemplateOutlet/ts/module.ts region='NgTemplateOutlet'}
|
3976 | *
|
3977 | * @publicApi
|
3978 | */
|
3979 | var NgTemplateOutlet = /** @class */ (function () {
|
3980 | function NgTemplateOutlet(_viewContainerRef) {
|
3981 | this._viewContainerRef = _viewContainerRef;
|
3982 | this._viewRef = null;
|
3983 | /**
|
3984 | * A context object to attach to the {@link EmbeddedViewRef}. This should be an
|
3985 | * object, the object's keys will be available for binding by the local template `let`
|
3986 | * declarations.
|
3987 | * Using the key `$implicit` in the context object will set its value as default.
|
3988 | */
|
3989 | this.ngTemplateOutletContext = null;
|
3990 | /**
|
3991 | * A string defining the template reference and optionally the context object for the template.
|
3992 | */
|
3993 | this.ngTemplateOutlet = null;
|
3994 | }
|
3995 | NgTemplateOutlet.prototype.ngOnChanges = function (changes) {
|
3996 | var recreateView = this._shouldRecreateView(changes);
|
3997 | if (recreateView) {
|
3998 | var viewContainerRef = this._viewContainerRef;
|
3999 | if (this._viewRef) {
|
4000 | viewContainerRef.remove(viewContainerRef.indexOf(this._viewRef));
|
4001 | }
|
4002 | this._viewRef = this.ngTemplateOutlet ?
|
4003 | viewContainerRef.createEmbeddedView(this.ngTemplateOutlet, this.ngTemplateOutletContext) :
|
4004 | null;
|
4005 | }
|
4006 | else if (this._viewRef && this.ngTemplateOutletContext) {
|
4007 | this._updateExistingContext(this.ngTemplateOutletContext);
|
4008 | }
|
4009 | };
|
4010 | /**
|
4011 | * We need to re-create existing embedded view if:
|
4012 | * - templateRef has changed
|
4013 | * - context has changes
|
4014 | *
|
4015 | * We mark context object as changed when the corresponding object
|
4016 | * shape changes (new properties are added or existing properties are removed).
|
4017 | * In other words we consider context with the same properties as "the same" even
|
4018 | * if object reference changes (see https://github.com/angular/angular/issues/13407).
|
4019 | */
|
4020 | NgTemplateOutlet.prototype._shouldRecreateView = function (changes) {
|
4021 | var ctxChange = changes['ngTemplateOutletContext'];
|
4022 | return !!changes['ngTemplateOutlet'] || (ctxChange && this._hasContextShapeChanged(ctxChange));
|
4023 | };
|
4024 | NgTemplateOutlet.prototype._hasContextShapeChanged = function (ctxChange) {
|
4025 | var e_1, _a;
|
4026 | var prevCtxKeys = Object.keys(ctxChange.previousValue || {});
|
4027 | var currCtxKeys = Object.keys(ctxChange.currentValue || {});
|
4028 | if (prevCtxKeys.length === currCtxKeys.length) {
|
4029 | try {
|
4030 | for (var currCtxKeys_1 = __values(currCtxKeys), currCtxKeys_1_1 = currCtxKeys_1.next(); !currCtxKeys_1_1.done; currCtxKeys_1_1 = currCtxKeys_1.next()) {
|
4031 | var propName = currCtxKeys_1_1.value;
|
4032 | if (prevCtxKeys.indexOf(propName) === -1) {
|
4033 | return true;
|
4034 | }
|
4035 | }
|
4036 | }
|
4037 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
4038 | finally {
|
4039 | try {
|
4040 | if (currCtxKeys_1_1 && !currCtxKeys_1_1.done && (_a = currCtxKeys_1.return)) _a.call(currCtxKeys_1);
|
4041 | }
|
4042 | finally { if (e_1) throw e_1.error; }
|
4043 | }
|
4044 | return false;
|
4045 | }
|
4046 | return true;
|
4047 | };
|
4048 | NgTemplateOutlet.prototype._updateExistingContext = function (ctx) {
|
4049 | var e_2, _a;
|
4050 | try {
|
4051 | for (var _b = __values(Object.keys(ctx)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
4052 | var propName = _c.value;
|
4053 | this._viewRef.context[propName] = this.ngTemplateOutletContext[propName];
|
4054 | }
|
4055 | }
|
4056 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
4057 | finally {
|
4058 | try {
|
4059 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
4060 | }
|
4061 | finally { if (e_2) throw e_2.error; }
|
4062 | }
|
4063 | };
|
4064 | __decorate([
|
4065 | Input(),
|
4066 | __metadata("design:type", Object)
|
4067 | ], NgTemplateOutlet.prototype, "ngTemplateOutletContext", void 0);
|
4068 | __decorate([
|
4069 | Input(),
|
4070 | __metadata("design:type", Object)
|
4071 | ], NgTemplateOutlet.prototype, "ngTemplateOutlet", void 0);
|
4072 | NgTemplateOutlet = __decorate([
|
4073 | Directive({ selector: '[ngTemplateOutlet]' }),
|
4074 | __metadata("design:paramtypes", [ViewContainerRef])
|
4075 | ], NgTemplateOutlet);
|
4076 | return NgTemplateOutlet;
|
4077 | }());
|
4078 |
|
4079 | /**
|
4080 | * @license
|
4081 | * Copyright Google Inc. All Rights Reserved.
|
4082 | *
|
4083 | * Use of this source code is governed by an MIT-style license that can be
|
4084 | * found in the LICENSE file at https://angular.io/license
|
4085 | */
|
4086 | /**
|
4087 | * A collection of Angular directives that are likely to be used in each and every Angular
|
4088 | * application.
|
4089 | */
|
4090 | var COMMON_DIRECTIVES = [
|
4091 | NgClass,
|
4092 | NgComponentOutlet,
|
4093 | NgForOf,
|
4094 | NgIf,
|
4095 | NgTemplateOutlet,
|
4096 | NgStyle,
|
4097 | NgSwitch,
|
4098 | NgSwitchCase,
|
4099 | NgSwitchDefault,
|
4100 | NgPlural,
|
4101 | NgPluralCase,
|
4102 | ];
|
4103 |
|
4104 | /**
|
4105 | * @license
|
4106 | * Copyright Google Inc. All Rights Reserved.
|
4107 | *
|
4108 | * Use of this source code is governed by an MIT-style license that can be
|
4109 | * found in the LICENSE file at https://angular.io/license
|
4110 | */
|
4111 | function invalidPipeArgumentError(type, value) {
|
4112 | return Error("InvalidPipeArgument: '" + value + "' for pipe '" + ɵstringify(type) + "'");
|
4113 | }
|
4114 |
|
4115 | /**
|
4116 | * @license
|
4117 | * Copyright Google Inc. All Rights Reserved.
|
4118 | *
|
4119 | * Use of this source code is governed by an MIT-style license that can be
|
4120 | * found in the LICENSE file at https://angular.io/license
|
4121 | */
|
4122 | var ObservableStrategy = /** @class */ (function () {
|
4123 | function ObservableStrategy() {
|
4124 | }
|
4125 | ObservableStrategy.prototype.createSubscription = function (async, updateLatestValue) {
|
4126 | return async.subscribe({ next: updateLatestValue, error: function (e) { throw e; } });
|
4127 | };
|
4128 | ObservableStrategy.prototype.dispose = function (subscription) { subscription.unsubscribe(); };
|
4129 | ObservableStrategy.prototype.onDestroy = function (subscription) { subscription.unsubscribe(); };
|
4130 | return ObservableStrategy;
|
4131 | }());
|
4132 | var PromiseStrategy = /** @class */ (function () {
|
4133 | function PromiseStrategy() {
|
4134 | }
|
4135 | PromiseStrategy.prototype.createSubscription = function (async, updateLatestValue) {
|
4136 | return async.then(updateLatestValue, function (e) { throw e; });
|
4137 | };
|
4138 | PromiseStrategy.prototype.dispose = function (subscription) { };
|
4139 | PromiseStrategy.prototype.onDestroy = function (subscription) { };
|
4140 | return PromiseStrategy;
|
4141 | }());
|
4142 | var _promiseStrategy = new PromiseStrategy();
|
4143 | var _observableStrategy = new ObservableStrategy();
|
4144 | /**
|
4145 | * @ngModule CommonModule
|
4146 | * @description
|
4147 | *
|
4148 | * Unwraps a value from an asynchronous primitive.
|
4149 | *
|
4150 | * The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has
|
4151 | * emitted. When a new value is emitted, the `async` pipe marks the component to be checked for
|
4152 | * changes. When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid
|
4153 | * potential memory leaks.
|
4154 | *
|
4155 | * @usageNotes
|
4156 | *
|
4157 | * ### Examples
|
4158 | *
|
4159 | * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
|
4160 | * promise.
|
4161 | *
|
4162 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
|
4163 | *
|
4164 | * It's also possible to use `async` with Observables. The example below binds the `time` Observable
|
4165 | * to the view. The Observable continuously updates the view with the current time.
|
4166 | *
|
4167 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
|
4168 | *
|
4169 | * @publicApi
|
4170 | */
|
4171 | var AsyncPipe = /** @class */ (function () {
|
4172 | function AsyncPipe(_ref) {
|
4173 | this._ref = _ref;
|
4174 | this._latestValue = null;
|
4175 | this._latestReturnedValue = null;
|
4176 | this._subscription = null;
|
4177 | this._obj = null;
|
4178 | this._strategy = null;
|
4179 | }
|
4180 | AsyncPipe_1 = AsyncPipe;
|
4181 | AsyncPipe.prototype.ngOnDestroy = function () {
|
4182 | if (this._subscription) {
|
4183 | this._dispose();
|
4184 | }
|
4185 | };
|
4186 | AsyncPipe.prototype.transform = function (obj) {
|
4187 | if (!this._obj) {
|
4188 | if (obj) {
|
4189 | this._subscribe(obj);
|
4190 | }
|
4191 | this._latestReturnedValue = this._latestValue;
|
4192 | return this._latestValue;
|
4193 | }
|
4194 | if (obj !== this._obj) {
|
4195 | this._dispose();
|
4196 | return this.transform(obj);
|
4197 | }
|
4198 | if (ɵlooseIdentical(this._latestValue, this._latestReturnedValue)) {
|
4199 | return this._latestReturnedValue;
|
4200 | }
|
4201 | this._latestReturnedValue = this._latestValue;
|
4202 | return WrappedValue.wrap(this._latestValue);
|
4203 | };
|
4204 | AsyncPipe.prototype._subscribe = function (obj) {
|
4205 | var _this = this;
|
4206 | this._obj = obj;
|
4207 | this._strategy = this._selectStrategy(obj);
|
4208 | this._subscription = this._strategy.createSubscription(obj, function (value) { return _this._updateLatestValue(obj, value); });
|
4209 | };
|
4210 | AsyncPipe.prototype._selectStrategy = function (obj) {
|
4211 | if (ɵisPromise(obj)) {
|
4212 | return _promiseStrategy;
|
4213 | }
|
4214 | if (ɵisObservable(obj)) {
|
4215 | return _observableStrategy;
|
4216 | }
|
4217 | throw invalidPipeArgumentError(AsyncPipe_1, obj);
|
4218 | };
|
4219 | AsyncPipe.prototype._dispose = function () {
|
4220 | this._strategy.dispose(this._subscription);
|
4221 | this._latestValue = null;
|
4222 | this._latestReturnedValue = null;
|
4223 | this._subscription = null;
|
4224 | this._obj = null;
|
4225 | };
|
4226 | AsyncPipe.prototype._updateLatestValue = function (async, value) {
|
4227 | if (async === this._obj) {
|
4228 | this._latestValue = value;
|
4229 | this._ref.markForCheck();
|
4230 | }
|
4231 | };
|
4232 | var AsyncPipe_1;
|
4233 | AsyncPipe = AsyncPipe_1 = __decorate([
|
4234 | Pipe({ name: 'async', pure: false }),
|
4235 | __metadata("design:paramtypes", [ChangeDetectorRef])
|
4236 | ], AsyncPipe);
|
4237 | return AsyncPipe;
|
4238 | }());
|
4239 |
|
4240 | /**
|
4241 | * @license
|
4242 | * Copyright Google Inc. All Rights Reserved.
|
4243 | *
|
4244 | * Use of this source code is governed by an MIT-style license that can be
|
4245 | * found in the LICENSE file at https://angular.io/license
|
4246 | */
|
4247 | /**
|
4248 | * Transforms text to all lower case.
|
4249 | *
|
4250 | * @see `UpperCasePipe`
|
4251 | * @see `TitleCasePipe`
|
4252 | * @usageNotes
|
4253 | *
|
4254 | * The following example defines a view that allows the user to enter
|
4255 | * text, and then uses the pipe to convert the input text to all lower case.
|
4256 | *
|
4257 | * <code-example path="common/pipes/ts/lowerupper_pipe.ts" region='LowerUpperPipe'></code-example>
|
4258 | *
|
4259 | * @ngModule CommonModule
|
4260 | * @publicApi
|
4261 | */
|
4262 | var LowerCasePipe = /** @class */ (function () {
|
4263 | function LowerCasePipe() {
|
4264 | }
|
4265 | LowerCasePipe_1 = LowerCasePipe;
|
4266 | /**
|
4267 | * @param value The string to transform to lower case.
|
4268 | */
|
4269 | LowerCasePipe.prototype.transform = function (value) {
|
4270 | if (!value)
|
4271 | return value;
|
4272 | if (typeof value !== 'string') {
|
4273 | throw invalidPipeArgumentError(LowerCasePipe_1, value);
|
4274 | }
|
4275 | return value.toLowerCase();
|
4276 | };
|
4277 | var LowerCasePipe_1;
|
4278 | LowerCasePipe = LowerCasePipe_1 = __decorate([
|
4279 | Pipe({ name: 'lowercase' })
|
4280 | ], LowerCasePipe);
|
4281 | return LowerCasePipe;
|
4282 | }());
|
4283 | //
|
4284 | // Regex below matches any Unicode word and compatible with ES5. In ES2018 the same result
|
4285 | // can be achieved by using /\p{L}\S*/gu and also known as Unicode Property Escapes
|
4286 | // (http://2ality.com/2017/07/regexp-unicode-property-escapes.html). Since there is no
|
4287 | // transpilation of this functionality down to ES5 without external tool, the only solution is
|
4288 | // to use already transpiled form. Example can be found here -
|
4289 | // https://mothereff.in/regexpu#input=var+regex+%3D+/%5Cp%7BL%7D/u%3B&unicodePropertyEscape=1
|
4290 | //
|
4291 | var unicodeWordMatch = /(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D])\S*/g;
|
4292 | /**
|
4293 | * Transforms text to title case.
|
4294 | * Capitalizes the first letter of each word, and transforms the
|
4295 | * rest of the word to lower case.
|
4296 | * Words are delimited by any whitespace character, such as a space, tab, or line-feed character.
|
4297 | *
|
4298 | * @see `LowerCasePipe`
|
4299 | * @see `UpperCasePipe`
|
4300 | *
|
4301 | * @usageNotes
|
4302 | * The following example shows the result of transforming various strings into title case.
|
4303 | *
|
4304 | * <code-example path="common/pipes/ts/titlecase_pipe.ts" region='TitleCasePipe'></code-example>
|
4305 | *
|
4306 | * @ngModule CommonModule
|
4307 | * @publicApi
|
4308 | */
|
4309 | var TitleCasePipe = /** @class */ (function () {
|
4310 | function TitleCasePipe() {
|
4311 | }
|
4312 | TitleCasePipe_1 = TitleCasePipe;
|
4313 | /**
|
4314 | * @param value The string to transform to title case.
|
4315 | */
|
4316 | TitleCasePipe.prototype.transform = function (value) {
|
4317 | if (!value)
|
4318 | return value;
|
4319 | if (typeof value !== 'string') {
|
4320 | throw invalidPipeArgumentError(TitleCasePipe_1, value);
|
4321 | }
|
4322 | return value.replace(unicodeWordMatch, (function (txt) { return txt[0].toUpperCase() + txt.substr(1).toLowerCase(); }));
|
4323 | };
|
4324 | var TitleCasePipe_1;
|
4325 | TitleCasePipe = TitleCasePipe_1 = __decorate([
|
4326 | Pipe({ name: 'titlecase' })
|
4327 | ], TitleCasePipe);
|
4328 | return TitleCasePipe;
|
4329 | }());
|
4330 | /**
|
4331 | * Transforms text to all upper case.
|
4332 | * @see `LowerCasePipe`
|
4333 | * @see `TitleCasePipe`
|
4334 | *
|
4335 | * @ngModule CommonModule
|
4336 | * @publicApi
|
4337 | */
|
4338 | var UpperCasePipe = /** @class */ (function () {
|
4339 | function UpperCasePipe() {
|
4340 | }
|
4341 | UpperCasePipe_1 = UpperCasePipe;
|
4342 | /**
|
4343 | * @param value The string to transform to upper case.
|
4344 | */
|
4345 | UpperCasePipe.prototype.transform = function (value) {
|
4346 | if (!value)
|
4347 | return value;
|
4348 | if (typeof value !== 'string') {
|
4349 | throw invalidPipeArgumentError(UpperCasePipe_1, value);
|
4350 | }
|
4351 | return value.toUpperCase();
|
4352 | };
|
4353 | var UpperCasePipe_1;
|
4354 | UpperCasePipe = UpperCasePipe_1 = __decorate([
|
4355 | Pipe({ name: 'uppercase' })
|
4356 | ], UpperCasePipe);
|
4357 | return UpperCasePipe;
|
4358 | }());
|
4359 |
|
4360 | /**
|
4361 | * @license
|
4362 | * Copyright Google Inc. All Rights Reserved.
|
4363 | *
|
4364 | * Use of this source code is governed by an MIT-style license that can be
|
4365 | * found in the LICENSE file at https://angular.io/license
|
4366 | */
|
4367 | // clang-format off
|
4368 | /**
|
4369 | * @ngModule CommonModule
|
4370 | * @description
|
4371 | *
|
4372 | * Formats a date value according to locale rules.
|
4373 | *
|
4374 | * Only the `en-US` locale data comes with Angular. To localize dates
|
4375 | * in another language, you must import the corresponding locale data.
|
4376 | * See the [I18n guide](guide/i18n#i18n-pipes) for more information.
|
4377 | *
|
4378 | * @see `formatDate()`
|
4379 | *
|
4380 | *
|
4381 | * @usageNotes
|
4382 | *
|
4383 | * The result of this pipe is not reevaluated when the input is mutated. To avoid the need to
|
4384 | * reformat the date on every change-detection cycle, treat the date as an immutable object
|
4385 | * and change the reference when the pipe needs to run again.
|
4386 | *
|
4387 | * ### Pre-defined format options
|
4388 | *
|
4389 | * Examples are given in `en-US` locale.
|
4390 | *
|
4391 | * - `'short'`: equivalent to `'M/d/yy, h:mm a'` (`6/15/15, 9:03 AM`).
|
4392 | * - `'medium'`: equivalent to `'MMM d, y, h:mm:ss a'` (`Jun 15, 2015, 9:03:01 AM`).
|
4393 | * - `'long'`: equivalent to `'MMMM d, y, h:mm:ss a z'` (`June 15, 2015 at 9:03:01 AM
|
4394 | * GMT+1`).
|
4395 | * - `'full'`: equivalent to `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (`Monday, June 15, 2015 at
|
4396 | * 9:03:01 AM GMT+01:00`).
|
4397 | * - `'shortDate'`: equivalent to `'M/d/yy'` (`6/15/15`).
|
4398 | * - `'mediumDate'`: equivalent to `'MMM d, y'` (`Jun 15, 2015`).
|
4399 | * - `'longDate'`: equivalent to `'MMMM d, y'` (`June 15, 2015`).
|
4400 | * - `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` (`Monday, June 15, 2015`).
|
4401 | * - `'shortTime'`: equivalent to `'h:mm a'` (`9:03 AM`).
|
4402 | * - `'mediumTime'`: equivalent to `'h:mm:ss a'` (`9:03:01 AM`).
|
4403 | * - `'longTime'`: equivalent to `'h:mm:ss a z'` (`9:03:01 AM GMT+1`).
|
4404 | * - `'fullTime'`: equivalent to `'h:mm:ss a zzzz'` (`9:03:01 AM GMT+01:00`).
|
4405 | *
|
4406 | * ### Custom format options
|
4407 | *
|
4408 | * You can construct a format string using symbols to specify the components
|
4409 | * of a date-time value, as described in the following table.
|
4410 | * Format details depend on the locale.
|
4411 | * Fields marked with (*) are only available in the extra data set for the given locale.
|
4412 | *
|
4413 | * | Field type | Format | Description | Example Value |
|
4414 | * |--------------------|-------------|---------------------------------------------------------------|------------------------------------------------------------|
|
4415 | * | Era | G, GG & GGG | Abbreviated | AD |
|
4416 | * | | GGGG | Wide | Anno Domini |
|
4417 | * | | GGGGG | Narrow | A |
|
4418 | * | Year | y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
|
4419 | * | | yy | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
|
4420 | * | | yyy | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
|
4421 | * | | yyyy | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
|
4422 | * | Month | M | Numeric: 1 digit | 9, 12 |
|
4423 | * | | MM | Numeric: 2 digits + zero padded | 09, 12 |
|
4424 | * | | MMM | Abbreviated | Sep |
|
4425 | * | | MMMM | Wide | September |
|
4426 | * | | MMMMM | Narrow | S |
|
4427 | * | Month standalone | L | Numeric: 1 digit | 9, 12 |
|
4428 | * | | LL | Numeric: 2 digits + zero padded | 09, 12 |
|
4429 | * | | LLL | Abbreviated | Sep |
|
4430 | * | | LLLL | Wide | September |
|
4431 | * | | LLLLL | Narrow | S |
|
4432 | * | Week of year | w | Numeric: minimum digits | 1... 53 |
|
4433 | * | | ww | Numeric: 2 digits + zero padded | 01... 53 |
|
4434 | * | Week of month | W | Numeric: 1 digit | 1... 5 |
|
4435 | * | Day of month | d | Numeric: minimum digits | 1 |
|
4436 | * | | dd | Numeric: 2 digits + zero padded | 01 |
|
4437 | * | Week day | E, EE & EEE | Abbreviated | Tue |
|
4438 | * | | EEEE | Wide | Tuesday |
|
4439 | * | | EEEEE | Narrow | T |
|
4440 | * | | EEEEEE | Short | Tu |
|
4441 | * | Period | a, aa & aaa | Abbreviated | am/pm or AM/PM |
|
4442 | * | | aaaa | Wide (fallback to `a` when missing) | ante meridiem/post meridiem |
|
4443 | * | | aaaaa | Narrow | a/p |
|
4444 | * | Period* | B, BB & BBB | Abbreviated | mid. |
|
4445 | * | | BBBB | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
|
4446 | * | | BBBBB | Narrow | md |
|
4447 | * | Period standalone* | b, bb & bbb | Abbreviated | mid. |
|
4448 | * | | bbbb | Wide | am, pm, midnight, noon, morning, afternoon, evening, night |
|
4449 | * | | bbbbb | Narrow | md |
|
4450 | * | Hour 1-12 | h | Numeric: minimum digits | 1, 12 |
|
4451 | * | | hh | Numeric: 2 digits + zero padded | 01, 12 |
|
4452 | * | Hour 0-23 | H | Numeric: minimum digits | 0, 23 |
|
4453 | * | | HH | Numeric: 2 digits + zero padded | 00, 23 |
|
4454 | * | Minute | m | Numeric: minimum digits | 8, 59 |
|
4455 | * | | mm | Numeric: 2 digits + zero padded | 08, 59 |
|
4456 | * | Second | s | Numeric: minimum digits | 0... 59 |
|
4457 | * | | ss | Numeric: 2 digits + zero padded | 00... 59 |
|
4458 | * | Fractional seconds | S | Numeric: 1 digit | 0... 9 |
|
4459 | * | | SS | Numeric: 2 digits + zero padded | 00... 99 |
|
4460 | * | | SSS | Numeric: 3 digits + zero padded (= milliseconds) | 000... 999 |
|
4461 | * | Zone | z, zz & zzz | Short specific non location format (fallback to O) | GMT-8 |
|
4462 | * | | zzzz | Long specific non location format (fallback to OOOO) | GMT-08:00 |
|
4463 | * | | Z, ZZ & ZZZ | ISO8601 basic format | -0800 |
|
4464 | * | | ZZZZ | Long localized GMT format | GMT-8:00 |
|
4465 | * | | ZZZZZ | ISO8601 extended format + Z indicator for offset 0 (= XXXXX) | -08:00 |
|
4466 | * | | O, OO & OOO | Short localized GMT format | GMT-8 |
|
4467 | * | | OOOO | Long localized GMT format | GMT-08:00 |
|
4468 | *
|
4469 | * Note that timezone correction is not applied to an ISO string that has no time component, such as "2016-09-19"
|
4470 | *
|
4471 | * ### Format examples
|
4472 | *
|
4473 | * These examples transform a date into various formats,
|
4474 | * assuming that `dateObj` is a JavaScript `Date` object for
|
4475 | * year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11,
|
4476 | * given in the local time for the `en-US` locale.
|
4477 | *
|
4478 | * ```
|
4479 | * {{ dateObj | date }} // output is 'Jun 15, 2015'
|
4480 | * {{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM'
|
4481 | * {{ dateObj | date:'shortTime' }} // output is '9:43 PM'
|
4482 | * {{ dateObj | date:'mm:ss' }} // output is '43:11'
|
4483 | * ```
|
4484 | *
|
4485 | * ### Usage example
|
4486 | *
|
4487 | * The following component uses a date pipe to display the current date in different formats.
|
4488 | *
|
4489 | * ```
|
4490 | * @Component({
|
4491 | * selector: 'date-pipe',
|
4492 | * template: `<div>
|
4493 | * <p>Today is {{today | date}}</p>
|
4494 | * <p>Or if you prefer, {{today | date:'fullDate'}}</p>
|
4495 | * <p>The time is {{today | date:'h:mm a z'}}</p>
|
4496 | * </div>`
|
4497 | * })
|
4498 | * // Get the current date and time as a date-time value.
|
4499 | * export class DatePipeComponent {
|
4500 | * today: number = Date.now();
|
4501 | * }
|
4502 | * ```
|
4503 | *
|
4504 | * @publicApi
|
4505 | */
|
4506 | // clang-format on
|
4507 | var DatePipe = /** @class */ (function () {
|
4508 | function DatePipe(locale) {
|
4509 | this.locale = locale;
|
4510 | }
|
4511 | DatePipe_1 = DatePipe;
|
4512 | /**
|
4513 | * @param value The date expression: a `Date` object, a number
|
4514 | * (milliseconds since UTC epoch), or an ISO string (https://www.w3.org/TR/NOTE-datetime).
|
4515 | * @param format The date/time components to include, using predefined options or a
|
4516 | * custom format string.
|
4517 | * @param timezone A timezone offset (such as `'+0430'`), or a standard
|
4518 | * UTC/GMT or continental US timezone abbreviation.
|
4519 | * When not supplied, uses the end-user's local system timezone.
|
4520 | * @param locale A locale code for the locale format rules to use.
|
4521 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
4522 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
4523 | * @returns A date string in the desired format.
|
4524 | */
|
4525 | DatePipe.prototype.transform = function (value, format, timezone, locale) {
|
4526 | if (format === void 0) { format = 'mediumDate'; }
|
4527 | if (value == null || value === '' || value !== value)
|
4528 | return null;
|
4529 | try {
|
4530 | return formatDate(value, format, locale || this.locale, timezone);
|
4531 | }
|
4532 | catch (error) {
|
4533 | throw invalidPipeArgumentError(DatePipe_1, error.message);
|
4534 | }
|
4535 | };
|
4536 | var DatePipe_1;
|
4537 | DatePipe = DatePipe_1 = __decorate([
|
4538 | Pipe({ name: 'date', pure: true }),
|
4539 | __param(0, Inject(LOCALE_ID)),
|
4540 | __metadata("design:paramtypes", [String])
|
4541 | ], DatePipe);
|
4542 | return DatePipe;
|
4543 | }());
|
4544 |
|
4545 | /**
|
4546 | * @license
|
4547 | * Copyright Google Inc. All Rights Reserved.
|
4548 | *
|
4549 | * Use of this source code is governed by an MIT-style license that can be
|
4550 | * found in the LICENSE file at https://angular.io/license
|
4551 | */
|
4552 | var _INTERPOLATION_REGEXP = /#/g;
|
4553 | /**
|
4554 | * @ngModule CommonModule
|
4555 | * @description
|
4556 | *
|
4557 | * Maps a value to a string that pluralizes the value according to locale rules.
|
4558 | *
|
4559 | * @usageNotes
|
4560 | *
|
4561 | * ### Example
|
4562 | *
|
4563 | * {@example common/pipes/ts/i18n_pipe.ts region='I18nPluralPipeComponent'}
|
4564 | *
|
4565 | * @publicApi
|
4566 | */
|
4567 | var I18nPluralPipe = /** @class */ (function () {
|
4568 | function I18nPluralPipe(_localization) {
|
4569 | this._localization = _localization;
|
4570 | }
|
4571 | I18nPluralPipe_1 = I18nPluralPipe;
|
4572 | /**
|
4573 | * @param value the number to be formatted
|
4574 | * @param pluralMap an object that mimics the ICU format, see
|
4575 | * http://userguide.icu-project.org/formatparse/messages.
|
4576 | * @param locale a `string` defining the locale to use (uses the current {@link LOCALE_ID} by
|
4577 | * default).
|
4578 | */
|
4579 | I18nPluralPipe.prototype.transform = function (value, pluralMap, locale) {
|
4580 | if (value == null)
|
4581 | return '';
|
4582 | if (typeof pluralMap !== 'object' || pluralMap === null) {
|
4583 | throw invalidPipeArgumentError(I18nPluralPipe_1, pluralMap);
|
4584 | }
|
4585 | var key = getPluralCategory(value, Object.keys(pluralMap), this._localization, locale);
|
4586 | return pluralMap[key].replace(_INTERPOLATION_REGEXP, value.toString());
|
4587 | };
|
4588 | var I18nPluralPipe_1;
|
4589 | I18nPluralPipe = I18nPluralPipe_1 = __decorate([
|
4590 | Pipe({ name: 'i18nPlural', pure: true }),
|
4591 | __metadata("design:paramtypes", [NgLocalization])
|
4592 | ], I18nPluralPipe);
|
4593 | return I18nPluralPipe;
|
4594 | }());
|
4595 |
|
4596 | /**
|
4597 | * @license
|
4598 | * Copyright Google Inc. All Rights Reserved.
|
4599 | *
|
4600 | * Use of this source code is governed by an MIT-style license that can be
|
4601 | * found in the LICENSE file at https://angular.io/license
|
4602 | */
|
4603 | /**
|
4604 | * @ngModule CommonModule
|
4605 | * @description
|
4606 | *
|
4607 | * Generic selector that displays the string that matches the current value.
|
4608 | *
|
4609 | * If none of the keys of the `mapping` match the `value`, then the content
|
4610 | * of the `other` key is returned when present, otherwise an empty string is returned.
|
4611 | *
|
4612 | * @usageNotes
|
4613 | *
|
4614 | * ### Example
|
4615 | *
|
4616 | * {@example common/pipes/ts/i18n_pipe.ts region='I18nSelectPipeComponent'}
|
4617 | *
|
4618 | * @publicApi
|
4619 | */
|
4620 | var I18nSelectPipe = /** @class */ (function () {
|
4621 | function I18nSelectPipe() {
|
4622 | }
|
4623 | I18nSelectPipe_1 = I18nSelectPipe;
|
4624 | /**
|
4625 | * @param value a string to be internationalized.
|
4626 | * @param mapping an object that indicates the text that should be displayed
|
4627 | * for different values of the provided `value`.
|
4628 | */
|
4629 | I18nSelectPipe.prototype.transform = function (value, mapping) {
|
4630 | if (value == null)
|
4631 | return '';
|
4632 | if (typeof mapping !== 'object' || typeof value !== 'string') {
|
4633 | throw invalidPipeArgumentError(I18nSelectPipe_1, mapping);
|
4634 | }
|
4635 | if (mapping.hasOwnProperty(value)) {
|
4636 | return mapping[value];
|
4637 | }
|
4638 | if (mapping.hasOwnProperty('other')) {
|
4639 | return mapping['other'];
|
4640 | }
|
4641 | return '';
|
4642 | };
|
4643 | var I18nSelectPipe_1;
|
4644 | I18nSelectPipe = I18nSelectPipe_1 = __decorate([
|
4645 | Pipe({ name: 'i18nSelect', pure: true })
|
4646 | ], I18nSelectPipe);
|
4647 | return I18nSelectPipe;
|
4648 | }());
|
4649 |
|
4650 | /**
|
4651 | * @license
|
4652 | * Copyright Google Inc. All Rights Reserved.
|
4653 | *
|
4654 | * Use of this source code is governed by an MIT-style license that can be
|
4655 | * found in the LICENSE file at https://angular.io/license
|
4656 | */
|
4657 | /**
|
4658 | * @ngModule CommonModule
|
4659 | * @description
|
4660 | *
|
4661 | * Converts a value into its JSON-format representation. Useful for debugging.
|
4662 | *
|
4663 | * @usageNotes
|
4664 | *
|
4665 | * The following component uses a JSON pipe to convert an object
|
4666 | * to JSON format, and displays the string in both formats for comparison.
|
4667 | *
|
4668 | * {@example common/pipes/ts/json_pipe.ts region='JsonPipe'}
|
4669 | *
|
4670 | * @publicApi
|
4671 | */
|
4672 | var JsonPipe = /** @class */ (function () {
|
4673 | function JsonPipe() {
|
4674 | }
|
4675 | /**
|
4676 | * @param value A value of any type to convert into a JSON-format string.
|
4677 | */
|
4678 | JsonPipe.prototype.transform = function (value) { return JSON.stringify(value, null, 2); };
|
4679 | JsonPipe = __decorate([
|
4680 | Pipe({ name: 'json', pure: false })
|
4681 | ], JsonPipe);
|
4682 | return JsonPipe;
|
4683 | }());
|
4684 |
|
4685 | /**
|
4686 | * @license
|
4687 | * Copyright Google Inc. All Rights Reserved.
|
4688 | *
|
4689 | * Use of this source code is governed by an MIT-style license that can be
|
4690 | * found in the LICENSE file at https://angular.io/license
|
4691 | */
|
4692 | function makeKeyValuePair(key, value) {
|
4693 | return { key: key, value: value };
|
4694 | }
|
4695 | /**
|
4696 | * @ngModule CommonModule
|
4697 | * @description
|
4698 | *
|
4699 | * Transforms Object or Map into an array of key value pairs.
|
4700 | *
|
4701 | * The output array will be ordered by keys.
|
4702 | * By default the comparator will be by Unicode point value.
|
4703 | * You can optionally pass a compareFn if your keys are complex types.
|
4704 | *
|
4705 | * @usageNotes
|
4706 | * ### Examples
|
4707 | *
|
4708 | * This examples show how an Object or a Map can be iterated by ngFor with the use of this keyvalue
|
4709 | * pipe.
|
4710 | *
|
4711 | * {@example common/pipes/ts/keyvalue_pipe.ts region='KeyValuePipe'}
|
4712 | *
|
4713 | * @publicApi
|
4714 | */
|
4715 | var KeyValuePipe = /** @class */ (function () {
|
4716 | function KeyValuePipe(differs) {
|
4717 | this.differs = differs;
|
4718 | this.keyValues = [];
|
4719 | }
|
4720 | KeyValuePipe.prototype.transform = function (input, compareFn) {
|
4721 | var _this = this;
|
4722 | if (compareFn === void 0) { compareFn = defaultComparator; }
|
4723 | if (!input || (!(input instanceof Map) && typeof input !== 'object')) {
|
4724 | return null;
|
4725 | }
|
4726 | if (!this.differ) {
|
4727 | // make a differ for whatever type we've been passed in
|
4728 | this.differ = this.differs.find(input).create();
|
4729 | }
|
4730 | var differChanges = this.differ.diff(input);
|
4731 | if (differChanges) {
|
4732 | this.keyValues = [];
|
4733 | differChanges.forEachItem(function (r) {
|
4734 | _this.keyValues.push(makeKeyValuePair(r.key, r.currentValue));
|
4735 | });
|
4736 | this.keyValues.sort(compareFn);
|
4737 | }
|
4738 | return this.keyValues;
|
4739 | };
|
4740 | KeyValuePipe = __decorate([
|
4741 | Pipe({ name: 'keyvalue', pure: false }),
|
4742 | __metadata("design:paramtypes", [KeyValueDiffers])
|
4743 | ], KeyValuePipe);
|
4744 | return KeyValuePipe;
|
4745 | }());
|
4746 | function defaultComparator(keyValueA, keyValueB) {
|
4747 | var a = keyValueA.key;
|
4748 | var b = keyValueB.key;
|
4749 | // if same exit with 0;
|
4750 | if (a === b)
|
4751 | return 0;
|
4752 | // make sure that undefined are at the end of the sort.
|
4753 | if (a === undefined)
|
4754 | return 1;
|
4755 | if (b === undefined)
|
4756 | return -1;
|
4757 | // make sure that nulls are at the end of the sort.
|
4758 | if (a === null)
|
4759 | return 1;
|
4760 | if (b === null)
|
4761 | return -1;
|
4762 | if (typeof a == 'string' && typeof b == 'string') {
|
4763 | return a < b ? -1 : 1;
|
4764 | }
|
4765 | if (typeof a == 'number' && typeof b == 'number') {
|
4766 | return a - b;
|
4767 | }
|
4768 | if (typeof a == 'boolean' && typeof b == 'boolean') {
|
4769 | return a < b ? -1 : 1;
|
4770 | }
|
4771 | // `a` and `b` are of different types. Compare their string values.
|
4772 | var aString = String(a);
|
4773 | var bString = String(b);
|
4774 | return aString == bString ? 0 : aString < bString ? -1 : 1;
|
4775 | }
|
4776 |
|
4777 | /**
|
4778 | * @license
|
4779 | * Copyright Google Inc. All Rights Reserved.
|
4780 | *
|
4781 | * Use of this source code is governed by an MIT-style license that can be
|
4782 | * found in the LICENSE file at https://angular.io/license
|
4783 | */
|
4784 | /**
|
4785 | * @ngModule CommonModule
|
4786 | * @description
|
4787 | *
|
4788 | * Transforms a number into a string,
|
4789 | * formatted according to locale rules that determine group sizing and
|
4790 | * separator, decimal-point character, and other locale-specific
|
4791 | * configurations.
|
4792 | *
|
4793 | * If no parameters are specified, the function rounds off to the nearest value using this
|
4794 | * [rounding method](https://en.wikibooks.org/wiki/Arithmetic/Rounding).
|
4795 | * The behavior differs from that of the JavaScript ```Math.round()``` function.
|
4796 | * In the following case for example, the pipe rounds down where
|
4797 | * ```Math.round()``` rounds up:
|
4798 | *
|
4799 | * ```html
|
4800 | * -2.5 | number:'1.0-0'
|
4801 | * > -3
|
4802 | * Math.round(-2.5)
|
4803 | * > -2
|
4804 | * ```
|
4805 | *
|
4806 | * @see `formatNumber()`
|
4807 | *
|
4808 | * @usageNotes
|
4809 | * The following code shows how the pipe transforms numbers
|
4810 | * into text strings, according to various format specifications,
|
4811 | * where the caller's default locale is `en-US`.
|
4812 | *
|
4813 | * ### Example
|
4814 | *
|
4815 | * <code-example path="common/pipes/ts/number_pipe.ts" region='NumberPipe'></code-example>
|
4816 | *
|
4817 | * @publicApi
|
4818 | */
|
4819 | var DecimalPipe = /** @class */ (function () {
|
4820 | function DecimalPipe(_locale) {
|
4821 | this._locale = _locale;
|
4822 | }
|
4823 | DecimalPipe_1 = DecimalPipe;
|
4824 | /**
|
4825 | * @param value The number to be formatted.
|
4826 | * @param digitsInfo Decimal representation options, specified by a string
|
4827 | * in the following format:<br>
|
4828 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
4829 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
4830 | * Default is `1`.
|
4831 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
4832 | * Default is `0`.
|
4833 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
4834 | * Default is `3`.
|
4835 | * @param locale A locale code for the locale format rules to use.
|
4836 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
4837 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
4838 | */
|
4839 | DecimalPipe.prototype.transform = function (value, digitsInfo, locale) {
|
4840 | if (isEmpty(value))
|
4841 | return null;
|
4842 | locale = locale || this._locale;
|
4843 | try {
|
4844 | var num = strToNumber(value);
|
4845 | return formatNumber(num, locale, digitsInfo);
|
4846 | }
|
4847 | catch (error) {
|
4848 | throw invalidPipeArgumentError(DecimalPipe_1, error.message);
|
4849 | }
|
4850 | };
|
4851 | var DecimalPipe_1;
|
4852 | DecimalPipe = DecimalPipe_1 = __decorate([
|
4853 | Pipe({ name: 'number' }),
|
4854 | __param(0, Inject(LOCALE_ID)),
|
4855 | __metadata("design:paramtypes", [String])
|
4856 | ], DecimalPipe);
|
4857 | return DecimalPipe;
|
4858 | }());
|
4859 | /**
|
4860 | * @ngModule CommonModule
|
4861 | * @description
|
4862 | *
|
4863 | * Transforms a number to a percentage
|
4864 | * string, formatted according to locale rules that determine group sizing and
|
4865 | * separator, decimal-point character, and other locale-specific
|
4866 | * configurations.
|
4867 | *
|
4868 | * @see `formatPercent()`
|
4869 | *
|
4870 | * @usageNotes
|
4871 | * The following code shows how the pipe transforms numbers
|
4872 | * into text strings, according to various format specifications,
|
4873 | * where the caller's default locale is `en-US`.
|
4874 | *
|
4875 | * <code-example path="common/pipes/ts/percent_pipe.ts" region='PercentPipe'></code-example>
|
4876 | *
|
4877 | * @publicApi
|
4878 | */
|
4879 | var PercentPipe = /** @class */ (function () {
|
4880 | function PercentPipe(_locale) {
|
4881 | this._locale = _locale;
|
4882 | }
|
4883 | PercentPipe_1 = PercentPipe;
|
4884 | /**
|
4885 | *
|
4886 | * @param value The number to be formatted as a percentage.
|
4887 | * @param digitsInfo Decimal representation options, specified by a string
|
4888 | * in the following format:<br>
|
4889 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
4890 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
4891 | * Default is `1`.
|
4892 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
4893 | * Default is `0`.
|
4894 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
4895 | * Default is `0`.
|
4896 | * @param locale A locale code for the locale format rules to use.
|
4897 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
4898 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
4899 | */
|
4900 | PercentPipe.prototype.transform = function (value, digitsInfo, locale) {
|
4901 | if (isEmpty(value))
|
4902 | return null;
|
4903 | locale = locale || this._locale;
|
4904 | try {
|
4905 | var num = strToNumber(value);
|
4906 | return formatPercent(num, locale, digitsInfo);
|
4907 | }
|
4908 | catch (error) {
|
4909 | throw invalidPipeArgumentError(PercentPipe_1, error.message);
|
4910 | }
|
4911 | };
|
4912 | var PercentPipe_1;
|
4913 | PercentPipe = PercentPipe_1 = __decorate([
|
4914 | Pipe({ name: 'percent' }),
|
4915 | __param(0, Inject(LOCALE_ID)),
|
4916 | __metadata("design:paramtypes", [String])
|
4917 | ], PercentPipe);
|
4918 | return PercentPipe;
|
4919 | }());
|
4920 | /**
|
4921 | * @ngModule CommonModule
|
4922 | * @description
|
4923 | *
|
4924 | * Transforms a number to a currency string, formatted according to locale rules
|
4925 | * that determine group sizing and separator, decimal-point character,
|
4926 | * and other locale-specific configurations.
|
4927 | *
|
4928 | * {@a currency-code-deprecation}
|
4929 | * <div class="alert is-helpful">
|
4930 | *
|
4931 | * **Deprecation notice:**
|
4932 | *
|
4933 | * The default currency code is currently always `USD` but this is deprecated from v9.
|
4934 | *
|
4935 | * **In v11 the default currency code will be taken from the current locale identified by
|
4936 | * the `LOCAL_ID` token. See the [i18n guide](guide/i18n#setting-up-the-locale-of-your-app) for
|
4937 | * more information.**
|
4938 | *
|
4939 | * If you need the previous behavior then set it by creating a `DEFAULT_CURRENCY_CODE` provider in
|
4940 | * your application `NgModule`:
|
4941 | *
|
4942 | * ```ts
|
4943 | * {provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'}
|
4944 | * ```
|
4945 | *
|
4946 | * </div>
|
4947 | *
|
4948 | * @see `getCurrencySymbol()`
|
4949 | * @see `formatCurrency()`
|
4950 | *
|
4951 | * @usageNotes
|
4952 | * The following code shows how the pipe transforms numbers
|
4953 | * into text strings, according to various format specifications,
|
4954 | * where the caller's default locale is `en-US`.
|
4955 | *
|
4956 | * <code-example path="common/pipes/ts/currency_pipe.ts" region='CurrencyPipe'></code-example>
|
4957 | *
|
4958 | * @publicApi
|
4959 | */
|
4960 | var CurrencyPipe = /** @class */ (function () {
|
4961 | function CurrencyPipe(_locale, _defaultCurrencyCode) {
|
4962 | if (_defaultCurrencyCode === void 0) { _defaultCurrencyCode = 'USD'; }
|
4963 | this._locale = _locale;
|
4964 | this._defaultCurrencyCode = _defaultCurrencyCode;
|
4965 | }
|
4966 | CurrencyPipe_1 = CurrencyPipe;
|
4967 | /**
|
4968 | *
|
4969 | * @param value The number to be formatted as currency.
|
4970 | * @param currencyCode The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code,
|
4971 | * such as `USD` for the US dollar and `EUR` for the euro. The default currency code can be
|
4972 | * configured using the `DEFAULT_CURRENCY_CODE` injection token.
|
4973 | * @param display The format for the currency indicator. One of the following:
|
4974 | * - `code`: Show the code (such as `USD`).
|
4975 | * - `symbol`(default): Show the symbol (such as `$`).
|
4976 | * - `symbol-narrow`: Use the narrow symbol for locales that have two symbols for their
|
4977 | * currency.
|
4978 | * For example, the Canadian dollar CAD has the symbol `CA$` and the symbol-narrow `$`. If the
|
4979 | * locale has no narrow symbol, uses the standard symbol for the locale.
|
4980 | * - String: Use the given string value instead of a code or a symbol.
|
4981 | * For example, an empty string will suppress the currency & symbol.
|
4982 | * - Boolean (marked deprecated in v5): `true` for symbol and false for `code`.
|
4983 | *
|
4984 | * @param digitsInfo Decimal representation options, specified by a string
|
4985 | * in the following format:<br>
|
4986 | * <code>{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}</code>.
|
4987 | * - `minIntegerDigits`: The minimum number of integer digits before the decimal point.
|
4988 | * Default is `1`.
|
4989 | * - `minFractionDigits`: The minimum number of digits after the decimal point.
|
4990 | * Default is `2`.
|
4991 | * - `maxFractionDigits`: The maximum number of digits after the decimal point.
|
4992 | * Default is `2`.
|
4993 | * If not provided, the number will be formatted with the proper amount of digits,
|
4994 | * depending on what the [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) specifies.
|
4995 | * For example, the Canadian dollar has 2 digits, whereas the Chilean peso has none.
|
4996 | * @param locale A locale code for the locale format rules to use.
|
4997 | * When not supplied, uses the value of `LOCALE_ID`, which is `en-US` by default.
|
4998 | * See [Setting your app locale](guide/i18n#setting-up-the-locale-of-your-app).
|
4999 | */
|
5000 | CurrencyPipe.prototype.transform = function (value, currencyCode, display, digitsInfo, locale) {
|
5001 | if (display === void 0) { display = 'symbol'; }
|
5002 | if (isEmpty(value))
|
5003 | return null;
|
5004 | locale = locale || this._locale;
|
5005 | if (typeof display === 'boolean') {
|
5006 | if (console && console.warn) {
|
5007 | console.warn("Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are \"code\", \"symbol\" or \"symbol-narrow\".");
|
5008 | }
|
5009 | display = display ? 'symbol' : 'code';
|
5010 | }
|
5011 | var currency = currencyCode || this._defaultCurrencyCode;
|
5012 | if (display !== 'code') {
|
5013 | if (display === 'symbol' || display === 'symbol-narrow') {
|
5014 | currency = getCurrencySymbol(currency, display === 'symbol' ? 'wide' : 'narrow', locale);
|
5015 | }
|
5016 | else {
|
5017 | currency = display;
|
5018 | }
|
5019 | }
|
5020 | try {
|
5021 | var num = strToNumber(value);
|
5022 | return formatCurrency(num, locale, currency, currencyCode, digitsInfo);
|
5023 | }
|
5024 | catch (error) {
|
5025 | throw invalidPipeArgumentError(CurrencyPipe_1, error.message);
|
5026 | }
|
5027 | };
|
5028 | var CurrencyPipe_1;
|
5029 | CurrencyPipe = CurrencyPipe_1 = __decorate([
|
5030 | Pipe({ name: 'currency' }),
|
5031 | __param(0, Inject(LOCALE_ID)),
|
5032 | __param(1, Inject(DEFAULT_CURRENCY_CODE)),
|
5033 | __metadata("design:paramtypes", [String, String])
|
5034 | ], CurrencyPipe);
|
5035 | return CurrencyPipe;
|
5036 | }());
|
5037 | function isEmpty(value) {
|
5038 | return value == null || value === '' || value !== value;
|
5039 | }
|
5040 | /**
|
5041 | * Transforms a string into a number (if needed).
|
5042 | */
|
5043 | function strToNumber(value) {
|
5044 | // Convert strings to numbers
|
5045 | if (typeof value === 'string' && !isNaN(Number(value) - parseFloat(value))) {
|
5046 | return Number(value);
|
5047 | }
|
5048 | if (typeof value !== 'number') {
|
5049 | throw new Error(value + " is not a number");
|
5050 | }
|
5051 | return value;
|
5052 | }
|
5053 |
|
5054 | /**
|
5055 | * @license
|
5056 | * Copyright Google Inc. All Rights Reserved.
|
5057 | *
|
5058 | * Use of this source code is governed by an MIT-style license that can be
|
5059 | * found in the LICENSE file at https://angular.io/license
|
5060 | */
|
5061 | /**
|
5062 | * @ngModule CommonModule
|
5063 | * @description
|
5064 | *
|
5065 | * Creates a new `Array` or `String` containing a subset (slice) of the elements.
|
5066 | *
|
5067 | * @usageNotes
|
5068 | *
|
5069 | * All behavior is based on the expected behavior of the JavaScript API `Array.prototype.slice()`
|
5070 | * and `String.prototype.slice()`.
|
5071 | *
|
5072 | * When operating on an `Array`, the returned `Array` is always a copy even when all
|
5073 | * the elements are being returned.
|
5074 | *
|
5075 | * When operating on a blank value, the pipe returns the blank value.
|
5076 | *
|
5077 | * ### List Example
|
5078 | *
|
5079 | * This `ngFor` example:
|
5080 | *
|
5081 | * {@example common/pipes/ts/slice_pipe.ts region='SlicePipe_list'}
|
5082 | *
|
5083 | * produces the following:
|
5084 | *
|
5085 | * ```html
|
5086 | * <li>b</li>
|
5087 | * <li>c</li>
|
5088 | * ```
|
5089 | *
|
5090 | * ### String Examples
|
5091 | *
|
5092 | * {@example common/pipes/ts/slice_pipe.ts region='SlicePipe_string'}
|
5093 | *
|
5094 | * @publicApi
|
5095 | */
|
5096 | var SlicePipe = /** @class */ (function () {
|
5097 | function SlicePipe() {
|
5098 | }
|
5099 | SlicePipe_1 = SlicePipe;
|
5100 | SlicePipe.prototype.transform = function (value, start, end) {
|
5101 | if (value == null)
|
5102 | return value;
|
5103 | if (!this.supports(value)) {
|
5104 | throw invalidPipeArgumentError(SlicePipe_1, value);
|
5105 | }
|
5106 | return value.slice(start, end);
|
5107 | };
|
5108 | SlicePipe.prototype.supports = function (obj) { return typeof obj === 'string' || Array.isArray(obj); };
|
5109 | var SlicePipe_1;
|
5110 | SlicePipe = SlicePipe_1 = __decorate([
|
5111 | Pipe({ name: 'slice', pure: false })
|
5112 | ], SlicePipe);
|
5113 | return SlicePipe;
|
5114 | }());
|
5115 |
|
5116 | /**
|
5117 | * @license
|
5118 | * Copyright Google Inc. All Rights Reserved.
|
5119 | *
|
5120 | * Use of this source code is governed by an MIT-style license that can be
|
5121 | * found in the LICENSE file at https://angular.io/license
|
5122 | */
|
5123 | /**
|
5124 | * A collection of Angular pipes that are likely to be used in each and every application.
|
5125 | */
|
5126 | var COMMON_PIPES = [
|
5127 | AsyncPipe,
|
5128 | UpperCasePipe,
|
5129 | LowerCasePipe,
|
5130 | JsonPipe,
|
5131 | SlicePipe,
|
5132 | DecimalPipe,
|
5133 | PercentPipe,
|
5134 | TitleCasePipe,
|
5135 | CurrencyPipe,
|
5136 | DatePipe,
|
5137 | I18nPluralPipe,
|
5138 | I18nSelectPipe,
|
5139 | KeyValuePipe,
|
5140 | ];
|
5141 |
|
5142 | /**
|
5143 | * @license
|
5144 | * Copyright Google Inc. All Rights Reserved.
|
5145 | *
|
5146 | * Use of this source code is governed by an MIT-style license that can be
|
5147 | * found in the LICENSE file at https://angular.io/license
|
5148 | */
|
5149 | // Note: This does not contain the location providers,
|
5150 | // as they need some platform specific implementations to work.
|
5151 | /**
|
5152 | * Exports all the basic Angular directives and pipes,
|
5153 | * such as `NgIf`, `NgForOf`, `DecimalPipe`, and so on.
|
5154 | * Re-exported by `BrowserModule`, which is included automatically in the root
|
5155 | * `AppModule` when you create a new app with the CLI `new` command.
|
5156 | *
|
5157 | * * The `providers` options configure the NgModule's injector to provide
|
5158 | * localization dependencies to members.
|
5159 | * * The `exports` options make the declared directives and pipes available for import
|
5160 | * by other NgModules.
|
5161 | *
|
5162 | * @publicApi
|
5163 | */
|
5164 | var CommonModule = /** @class */ (function () {
|
5165 | function CommonModule() {
|
5166 | }
|
5167 | CommonModule = __decorate([
|
5168 | NgModule({
|
5169 | declarations: [COMMON_DIRECTIVES, COMMON_PIPES],
|
5170 | exports: [COMMON_DIRECTIVES, COMMON_PIPES],
|
5171 | providers: [
|
5172 | { provide: NgLocalization, useClass: NgLocaleLocalization },
|
5173 | ],
|
5174 | })
|
5175 | ], CommonModule);
|
5176 | return CommonModule;
|
5177 | }());
|
5178 |
|
5179 | /**
|
5180 | * @license
|
5181 | * Copyright Google Inc. All Rights Reserved.
|
5182 | *
|
5183 | * Use of this source code is governed by an MIT-style license that can be
|
5184 | * found in the LICENSE file at https://angular.io/license
|
5185 | */
|
5186 | var PLATFORM_BROWSER_ID = 'browser';
|
5187 | var PLATFORM_SERVER_ID = 'server';
|
5188 | var PLATFORM_WORKER_APP_ID = 'browserWorkerApp';
|
5189 | var PLATFORM_WORKER_UI_ID = 'browserWorkerUi';
|
5190 | /**
|
5191 | * Returns whether a platform id represents a browser platform.
|
5192 | * @publicApi
|
5193 | */
|
5194 | function isPlatformBrowser(platformId) {
|
5195 | return platformId === PLATFORM_BROWSER_ID;
|
5196 | }
|
5197 | /**
|
5198 | * Returns whether a platform id represents a server platform.
|
5199 | * @publicApi
|
5200 | */
|
5201 | function isPlatformServer(platformId) {
|
5202 | return platformId === PLATFORM_SERVER_ID;
|
5203 | }
|
5204 | /**
|
5205 | * Returns whether a platform id represents a web worker app platform.
|
5206 | * @publicApi
|
5207 | */
|
5208 | function isPlatformWorkerApp(platformId) {
|
5209 | return platformId === PLATFORM_WORKER_APP_ID;
|
5210 | }
|
5211 | /**
|
5212 | * Returns whether a platform id represents a web worker UI platform.
|
5213 | * @publicApi
|
5214 | */
|
5215 | function isPlatformWorkerUi(platformId) {
|
5216 | return platformId === PLATFORM_WORKER_UI_ID;
|
5217 | }
|
5218 |
|
5219 | /**
|
5220 | * @license
|
5221 | * Copyright Google Inc. All Rights Reserved.
|
5222 | *
|
5223 | * Use of this source code is governed by an MIT-style license that can be
|
5224 | * found in the LICENSE file at https://angular.io/license
|
5225 | */
|
5226 | /**
|
5227 | * @publicApi
|
5228 | */
|
5229 | var VERSION = new Version('9.0.4');
|
5230 |
|
5231 | /**
|
5232 | * @license
|
5233 | * Copyright Google Inc. All Rights Reserved.
|
5234 | *
|
5235 | * Use of this source code is governed by an MIT-style license that can be
|
5236 | * found in the LICENSE file at https://angular.io/license
|
5237 | */
|
5238 | /**
|
5239 | * Defines a scroll position manager. Implemented by `BrowserViewportScroller`.
|
5240 | *
|
5241 | * @publicApi
|
5242 | */
|
5243 | var ViewportScroller = /** @class */ (function () {
|
5244 | function ViewportScroller() {
|
5245 | }
|
5246 | // De-sugared tree-shakable injection
|
5247 | // See #23917
|
5248 | /** @nocollapse */
|
5249 | ViewportScroller.ɵprov = ɵɵdefineInjectable({
|
5250 | token: ViewportScroller,
|
5251 | providedIn: 'root',
|
5252 | factory: function () { return new BrowserViewportScroller(ɵɵinject(DOCUMENT), window, ɵɵinject(ErrorHandler)); }
|
5253 | });
|
5254 | return ViewportScroller;
|
5255 | }());
|
5256 | /**
|
5257 | * Manages the scroll position for a browser window.
|
5258 | */
|
5259 | var BrowserViewportScroller = /** @class */ (function () {
|
5260 | function BrowserViewportScroller(document, window, errorHandler) {
|
5261 | this.document = document;
|
5262 | this.window = window;
|
5263 | this.errorHandler = errorHandler;
|
5264 | this.offset = function () { return [0, 0]; };
|
5265 | }
|
5266 | /**
|
5267 | * Configures the top offset used when scrolling to an anchor.
|
5268 | * @param offset A position in screen coordinates (a tuple with x and y values)
|
5269 | * or a function that returns the top offset position.
|
5270 | *
|
5271 | */
|
5272 | BrowserViewportScroller.prototype.setOffset = function (offset) {
|
5273 | if (Array.isArray(offset)) {
|
5274 | this.offset = function () { return offset; };
|
5275 | }
|
5276 | else {
|
5277 | this.offset = offset;
|
5278 | }
|
5279 | };
|
5280 | /**
|
5281 | * Retrieves the current scroll position.
|
5282 | * @returns The position in screen coordinates.
|
5283 | */
|
5284 | BrowserViewportScroller.prototype.getScrollPosition = function () {
|
5285 | if (this.supportScrollRestoration()) {
|
5286 | return [this.window.scrollX, this.window.scrollY];
|
5287 | }
|
5288 | else {
|
5289 | return [0, 0];
|
5290 | }
|
5291 | };
|
5292 | /**
|
5293 | * Sets the scroll position.
|
5294 | * @param position The new position in screen coordinates.
|
5295 | */
|
5296 | BrowserViewportScroller.prototype.scrollToPosition = function (position) {
|
5297 | if (this.supportScrollRestoration()) {
|
5298 | this.window.scrollTo(position[0], position[1]);
|
5299 | }
|
5300 | };
|
5301 | /**
|
5302 | * Scrolls to an anchor element.
|
5303 | * @param anchor The ID of the anchor element.
|
5304 | */
|
5305 | BrowserViewportScroller.prototype.scrollToAnchor = function (anchor) {
|
5306 | if (this.supportScrollRestoration()) {
|
5307 | // Escape anything passed to `querySelector` as it can throw errors and stop the application
|
5308 | // from working if invalid values are passed.
|
5309 | if (this.window.CSS && this.window.CSS.escape) {
|
5310 | anchor = this.window.CSS.escape(anchor);
|
5311 | }
|
5312 | else {
|
5313 | anchor = anchor.replace(/(\"|\'\ |:|\.|\[|\]|,|=)/g, '\\$1');
|
5314 | }
|
5315 | try {
|
5316 | var elSelectedById = this.document.querySelector("#" + anchor);
|
5317 | if (elSelectedById) {
|
5318 | this.scrollToElement(elSelectedById);
|
5319 | return;
|
5320 | }
|
5321 | var elSelectedByName = this.document.querySelector("[name='" + anchor + "']");
|
5322 | if (elSelectedByName) {
|
5323 | this.scrollToElement(elSelectedByName);
|
5324 | return;
|
5325 | }
|
5326 | }
|
5327 | catch (e) {
|
5328 | this.errorHandler.handleError(e);
|
5329 | }
|
5330 | }
|
5331 | };
|
5332 | /**
|
5333 | * Disables automatic scroll restoration provided by the browser.
|
5334 | */
|
5335 | BrowserViewportScroller.prototype.setHistoryScrollRestoration = function (scrollRestoration) {
|
5336 | if (this.supportScrollRestoration()) {
|
5337 | var history_1 = this.window.history;
|
5338 | if (history_1 && history_1.scrollRestoration) {
|
5339 | history_1.scrollRestoration = scrollRestoration;
|
5340 | }
|
5341 | }
|
5342 | };
|
5343 | BrowserViewportScroller.prototype.scrollToElement = function (el) {
|
5344 | var rect = el.getBoundingClientRect();
|
5345 | var left = rect.left + this.window.pageXOffset;
|
5346 | var top = rect.top + this.window.pageYOffset;
|
5347 | var offset = this.offset();
|
5348 | this.window.scrollTo(left - offset[0], top - offset[1]);
|
5349 | };
|
5350 | /**
|
5351 | * We only support scroll restoration when we can get a hold of window.
|
5352 | * This means that we do not support this behavior when running in a web worker.
|
5353 | *
|
5354 | * Lifting this restriction right now would require more changes in the dom adapter.
|
5355 | * Since webworkers aren't widely used, we will lift it once RouterScroller is
|
5356 | * battle-tested.
|
5357 | */
|
5358 | BrowserViewportScroller.prototype.supportScrollRestoration = function () {
|
5359 | try {
|
5360 | return !!this.window && !!this.window.scrollTo;
|
5361 | }
|
5362 | catch (_a) {
|
5363 | return false;
|
5364 | }
|
5365 | };
|
5366 | return BrowserViewportScroller;
|
5367 | }());
|
5368 | /**
|
5369 | * Provides an empty implementation of the viewport scroller. This will
|
5370 | * live in @angular/common as it will be used by both platform-server and platform-webworker.
|
5371 | */
|
5372 | var NullViewportScroller = /** @class */ (function () {
|
5373 | function NullViewportScroller() {
|
5374 | }
|
5375 | /**
|
5376 | * Empty implementation
|
5377 | */
|
5378 | NullViewportScroller.prototype.setOffset = function (offset) { };
|
5379 | /**
|
5380 | * Empty implementation
|
5381 | */
|
5382 | NullViewportScroller.prototype.getScrollPosition = function () { return [0, 0]; };
|
5383 | /**
|
5384 | * Empty implementation
|
5385 | */
|
5386 | NullViewportScroller.prototype.scrollToPosition = function (position) { };
|
5387 | /**
|
5388 | * Empty implementation
|
5389 | */
|
5390 | NullViewportScroller.prototype.scrollToAnchor = function (anchor) { };
|
5391 | /**
|
5392 | * Empty implementation
|
5393 | */
|
5394 | NullViewportScroller.prototype.setHistoryScrollRestoration = function (scrollRestoration) { };
|
5395 | return NullViewportScroller;
|
5396 | }());
|
5397 |
|
5398 | /**
|
5399 | * @license
|
5400 | * Copyright Google Inc. All Rights Reserved.
|
5401 | *
|
5402 | * Use of this source code is governed by an MIT-style license that can be
|
5403 | * found in the LICENSE file at https://angular.io/license
|
5404 | */
|
5405 |
|
5406 | /**
|
5407 | * @license
|
5408 | * Copyright Google Inc. All Rights Reserved.
|
5409 | *
|
5410 | * Use of this source code is governed by an MIT-style license that can be
|
5411 | * found in the LICENSE file at https://angular.io/license
|
5412 | */
|
5413 | // This file only reexports content of the `src` folder. Keep it that way.
|
5414 |
|
5415 | /**
|
5416 | * @license
|
5417 | * Copyright Google Inc. All Rights Reserved.
|
5418 | *
|
5419 | * Use of this source code is governed by an MIT-style license that can be
|
5420 | * found in the LICENSE file at https://angular.io/license
|
5421 | */
|
5422 |
|
5423 | /**
|
5424 | * Generated bundle index. Do not edit.
|
5425 | */
|
5426 |
|
5427 | export { APP_BASE_HREF, AsyncPipe, CommonModule, CurrencyPipe, DOCUMENT, DatePipe, DecimalPipe, FormStyle, FormatWidth, HashLocationStrategy, I18nPluralPipe, I18nSelectPipe, JsonPipe, KeyValuePipe, LOCATION_INITIALIZED, Location, LocationStrategy, LowerCasePipe, NgClass, NgComponentOutlet, NgForOf, NgForOfContext, NgIf, NgIfContext, NgLocaleLocalization, NgLocalization, NgPlural, NgPluralCase, NgStyle, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NumberFormatStyle, NumberSymbol, PathLocationStrategy, PercentPipe, PlatformLocation, Plural, SlicePipe, TitleCasePipe, TranslationWidth, UpperCasePipe, VERSION, ViewportScroller, WeekDay, formatCurrency, formatDate, formatNumber, formatPercent, getCurrencySymbol, getLocaleCurrencyCode, getLocaleCurrencyName, getLocaleCurrencySymbol, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleDayNames, getLocaleDayPeriods, getLocaleEraNames, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocaleFirstDayOfWeek, getLocaleId, getLocaleMonthNames, getLocaleNumberFormat, getLocaleNumberSymbol, getLocalePluralCase, getLocaleTimeFormat, getLocaleWeekEndRange, getNumberOfCurrencyDigits, isPlatformBrowser, isPlatformServer, isPlatformWorkerApp, isPlatformWorkerUi, registerLocaleData, BrowserPlatformLocation as ɵBrowserPlatformLocation, DomAdapter as ɵDomAdapter, NullViewportScroller as ɵNullViewportScroller, PLATFORM_BROWSER_ID as ɵPLATFORM_BROWSER_ID, PLATFORM_SERVER_ID as ɵPLATFORM_SERVER_ID, PLATFORM_WORKER_APP_ID as ɵPLATFORM_WORKER_APP_ID, PLATFORM_WORKER_UI_ID as ɵPLATFORM_WORKER_UI_ID, useBrowserPlatformLocation as ɵangular_packages_common_common_a, createBrowserPlatformLocation as ɵangular_packages_common_common_b, createLocation as ɵangular_packages_common_common_c, provideLocationStrategy as ɵangular_packages_common_common_d, COMMON_DIRECTIVES as ɵangular_packages_common_common_e, COMMON_PIPES as ɵangular_packages_common_common_f, getDOM as ɵgetDOM, parseCookieValue as ɵparseCookieValue, setRootDomAdapter as ɵsetRootDomAdapter };
|
5428 | //# sourceMappingURL=common.js.map
|