- Mismatches deep within object/array structures are pinpointed with a JsonPath-like syntax.
88 lines
1.7 KiB
JavaScript
88 lines
1.7 KiB
JavaScript
getJasmineRequireObj().util = function() {
|
|
|
|
var util = {};
|
|
|
|
util.inherit = function(childClass, parentClass) {
|
|
var Subclass = function() {
|
|
};
|
|
Subclass.prototype = parentClass.prototype;
|
|
childClass.prototype = new Subclass();
|
|
};
|
|
|
|
util.htmlEscape = function(str) {
|
|
if (!str) {
|
|
return str;
|
|
}
|
|
return str.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
};
|
|
|
|
util.argsToArray = function(args) {
|
|
var arrayOfArgs = [];
|
|
for (var i = 0; i < args.length; i++) {
|
|
arrayOfArgs.push(args[i]);
|
|
}
|
|
return arrayOfArgs;
|
|
};
|
|
|
|
util.isUndefined = function(obj) {
|
|
return obj === void 0;
|
|
};
|
|
|
|
util.arrayContains = function(array, search) {
|
|
var i = array.length;
|
|
while (i--) {
|
|
if (array[i] === search) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
util.clone = function(obj) {
|
|
if (Object.prototype.toString.apply(obj) === '[object Array]') {
|
|
return obj.slice();
|
|
}
|
|
|
|
var cloned = {};
|
|
for (var prop in obj) {
|
|
if (obj.hasOwnProperty(prop)) {
|
|
cloned[prop] = obj[prop];
|
|
}
|
|
}
|
|
|
|
return cloned;
|
|
};
|
|
|
|
util.getPropertyDescriptor = function(obj, methodName) {
|
|
var descriptor,
|
|
proto = obj;
|
|
|
|
do {
|
|
descriptor = Object.getOwnPropertyDescriptor(proto, methodName);
|
|
proto = Object.getPrototypeOf(proto);
|
|
} while (!descriptor && proto);
|
|
|
|
return descriptor;
|
|
};
|
|
|
|
util.objectDifference = function(obj, toRemove) {
|
|
var diff = {};
|
|
|
|
for (var key in obj) {
|
|
if (util.has(obj, key) && !util.has(toRemove, key)) {
|
|
diff[key] = obj[key];
|
|
}
|
|
}
|
|
|
|
return diff;
|
|
};
|
|
|
|
util.has = function(obj, key) {
|
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
};
|
|
|
|
return util;
|
|
};
|