2019-04-23 07:16:08 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-04-23 07:16:08 -07:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export function stripPrefix(val: string, prefix: string): string {
|
|
|
|
|
return val.startsWith(prefix) ? val.substring(prefix.length) : val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deepEqual(a: any, b: any): boolean {
|
|
|
|
|
if (a === b) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (!a || !b) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
if ((a.prototype !== b.prototype) || (Array.isArray(a) && Array.isArray(b))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 16:40:21 -07:00
|
|
|
export function isAnchor(el: (Node&ParentNode)|Element|null): el is HTMLAnchorElement {
|
2019-04-23 07:16:08 -07:00
|
|
|
return (<HTMLAnchorElement>el).href !== undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 15:28:25 +08:00
|
|
|
export function isPromise<T = any>(obj: any): obj is Promise<T> {
|
2019-04-23 07:16:08 -07:00
|
|
|
// allow any Promise/A+ compliant thenable.
|
|
|
|
|
// It's up to the caller to ensure that obj.then conforms to the spec
|
|
|
|
|
return !!obj && typeof obj.then === 'function';
|
|
|
|
|
}
|