updated by GasGit automation
This commit is contained in:
parent
5b0156f827
commit
ae970d3b13
1 changed files with 38 additions and 30 deletions
|
@ -1,15 +1,24 @@
|
|||
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
|
||||
* @return {string} the stack trace
|
||||
*/
|
||||
ns.errorStack = function(e) {
|
||||
ns.errorStack = function (e) {
|
||||
try {
|
||||
// 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
|
||||
}
|
||||
catch(err) {
|
||||
catch (err) {
|
||||
return 'Error:' + e + '\n' + err.stack.split('\n').slice(1).join('\n');
|
||||
}
|
||||
};
|
||||
|
@ -20,19 +29,19 @@ var Utils = (function(ns) {
|
|||
* @param {function} [func] return true if two items are equal
|
||||
* @return {[*]} the unique items
|
||||
*/
|
||||
ns.unique = function (a,func) {
|
||||
return a.filter (function (d) {
|
||||
return a.reduce (function (p,c) {
|
||||
if ((func && func (d,c)) || (!func && d===c)) {
|
||||
ns.unique = function (a, func) {
|
||||
return a.filter(function (d) {
|
||||
return a.reduce(function (p, c) {
|
||||
if ((func && func(d, c)) || (!func && d === c)) {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
},0) === 1;
|
||||
}, 0) === 1;
|
||||
})
|
||||
};
|
||||
|
||||
ns.isSameAs = function (a,b) {
|
||||
return ns.keyDigest (a) === ns.keyDigest(b);
|
||||
ns.isSameAs = function (a, b) {
|
||||
return ns.keyDigest(a) === ns.keyDigest(b);
|
||||
};
|
||||
/**
|
||||
* @param {[*]} arguments unspecified number and type of args
|
||||
|
@ -40,9 +49,9 @@ var Utils = (function(ns) {
|
|||
*/
|
||||
ns.keyDigest = function () {
|
||||
// conver args to an array and digest them
|
||||
return Utilities.base64Encode (
|
||||
Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1,Array.prototype.slice.call(arguments).map(function (d) {
|
||||
return (Object(d) === d) ? JSON.stringify(d) : d.toString();
|
||||
return Utilities.base64Encode(
|
||||
Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, Array.prototype.slice.call(arguments).map(function (d) {
|
||||
return (Object(d) === d) ? JSON.stringify(d) : (ns.isUndefined(d) ? 'undefined' : d.toString());
|
||||
}).join("-")));
|
||||
};
|
||||
/**
|
||||
|
@ -51,15 +60,15 @@ var Utils = (function(ns) {
|
|||
* @return {object} a clone
|
||||
*/
|
||||
ns.clone = function (cloneThis) {
|
||||
return ns.vanExtend ({} , cloneThis);
|
||||
return ns.vanExtend({}, cloneThis);
|
||||
}
|
||||
/**
|
||||
* recursively extend an object with other objects
|
||||
* @param {[object]} obs the array of objects to be merged
|
||||
* @return {object} the extended object
|
||||
*/
|
||||
ns.vanMerge = function(obs) {
|
||||
return (obs || []).reduce(function(p, c) {
|
||||
ns.vanMerge = function (obs) {
|
||||
return (obs || []).reduce(function (p, c) {
|
||||
return ns.vanExtend(p, c);
|
||||
}, {});
|
||||
};
|
||||
|
@ -69,10 +78,10 @@ var Utils = (function(ns) {
|
|||
* @param {object} opt the object to extend by
|
||||
* @return {object} the extended object
|
||||
*/
|
||||
ns.vanExtend = function(result, opt) {
|
||||
ns.vanExtend = function (result, opt) {
|
||||
result = result || {};
|
||||
opt = opt || {};
|
||||
return Object.keys(opt).reduce(function(p, c) {
|
||||
return Object.keys(opt).reduce(function (p, c) {
|
||||
// if its an object
|
||||
if (ns.isVanObject(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
|
||||
* @return {*} the new value
|
||||
*/
|
||||
ns.fixDef = function(value, defValue) {
|
||||
ns.fixDef = function (value, defValue) {
|
||||
return typeof value === typeof undefined ? defValue : value;
|
||||
};
|
||||
/**
|
||||
|
@ -96,7 +105,7 @@ var Utils = (function(ns) {
|
|||
* @param {*} value the value to check
|
||||
* @return {bool} whether it was undefined
|
||||
*/
|
||||
ns.isUndefined = function(value) {
|
||||
ns.isUndefined = function (value) {
|
||||
return typeof value === typeof undefined;
|
||||
};
|
||||
/**
|
||||
|
@ -104,10 +113,9 @@ var Utils = (function(ns) {
|
|||
* @param {*} the thing to test
|
||||
* @return {bool} whether it was an object
|
||||
*/
|
||||
ns.isVanObject = function(value) {
|
||||
ns.isVanObject = function (value) {
|
||||
return typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
return ns;
|
||||
})(Utils || {});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue