UNPKG

nowjs-core

Version:

NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence

84 lines (83 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const numberComparator = (a, b) => { if (a > b) { return 1; } else if (a === b) { return 0; } else { return -1; } }; exports.numberComparator = numberComparator; const stringComparator = (a, b) => { return a.localeCompare(b); }; exports.stringComparator = stringComparator; const booleanComparator = (a, b) => { if (a === b) { return 0; } else { return -1; } }; exports.booleanComparator = booleanComparator; const objectComparator = (a, b) => { if (a > b) { return 1; } else if (a === b) { return 0; } else { return -1; } }; exports.objectComparator = objectComparator; const deepObjectComparator = (a, b) => { if (a > b) { return 1; } else if (a === b) { return 0; } else { return -1; } }; exports.deepObjectComparator = deepObjectComparator; function isEquals(x, y) { if (x === null || x === undefined || y === null || y === undefined) { return x === y; } if (x.constructor !== y.constructor) { return false; } if (x instanceof Function) { return x === y; } if (x instanceof RegExp) { return x === y; } if (x === y || x.valueOf() === y.valueOf()) { return true; } if (Array.isArray(x) && x.length !== y.length) { return false; } if (x instanceof Date) { return false; } if (!(x instanceof Object)) { return false; } if (!(y instanceof Object)) { return false; } const p = Object.keys(x); return Object.keys(y).every(i => p.indexOf(i) !== -1) && p.every(i => isEquals(x[i], y[i])); } exports.isEquals = isEquals;