updated by GasGit automation

This commit is contained in:
Bruce McPherson 2016-06-17 09:55:27 +01:00
parent 5b0156f827
commit ae970d3b13

View file

@ -1,48 +1,57 @@
var Utils = (function(ns) { var Utils = (function (ns) {
/**
* create a column label for sheet address, starting at 1 = A, 27 = AA etc..
* @param {number} columnNumber the column number
* @return {string} the address label
*/
ns.columnLabelMaker = function (columnNumber, s) {
s = String.fromCharCode(((columnNumber - 1) % 26) + 'A'.charCodeAt(0)) + (s || '');
return columnNumber > 26 ? columnLabelMaker(Math.floor((columnNumber - 1) / 26), s) : s;
};
/** /**
* get the stack * get the stack
* @return {string} the stack trace * @return {string} the stack trace
*/ */
ns.errorStack = function(e) { ns.errorStack = function (e) {
try { try {
// throw a fake error // throw a fake error
throw new Error(); //x is undefined and will fail under use struct- ths will provoke an error so i can get the call stack throw new Error(); //x is undefined and will fail under use struct- ths will provoke an error so i can get the call stack
} }
catch(err) { catch (err) {
return 'Error:' + e + '\n' + err.stack.split('\n').slice(1).join('\n'); return 'Error:' + e + '\n' + err.stack.split('\n').slice(1).join('\n');
} }
}; };
/** /**
* get an array of unique values * get an array of unique values
* @param {[*]} a the array * @param {[*]} a the array
* @param {function} [func] return true if two items are equal * @param {function} [func] return true if two items are equal
* @return {[*]} the unique items * @return {[*]} the unique items
*/ */
ns.unique = function (a,func) { ns.unique = function (a, func) {
return a.filter (function (d) { return a.filter(function (d) {
return a.reduce (function (p,c) { return a.reduce(function (p, c) {
if ((func && func (d,c)) || (!func && d===c)) { if ((func && func(d, c)) || (!func && d === c)) {
p++; p++;
} }
return p; return p;
},0) === 1; }, 0) === 1;
}) })
}; };
ns.isSameAs = function (a,b) { ns.isSameAs = function (a, b) {
return ns.keyDigest (a) === ns.keyDigest(b); return ns.keyDigest(a) === ns.keyDigest(b);
}; };
/** /**
* @param {[*]} arguments unspecified number and type of args * @param {[*]} arguments unspecified number and type of args
* @return {string} a digest of the arguments to use as a key * @return {string} a digest of the arguments to use as a key
*/ */
ns.keyDigest = function () { ns.keyDigest = function () {
// conver args to an array and digest them // conver args to an array and digest them
return Utilities.base64Encode ( return Utilities.base64Encode(
Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1,Array.prototype.slice.call(arguments).map(function (d) { Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, Array.prototype.slice.call(arguments).map(function (d) {
return (Object(d) === d) ? JSON.stringify(d) : d.toString(); return (Object(d) === d) ? JSON.stringify(d) : (ns.isUndefined(d) ? 'undefined' : d.toString());
}).join("-"))); }).join("-")));
}; };
/** /**
@ -51,15 +60,15 @@ var Utils = (function(ns) {
* @return {object} a clone * @return {object} a clone
*/ */
ns.clone = function (cloneThis) { ns.clone = function (cloneThis) {
return ns.vanExtend ({} , cloneThis); return ns.vanExtend({}, cloneThis);
} }
/** /**
* recursively extend an object with other objects * recursively extend an object with other objects
* @param {[object]} obs the array of objects to be merged * @param {[object]} obs the array of objects to be merged
* @return {object} the extended object * @return {object} the extended object
*/ */
ns.vanMerge = function(obs) { ns.vanMerge = function (obs) {
return (obs || []).reduce(function(p, c) { return (obs || []).reduce(function (p, c) {
return ns.vanExtend(p, c); return ns.vanExtend(p, c);
}, {}); }, {});
}; };
@ -69,10 +78,10 @@ var Utils = (function(ns) {
* @param {object} opt the object to extend by * @param {object} opt the object to extend by
* @return {object} the extended object * @return {object} the extended object
*/ */
ns.vanExtend = function(result, opt) { ns.vanExtend = function (result, opt) {
result = result || {}; result = result || {};
opt = opt || {}; opt = opt || {};
return Object.keys(opt).reduce(function(p, c) { return Object.keys(opt).reduce(function (p, c) {
// if its an object // if its an object
if (ns.isVanObject(opt[c])) { if (ns.isVanObject(opt[c])) {
p[c] = ns.vanExtend(p[c], opt[c]); p[c] = ns.vanExtend(p[c], opt[c]);
@ -88,7 +97,7 @@ var Utils = (function(ns) {
* @param {*} defValue use this one if undefined * @param {*} defValue use this one if undefined
* @return {*} the new value * @return {*} the new value
*/ */
ns.fixDef = function(value, defValue) { ns.fixDef = function (value, defValue) {
return typeof value === typeof undefined ? defValue : value; return typeof value === typeof undefined ? defValue : value;
}; };
/** /**
@ -96,7 +105,7 @@ var Utils = (function(ns) {
* @param {*} value the value to check * @param {*} value the value to check
* @return {bool} whether it was undefined * @return {bool} whether it was undefined
*/ */
ns.isUndefined = function(value) { ns.isUndefined = function (value) {
return typeof value === typeof undefined; return typeof value === typeof undefined;
}; };
/** /**
@ -104,10 +113,9 @@ var Utils = (function(ns) {
* @param {*} the thing to test * @param {*} the thing to test
* @return {bool} whether it was an object * @return {bool} whether it was an object
*/ */
ns.isVanObject = function(value) { ns.isVanObject = function (value) {
return typeof value === "object" && !Array.isArray(value); return typeof value === "object" && !Array.isArray(value);
} }
return ns; return ns;
})(Utils || {}); })(Utils || {});