All files / src/utils objects.ts

89.74% Statements 35/39
83.33% Branches 20/24
100% Functions 5/5
89.74% Lines 35/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73          1x 186x 49x   137x 2x   135x 8x   127x 119x   8x             8x 4x     4x 6x         4x   4x 6x   4x 4x 4x 6x   4x 4x     4x 5x 1x       7x     1x 2807x     1x 1149x     1x 3539x     1x 246x  
/*---------------------------------------------------------------------------------------------
*  Copyright (c) Microsoft Corporation. All rights reserved.
*  Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
 
export function equals(one: any, other: any): boolean {
	if (one === other) {
		return true;
	}
	if (one === null || one === undefined || other === null || other === undefined) {
		return false;
	}
	if (typeof one !== typeof other) {
		return false;
	}
	if (typeof one !== 'object') {
		return false;
	}
	Iif ((Array.isArray(one)) !== (Array.isArray(other))) {
		return false;
	}
 
	var i: number,
		key: string;
 
	if (Array.isArray(one)) {
		Iif (one.length !== other.length) {
			return false;
		}
		for (i = 0; i < one.length; i++) {
			Iif (!equals(one[i], other[i])) {
				return false;
			}
		}
	} else {
		var oneKeys: string[] = [];
 
		for (key in one) {
			oneKeys.push(key);
		}
		oneKeys.sort();
		var otherKeys: string[] = [];
		for (key in other) {
			otherKeys.push(key);
		}
		otherKeys.sort();
		Iif (!equals(oneKeys, otherKeys)) {
			return false;
		}
		for (i = 0; i < oneKeys.length; i++) {
			if (!equals(one[oneKeys[i]], other[oneKeys[i]])) {
				return false;
			}
		}
	}
	return true;
}
 
export function isNumber(val: any): val is number {
	return typeof val === 'number';
}
 
export function isDefined(val: any): val is object {
	return typeof val !== 'undefined';
}
 
export function isBoolean(val: any): val is boolean {
	return typeof val === 'boolean';
}
 
export function isString(val: any): val is string {
	return typeof val === 'string';
}