// @dynamic export class ObjectOperations { static deepCopy = function (obj: object) { if (obj == null || typeof (obj) != 'object') return obj; return JSON.parse(JSON.stringify(obj)); /* if(obj == null || typeof(obj) != 'object') { return obj; } var copy = obj.constructor(); for (var key in obj) { if (typeof obj[key]!=="function") { copy[key] = this.deepCopy(obj[key]); } } return copy;*/ }; static deepFind = function (obj: object, path: string) { if (!path || !obj) return obj; var paths = path.split('.'); var current = obj; var i; for (i = 0; i < paths.length; ++i) { if (current[paths[i]] == undefined) return undefined; else current = current[paths[i]]; } return current; }; static deepSet = function (obj: object, path: any, value: any) { path = isNaN(path) ? path.split('.') : path; var i = 0; for (; i < path.length - 1; i++) { if (!obj[path[i]]) obj[path[i]] = {}; obj = obj[path[i]]; } if (isNaN(path)) obj[path[i]] = value; else obj[path] = value; }; static deepEqual = function (x: object, y: object) { // if both x and y are null or undefined and exactly the same if (x === y) return true; // if they are not strictly equal, they both need to be Objects if (!(x instanceof Object) || !(y instanceof Object)) return false; // they must have the exact same prototype chain, the closest we can do is // test there constructor. if (x.constructor !== y.constructor) return false; for (var p in x) { // other properties were tested using x.constructor === y.constructor if (!x.hasOwnProperty(p)) continue; // allows to compare x[ p ] and y[ p ] when set to undefined if (!y.hasOwnProperty(p)) return false; // if they have the same strict value or identity then they are equal if (x[p] === y[p]) continue; // Numbers, Strings, Functions, Booleans must be strictly equal if (typeof (x[p]) !== "object") return false; // Objects and Arrays must be tested recursively if (!this.deepEqual(x[p], y[p])) return false; } // allows x[ p ] to be set to undefined for (p in y) if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) return false; return true; } static isSimilar = function (a, b) { var minimator = function (x, y, z) { if (x < y && x < z) return x; if (y < x && y < z) return y; return z; } if (!a || !b) return false; a = a.toLowerCase(); b = b.toLowerCase(); var cost; var m = a.length; var n = b.length; if (m < n) { var c = a; a = b; b = c; var o = m; m = n; n = o; } var r = []; r[0] = []; for (var d = 0; d < n + 1; ++d) { r[0][d] = d; } for (var i = 1; i < m + 1; ++i) { r[i] = []; r[i][0] = i; for (var j = 1; j < n + 1; ++j) { cost = a.charAt(i - 1) === b.charAt(j - 1) ? 0 : 1; r[i][j] = minimator(r[i - 1][j] + 1, r[i][j - 1] + 1, r[i - 1][j - 1] + cost); } } var similarityLimit = (a.length + b.length) / 6; return r[m][n] <= similarityLimit; }; }