[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { ɵisObservable as isObservable, ɵisPromise as isPromise } from '@angular/core';
|
---|
| 9 | import { from, of } from 'rxjs';
|
---|
| 10 | export function shallowEqualArrays(a, b) {
|
---|
| 11 | if (a.length !== b.length)
|
---|
| 12 | return false;
|
---|
| 13 | for (let i = 0; i < a.length; ++i) {
|
---|
| 14 | if (!shallowEqual(a[i], b[i]))
|
---|
| 15 | return false;
|
---|
| 16 | }
|
---|
| 17 | return true;
|
---|
| 18 | }
|
---|
| 19 | export function shallowEqual(a, b) {
|
---|
| 20 | // While `undefined` should never be possible, it would sometimes be the case in IE 11
|
---|
| 21 | // and pre-chromium Edge. The check below accounts for this edge case.
|
---|
| 22 | const k1 = a ? Object.keys(a) : undefined;
|
---|
| 23 | const k2 = b ? Object.keys(b) : undefined;
|
---|
| 24 | if (!k1 || !k2 || k1.length != k2.length) {
|
---|
| 25 | return false;
|
---|
| 26 | }
|
---|
| 27 | let key;
|
---|
| 28 | for (let i = 0; i < k1.length; i++) {
|
---|
| 29 | key = k1[i];
|
---|
| 30 | if (!equalArraysOrString(a[key], b[key])) {
|
---|
| 31 | return false;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | return true;
|
---|
| 35 | }
|
---|
| 36 | /**
|
---|
| 37 | * Test equality for arrays of strings or a string.
|
---|
| 38 | */
|
---|
| 39 | export function equalArraysOrString(a, b) {
|
---|
| 40 | if (Array.isArray(a) && Array.isArray(b)) {
|
---|
| 41 | if (a.length !== b.length)
|
---|
| 42 | return false;
|
---|
| 43 | const aSorted = [...a].sort();
|
---|
| 44 | const bSorted = [...b].sort();
|
---|
| 45 | return aSorted.every((val, index) => bSorted[index] === val);
|
---|
| 46 | }
|
---|
| 47 | else {
|
---|
| 48 | return a === b;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | /**
|
---|
| 52 | * Flattens single-level nested arrays.
|
---|
| 53 | */
|
---|
| 54 | export function flatten(arr) {
|
---|
| 55 | return Array.prototype.concat.apply([], arr);
|
---|
| 56 | }
|
---|
| 57 | /**
|
---|
| 58 | * Return the last element of an array.
|
---|
| 59 | */
|
---|
| 60 | export function last(a) {
|
---|
| 61 | return a.length > 0 ? a[a.length - 1] : null;
|
---|
| 62 | }
|
---|
| 63 | /**
|
---|
| 64 | * Verifys all booleans in an array are `true`.
|
---|
| 65 | */
|
---|
| 66 | export function and(bools) {
|
---|
| 67 | return !bools.some(v => !v);
|
---|
| 68 | }
|
---|
| 69 | export function forEach(map, callback) {
|
---|
| 70 | for (const prop in map) {
|
---|
| 71 | if (map.hasOwnProperty(prop)) {
|
---|
| 72 | callback(map[prop], prop);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | export function wrapIntoObservable(value) {
|
---|
| 77 | if (isObservable(value)) {
|
---|
| 78 | return value;
|
---|
| 79 | }
|
---|
| 80 | if (isPromise(value)) {
|
---|
| 81 | // Use `Promise.resolve()` to wrap promise-like instances.
|
---|
| 82 | // Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
|
---|
| 83 | // change detection.
|
---|
| 84 | return from(Promise.resolve(value));
|
---|
| 85 | }
|
---|
| 86 | return of(value);
|
---|
| 87 | }
|
---|
| 88 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29sbGVjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvdXRpbHMvY29sbGVjdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUM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