Comparing version 1.3.1 to 2.0.0
# hashIt CHANGELOG | ||
#### 2.0.0 | ||
* Use JSON.stringify with replacer as default, without try/catch | ||
* Move use of try/catch with fallback to prune to new `hashIt.withRecursion` method (only necessary for deeply-recursive objects like `window`) | ||
* Reorder switch statement for commonality of use cases | ||
* Leverage typeof in switch statements when possible for performance | ||
#### 1.3.1 | ||
* Add optimize-js plugin for performance in script version | ||
#### 1.3.0 | ||
@@ -4,0 +13,0 @@ * Add hashIt.isUndefined, hashIt.isNull, and hashIt.isEmpty methods |
@@ -79,3 +79,5 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var hashIt = function hashIt(object) { | ||
return (0, _utils.getIntegerHashValue)((0, _utils.stringify)(object)); | ||
var stringifiedValue = (0, _utils.getStringifiedValue)(object); | ||
return (0, _utils.getIntegerHashValue)(stringifiedValue); | ||
}; | ||
@@ -149,2 +151,14 @@ | ||
/** | ||
* return the unique integer hash value for the object | ||
* | ||
* @param {*} object | ||
* @returns {number} | ||
*/ | ||
hashIt.withRecursion = function (object) { | ||
var stringifiedValue = (0, _utils.getStringifiedValueWithRecursion)(object); | ||
return (0, _utils.getIntegerHashValue)(stringifiedValue); | ||
}; | ||
exports.default = hashIt; | ||
@@ -162,6 +176,8 @@ module.exports = exports['default']; | ||
}); | ||
exports.stringify = exports.replacer = exports.getIntegerHashValue = undefined; | ||
exports.replacer = exports.getStringifiedValueWithRecursion = exports.getStringifiedValue = exports.getIntegerHashValue = undefined; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _prune = __webpack_require__(3); | ||
@@ -175,8 +191,12 @@ | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var HTML_ELEMENT_REGEXP = /\[object (HTML(.*)Element)\]/; | ||
var MATH_PROPERTIES = ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2']; | ||
var MATH_OBJECT = ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2'].reduce(function (mathObject, property) { | ||
return _extends({}, mathObject, _defineProperty({}, property, Math[property])); | ||
}, {}); | ||
/** | ||
* get the string value of the buffer passed | ||
* | ||
* | ||
* @param {ArrayBuffer} buffer | ||
@@ -194,5 +214,22 @@ * @returns {string} | ||
/** | ||
* get the key,value pairs for maps and sets | ||
* | ||
* @param {Map|Set} iterable | ||
* @param {string} type | ||
* @returns {Array<Array>} | ||
*/ | ||
var getIterablePairs = function getIterablePairs(iterable, type) { | ||
var pairs = [getObjectType(type)]; | ||
iterable.forEach(function (item, key) { | ||
pairs.push([key, item]); | ||
}); | ||
return pairs; | ||
}; | ||
/** | ||
* strip away [object and ] from return of toString() | ||
* to get the object class | ||
* | ||
* | ||
* @param {string} type | ||
@@ -207,3 +244,3 @@ * @returns {string} | ||
* prepend type to string value | ||
* | ||
* | ||
* @param {string} string | ||
@@ -230,103 +267,65 @@ * @param {string} type | ||
var _ret = function () { | ||
switch (type) { | ||
case _toString.ARGUMENTS: | ||
case _toString.ARRAY: | ||
case _toString.BOOLEAN: | ||
case _toString.NUMBER: | ||
case _toString.STRING: | ||
return { | ||
v: object | ||
}; | ||
switch (typeof object === 'undefined' ? 'undefined' : _typeof(object)) { | ||
case _toString.STRING_TYPEOF: | ||
case _toString.NUMBER_TYPEOF: | ||
return object; | ||
case _toString.OBJECT: | ||
return { | ||
v: !!object ? object : prependTypeToString(object, type) | ||
}; | ||
case _toString.BOOLEAN_TYPEOF: | ||
case _toString.UNDEFINED_TYPEOF: | ||
return prependTypeToString(object, type); | ||
case _toString.ERROR: | ||
case _toString.NULL: | ||
case _toString.REGEXP: | ||
case _toString.UNDEFINED: | ||
return { | ||
v: prependTypeToString(object, type) | ||
}; | ||
case _toString.FUNCTION_TYPEOF: | ||
return (0, _toString.toFunctionString)(object, type === _toString.GENERATOR); | ||
case _toString.DATE: | ||
return { | ||
v: prependTypeToString(object.valueOf(), type) | ||
}; | ||
default: | ||
switch (type) { | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
case _toString.ARGUMENTS: | ||
return object; | ||
case _toString.FUNCTION: | ||
case _toString.GENERATOR: | ||
return { | ||
v: (0, _toString.toFunctionString)(object, type === _toString.GENERATOR) | ||
}; | ||
case _toString.ERROR: | ||
case _toString.NULL: | ||
case _toString.REGEXP: | ||
return prependTypeToString(object, type); | ||
case _toString.SYMBOL: | ||
return { | ||
v: object.toString() | ||
}; | ||
case _toString.DATE: | ||
return prependTypeToString(object.valueOf(), type); | ||
case _toString.PROMISE: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return { | ||
v: prependTypeToString('NOT_ENUMERABLE', type) | ||
}; | ||
case _toString.SYMBOL: | ||
return object.toString(); | ||
case _toString.MAP: | ||
case _toString.SET: | ||
var pairs = [getObjectType(type)]; | ||
case _toString.PROMISE: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return prependTypeToString('NOT_ENUMERABLE', type); | ||
object.forEach(function (item, key) { | ||
pairs.push([key, item]); | ||
}); | ||
case _toString.MAP: | ||
case _toString.SET: | ||
return getIterablePairs(object, type); | ||
return { | ||
v: pairs | ||
}; | ||
case _toString.ARRAY_BUFFER: | ||
return prependTypeToString(arrayBufferToString(object), type); | ||
case _toString.ARRAY_BUFFER: | ||
return { | ||
v: prependTypeToString(arrayBufferToString(object), type) | ||
}; | ||
case _toString.DATA_VIEW: | ||
return prependTypeToString(arrayBufferToString(object.buffer), type); | ||
case _toString.DATA_VIEW: | ||
return { | ||
v: prependTypeToString(arrayBufferToString(object.buffer), type) | ||
}; | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
return prependTypeToString(object.join(','), type); | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
return { | ||
v: prependTypeToString(object.join(','), type) | ||
}; | ||
case _toString.MATH: | ||
return MATH_OBJECT; | ||
case _toString.MATH: | ||
var mathObject = {}; | ||
MATH_PROPERTIES.forEach(function (prop) { | ||
mathObject[prop] = object[prop]; | ||
}); | ||
return { | ||
v: mathObject | ||
}; | ||
default: | ||
return { | ||
v: HTML_ELEMENT_REGEXP.test(type) ? 'HTMLElement ' + object.textContent : object | ||
}; | ||
} | ||
}(); | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
default: | ||
return HTML_ELEMENT_REGEXP.test(type) ? 'HTMLElement ' + object.textContent : object; | ||
} | ||
} | ||
}; | ||
@@ -340,3 +339,3 @@ | ||
return function (key, value) { | ||
if (key === '') { | ||
if (!key) { | ||
stack = [value]; | ||
@@ -350,58 +349,67 @@ recursiveCounter = 0; | ||
switch (type) { | ||
case _toString.ARGUMENTS: | ||
case _toString.BOOLEAN: | ||
case _toString.NUMBER: | ||
case _toString.STRING: | ||
switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) { | ||
case _toString.STRING_TYPEOF: | ||
case _toString.NUMBER_TYPEOF: | ||
case _toString.BOOLEAN_TYPEOF: | ||
return value; | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
if (!value) { | ||
return prependTypeToString(value, type); | ||
} | ||
case _toString.UNDEFINED_TYPEOF: | ||
case _toString.FUNCTION_TYPEOF: | ||
return getValueForStringification(value); | ||
if (++recursiveCounter > 255) { | ||
return 'Undefined undefined'; | ||
} | ||
default: | ||
switch (type) { | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
if (!value) { | ||
return prependTypeToString(value, type); | ||
} | ||
index = stack.indexOf(value); | ||
if (++recursiveCounter > 255) { | ||
return 'Undefined undefined'; | ||
} | ||
if (!~index) { | ||
stack.push(value); | ||
index = stack.indexOf(value); | ||
return value; | ||
} | ||
if (!~index) { | ||
stack.push(value); | ||
return '*Recursive-' + index; | ||
return value; | ||
} | ||
case _toString.ARRAY_BUFFER: | ||
case _toString.DATA_VIEW: | ||
case _toString.DATE: | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.FUNCTION: | ||
case _toString.GENERATOR: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.ERROR: | ||
case _toString.MAP: | ||
case _toString.MATH: | ||
case _toString.NULL: | ||
case _toString.PROMISE: | ||
case _toString.REGEXP: | ||
case _toString.SET: | ||
case _toString.SYMBOL: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
case _toString.UNDEFINED: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return getValueForStringification(value); | ||
return '*Recursive-' + index; | ||
default: | ||
return value; | ||
case _toString.ARGUMENTS: | ||
return value; | ||
case _toString.DATE: | ||
case _toString.FUNCTION: | ||
case _toString.MAP: | ||
case _toString.SET: | ||
case _toString.PROMISE: | ||
case _toString.REGEXP: | ||
case _toString.NULL: | ||
case _toString.ARRAY_BUFFER: | ||
case _toString.DATA_VIEW: | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.GENERATOR: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.ERROR: | ||
case _toString.MATH: | ||
case _toString.SYMBOL: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
case _toString.UNDEFINED: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return getValueForStringification(value); | ||
default: | ||
return value; | ||
} | ||
} | ||
@@ -423,7 +431,9 @@ }; | ||
var length = string.length; | ||
var hashValue = 5381, | ||
index = string.length; | ||
index = -1; | ||
while (index) { | ||
hashValue = hashValue * 33 ^ string.charCodeAt(--index); | ||
while (++index < length) { | ||
hashValue = (hashValue << 5) + hashValue + string.charCodeAt(index); | ||
} | ||
@@ -434,6 +444,14 @@ | ||
var stringify = function stringify(value) { | ||
return JSON.stringify(value, REPLACER); | ||
}; | ||
var prune = function prune(value) { | ||
return _prune2.default.prune(value); | ||
}; | ||
/** | ||
* move try/catch to standalone function as any function that contains a try/catch | ||
* is not optimized (this allows optimization for as much as possible) | ||
* | ||
* fac | ||
* @param {*} value | ||
@@ -444,5 +462,5 @@ * @returns {string} | ||
try { | ||
return JSON.stringify(value, REPLACER); | ||
return stringify(value, REPLACER); | ||
} catch (exception) { | ||
return _prune2.default.prune(value); | ||
return prune(value); | ||
} | ||
@@ -452,3 +470,4 @@ }; | ||
/** | ||
* stringify the object passed leveraging the REPLACER | ||
* stringify the object passed leveraging JSON.stringify | ||
* with REPLACER, falling back to prune | ||
* | ||
@@ -458,3 +477,26 @@ * @param {*} object | ||
*/ | ||
var stringify = function stringify(object) { | ||
var getStringifiedValue = function getStringifiedValue(object) { | ||
var valueForStringification = getValueForStringification(object); | ||
if (typeof valueForStringification === 'string') { | ||
return valueForStringification; | ||
} | ||
return stringify(valueForStringification); | ||
}; | ||
/** | ||
* stringify the object passed leveraging JSON.stringify | ||
* with REPLACER | ||
* | ||
* @param {*} object | ||
* @returns {string} | ||
*/ | ||
var getStringifiedValueWithRecursion = function getStringifiedValueWithRecursion(object) { | ||
var valueForStringification = getValueForStringification(object); | ||
if (typeof valueForStringification === 'string') { | ||
return valueForStringification; | ||
} | ||
return tryCatch(getValueForStringification(object)); | ||
@@ -464,4 +506,5 @@ }; | ||
exports.getIntegerHashValue = getIntegerHashValue; | ||
exports.getStringifiedValue = getStringifiedValue; | ||
exports.getStringifiedValueWithRecursion = getStringifiedValueWithRecursion; | ||
exports.replacer = REPLACER; | ||
exports.stringify = stringify; | ||
@@ -664,2 +707,10 @@ /***/ }, | ||
var BOOLEAN_TYPEOF = exports.BOOLEAN_TYPEOF = 'boolean'; | ||
var FUNCTION_TYPEOF = exports.FUNCTION_TYPEOF = 'function'; | ||
var NUMBER_TYPEOF = exports.NUMBER_TYPEOF = 'number'; | ||
var STRING_TYPEOF = exports.STRING_TYPEOF = 'string'; | ||
var UNDEFINED_TYPEOF = exports.UNDEFINED_TYPEOF = 'undefined'; | ||
var objectToString = Object.prototype.toString; | ||
/** | ||
@@ -685,3 +736,3 @@ * get the generic string value of the function passed | ||
var toString = exports.toString = function toString(object) { | ||
return Object.prototype.toString.call(object); | ||
return objectToString.call(object); | ||
}; | ||
@@ -688,0 +739,0 @@ |
@@ -1,1 +0,1 @@ | ||
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("hashIt",[],t):"object"==typeof exports?exports.hashIt=t():e.hashIt=t()})(this,(function(){return (function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)})([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2),o=function(e){return(0,n.getIntegerHashValue)((0,n.stringify)(e))},c=o(void 0),u=o(null),a=o([]),i=o(new Map),s=o(0),f=o({}),A=o(new Set),R=o("");o.isEqual=function(){var e=arguments.length;if(1===e)throw new Error("isEqual requires at least two objects to be passed for comparison.");for(var t=0;++t<e;)if(o(arguments.length<=t-1+0?void 0:arguments[t-1+0])!==o(arguments.length<=t+0?void 0:arguments[t+0]))return!1;return!0},o.isEmpty=function(e){var t=o(e);return t===c||t===u||t===a||t===i||t===s||t===f||t===A||t===R},o.isNull=function(e){return o(e)===u},o.isUndefined=function(e){return o(e)===c},t.default=o,e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.stringify=t.replacer=t.getIntegerHashValue=void 0;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=r(3),u=n(c),a=r(4),i=/\[object (HTML(.*)Element)\]/,s=["E","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2"],f=function(e){return"undefined"==typeof Uint16Array?"":String.fromCharCode.apply(null,new Uint16Array(e))},A=function(e){return e.replace(/^\[object (.+)\]$/,"$1")},R=function(e,t){return A(t)+" "+e},l=function(e){var t=(0,a.toString)(e),r=(function(){switch(t){case a.ARGUMENTS:case a.ARRAY:case a.BOOLEAN:case a.NUMBER:case a.STRING:return{v:e};case a.OBJECT:return{v:e?e:R(e,t)};case a.ERROR:case a.NULL:case a.REGEXP:case a.UNDEFINED:return{v:R(e,t)};case a.DATE:return{v:R(e.valueOf(),t)};case a.FUNCTION:case a.GENERATOR:return{v:(0,a.toFunctionString)(e,t===a.GENERATOR)};case a.SYMBOL:return{v:e.toString()};case a.PROMISE:case a.WEAKMAP:case a.WEAKSET:return{v:R("NOT_ENUMERABLE",t)};case a.MAP:case a.SET:var r=[A(t)];return e.forEach((function(e,t){r.push([t,e])})),{v:r};case a.ARRAY_BUFFER:return{v:R(f(e),t)};case a.DATA_VIEW:return{v:R(f(e.buffer),t)};case a.FLOAT_32_ARRAY:case a.FLOAT_64_ARRAY:case a.INT_8_ARRAY:case a.INT_16_ARRAY:case a.INT_32_ARRAY:case a.UINT_8_ARRAY:case a.UINT_8_CLAMPED_ARRAY:case a.UINT_16_ARRAY:case a.UINT_32_ARRAY:return{v:R(e.join(","),t)};case a.MATH:var n={};return s.forEach((function(t){n[t]=e[t]})),{v:n};default:return{v:i.test(t)?"HTMLElement "+e.textContent:e}}})();if("object"===("undefined"==typeof r?"undefined":o(r)))return r.v},E=(function(e,t,r,n){return function(t,o){if(""===t)return e=[o],r=0,o;var c=(0,a.toString)(o);switch(c){case a.ARGUMENTS:case a.BOOLEAN:case a.NUMBER:case a.STRING:return o;case a.ARRAY:case a.OBJECT:return o?++r>255?"Undefined undefined":(n=e.indexOf(o),~n?"*Recursive-"+n:(e.push(o),o)):R(o,c);case a.ARRAY_BUFFER:case a.DATA_VIEW:case a.DATE:case a.FLOAT_32_ARRAY:case a.FLOAT_64_ARRAY:case a.FUNCTION:case a.GENERATOR:case a.INT_8_ARRAY:case a.INT_16_ARRAY:case a.INT_32_ARRAY:case a.ERROR:case a.MAP:case a.MATH:case a.NULL:case a.PROMISE:case a.REGEXP:case a.SET:case a.SYMBOL:case a.UINT_8_ARRAY:case a.UINT_8_CLAMPED_ARRAY:case a.UINT_16_ARRAY:case a.UINT_32_ARRAY:case a.UNDEFINED:case a.WEAKMAP:case a.WEAKSET:return l(o);default:return o}}})(),_=function(e){if(!e)return 0;for(var t=5381,r=e.length;r;)t=33*t^e.charCodeAt(--r);return t>>>0},b=function(e){try{return JSON.stringify(e,E)}catch(t){return u.default.prune(e)}},d=function(e){return b(l(e))};t.getIntegerHashValue=_,t.replacer=E,t.stringify=d},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=r(4),c=6,u=50,a="*Recursive",i=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,s={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},f=void 0,A=function(e,t){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t(r)},R=function(e){i.lastIndex=0;var t=void 0;return i.test(e)?'"'+e.replace(i,(function(e){return t=s[e],(0,o.toString)(t)===o.STRING?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}))+'"':'"'+e+'"'},l=function(e){f=[];var t=function r(e,t,c){var i=t[e],s=[],l=void 0;switch("undefined"==typeof i?"undefined":n(i)){case"string":return R(i);case"boolean":case"null":case"number":case"undefined":return""+i;case"function":return(0,o.toFunctionString)(i);case"object":if(!i)return""+i;var E=f.indexOf(i);if(c<=0||~E)return a+"-"+E;switch((0,o.toString)(i)){case o.ARRAY:f.push(i);for(var _=Math.min(i.length,u),b=-1;++b<_;)s[b]=r(b,i,c-1);return l="["+s.join(",")+"]";case o.DATE:return""+i.valueOf();default:return f.push(i),A(i,(function(e){try{l=r(e,i,c-1),l&&s.push(R(e)+":"+l)}catch(t){}})),"{"+s.join(",")+"}"}}};return t("",{"":e},c)};t.default={prune:l},e.exports=t.default},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ARGUMENTS="[object Arguments]",t.ARRAY="[object Array]",t.ARRAY_BUFFER="[object ArrayBuffer]",t.BOOLEAN="[object Boolean]",t.DATA_VIEW="[object DataView]",t.DATE="[object Date]",t.ERROR="[object Error]",t.FLOAT_32_ARRAY="[object Float32Array]",t.FLOAT_64_ARRAY="[object Float64Array]",t.FUNCTION="[object Function]",t.GENERATOR="[object GeneratorFunction]",t.INT_8_ARRAY="[object Int8Array]",t.INT_16_ARRAY="[object Int16Array]",t.INT_32_ARRAY="[object Int32Array]",t.MAP="[object Map]",t.MATH="[object Math]",t.NULL="[object Null]",t.NUMBER="[object Number]",t.OBJECT="[object Object]",t.PROMISE="[object Promise]",t.REGEXP="[object RegExp]",t.SET="[object Set]",t.STRING="[object String]",t.SYMBOL="[object Symbol]",t.UINT_8_ARRAY="[object Uint8Array]",t.UINT_8_CLAMPED_ARRAY="[object Uint8ClampedArray]",t.UINT_16_ARRAY="[object Uint16Array]",t.UINT_32_ARRAY="[object Uint32Array]",t.UNDEFINED="[object Undefined]",t.WEAKMAP="[object WeakMap]",t.WEAKSET="[object WeakSet]",t.toFunctionString=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"function"+(t?"*":"")+" "+(e.name||"anonymous")+"("+new Array(e.length+1).join(",arg").slice(1)+"){}"},t.toString=function(e){return Object.prototype.toString.call(e)}}])})); | ||
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("hashIt",[],t):"object"==typeof exports?exports.hashIt=t():e.hashIt=t()})(this,(function(){return (function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)})([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2),o=function(e){var t=(0,n.getStringifiedValue)(e);return(0,n.getIntegerHashValue)(t)},u=o(void 0),c=o(null),a=o([]),i=o(new Map),s=o(0),f=o({}),A=o(new Set),R=o("");o.isEqual=function(){var e=arguments.length;if(1===e)throw new Error("isEqual requires at least two objects to be passed for comparison.");for(var t=0;++t<e;)if(o(arguments.length<=t-1+0?void 0:arguments[t-1+0])!==o(arguments.length<=t+0?void 0:arguments[t+0]))return!1;return!0},o.isEmpty=function(e){var t=o(e);return t===u||t===c||t===a||t===i||t===s||t===f||t===A||t===R},o.isNull=function(e){return o(e)===c},o.isUndefined=function(e){return o(e)===u},o.withRecursion=function(e){var t=(0,n.getStringifiedValueWithRecursion)(e);return(0,n.getIntegerHashValue)(t)},t.default=o,e.exports=t.default},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(t,"__esModule",{value:!0}),t.replacer=t.getStringifiedValueWithRecursion=t.getStringifiedValue=t.getIntegerHashValue=void 0;var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=r(3),i=n(a),s=r(4),f=/\[object (HTML(.*)Element)\]/,A=["E","LN2","LN10","LOG2E","LOG10E","PI","SQRT1_2","SQRT2"].reduce((function(e,t){return c({},e,o({},t,Math[t]))}),{}),R=function(e){return"undefined"==typeof Uint16Array?"":String.fromCharCode.apply(null,new Uint16Array(e))},l=function(e,t){var r=[E(t)];return e.forEach((function(e,t){r.push([t,e])})),r},E=function(e){return e.replace(/^\[object (.+)\]$/,"$1")},_=function(e,t){return E(t)+" "+e},d=function(e){var t=(0,s.toString)(e);switch("undefined"==typeof e?"undefined":u(e)){case s.STRING_TYPEOF:case s.NUMBER_TYPEOF:return e;case s.BOOLEAN_TYPEOF:case s.UNDEFINED_TYPEOF:return _(e,t);case s.FUNCTION_TYPEOF:return(0,s.toFunctionString)(e,t===s.GENERATOR);default:switch(t){case s.ARRAY:case s.OBJECT:case s.ARGUMENTS:return e;case s.ERROR:case s.NULL:case s.REGEXP:return _(e,t);case s.DATE:return _(e.valueOf(),t);case s.SYMBOL:return e.toString();case s.PROMISE:case s.WEAKMAP:case s.WEAKSET:return _("NOT_ENUMERABLE",t);case s.MAP:case s.SET:return l(e,t);case s.ARRAY_BUFFER:return _(R(e),t);case s.DATA_VIEW:return _(R(e.buffer),t);case s.FLOAT_32_ARRAY:case s.FLOAT_64_ARRAY:case s.INT_8_ARRAY:case s.INT_16_ARRAY:case s.INT_32_ARRAY:case s.UINT_8_ARRAY:case s.UINT_8_CLAMPED_ARRAY:case s.UINT_16_ARRAY:case s.UINT_32_ARRAY:return _(e.join(","),t);case s.MATH:return A;default:return f.test(t)?"HTMLElement "+e.textContent:e}}},T=(function(e,t,r,n){return function(t,o){if(!t)return e=[o],r=0,o;var c=(0,s.toString)(o);switch("undefined"==typeof o?"undefined":u(o)){case s.STRING_TYPEOF:case s.NUMBER_TYPEOF:case s.BOOLEAN_TYPEOF:return o;case s.UNDEFINED_TYPEOF:case s.FUNCTION_TYPEOF:return d(o);default:switch(c){case s.ARRAY:case s.OBJECT:return o?++r>255?"Undefined undefined":(n=e.indexOf(o),~n?"*Recursive-"+n:(e.push(o),o)):_(o,c);case s.ARGUMENTS:return o;case s.DATE:case s.FUNCTION:case s.MAP:case s.SET:case s.PROMISE:case s.REGEXP:case s.NULL:case s.ARRAY_BUFFER:case s.DATA_VIEW:case s.FLOAT_32_ARRAY:case s.FLOAT_64_ARRAY:case s.GENERATOR:case s.INT_8_ARRAY:case s.INT_16_ARRAY:case s.INT_32_ARRAY:case s.ERROR:case s.MATH:case s.SYMBOL:case s.UINT_8_ARRAY:case s.UINT_8_CLAMPED_ARRAY:case s.UINT_16_ARRAY:case s.UINT_32_ARRAY:case s.UNDEFINED:case s.WEAKMAP:case s.WEAKSET:return d(o);default:return o}}}})(),b=function(e){if(!e)return 0;for(var t=e.length,r=5381,n=-1;++n<t;)r=(r<<5)+r+e.charCodeAt(n);return r>>>0},p=function(e){return JSON.stringify(e,T)},N=function(e){return i.default.prune(e)},O=function(e){try{return p(e,T)}catch(t){return N(e)}},y=function(e){var t=d(e);return"string"==typeof t?t:p(t)},S=function(e){var t=d(e);return"string"==typeof t?t:O(d(e))};t.getIntegerHashValue=b,t.getStringifiedValue=y,t.getStringifiedValueWithRecursion=S,t.replacer=T},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=r(4),u=6,c=50,a="*Recursive",i=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,s={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},f=void 0,A=function(e,t){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t(r)},R=function(e){i.lastIndex=0;var t=void 0;return i.test(e)?'"'+e.replace(i,(function(e){return t=s[e],(0,o.toString)(t)===o.STRING?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}))+'"':'"'+e+'"'},l=function(e){f=[];var t=function r(e,t,u){var i=t[e],s=[],l=void 0;switch("undefined"==typeof i?"undefined":n(i)){case"string":return R(i);case"boolean":case"null":case"number":case"undefined":return""+i;case"function":return(0,o.toFunctionString)(i);case"object":if(!i)return""+i;var E=f.indexOf(i);if(u<=0||~E)return a+"-"+E;switch((0,o.toString)(i)){case o.ARRAY:f.push(i);for(var _=Math.min(i.length,c),d=-1;++d<_;)s[d]=r(d,i,u-1);return l="["+s.join(",")+"]";case o.DATE:return""+i.valueOf();default:return f.push(i),A(i,(function(e){try{l=r(e,i,u-1),l&&s.push(R(e)+":"+l)}catch(t){}})),"{"+s.join(",")+"}"}}};return t("",{"":e},u)};t.default={prune:l},e.exports=t.default},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=(t.ARGUMENTS="[object Arguments]",t.ARRAY="[object Array]",t.ARRAY_BUFFER="[object ArrayBuffer]",t.BOOLEAN="[object Boolean]",t.DATA_VIEW="[object DataView]",t.DATE="[object Date]",t.ERROR="[object Error]",t.FLOAT_32_ARRAY="[object Float32Array]",t.FLOAT_64_ARRAY="[object Float64Array]",t.FUNCTION="[object Function]",t.GENERATOR="[object GeneratorFunction]",t.INT_8_ARRAY="[object Int8Array]",t.INT_16_ARRAY="[object Int16Array]",t.INT_32_ARRAY="[object Int32Array]",t.MAP="[object Map]",t.MATH="[object Math]",t.NULL="[object Null]",t.NUMBER="[object Number]",t.OBJECT="[object Object]",t.PROMISE="[object Promise]",t.REGEXP="[object RegExp]",t.SET="[object Set]",t.STRING="[object String]",t.SYMBOL="[object Symbol]",t.UINT_8_ARRAY="[object Uint8Array]",t.UINT_8_CLAMPED_ARRAY="[object Uint8ClampedArray]",t.UINT_16_ARRAY="[object Uint16Array]",t.UINT_32_ARRAY="[object Uint32Array]",t.UNDEFINED="[object Undefined]",t.WEAKMAP="[object WeakMap]",t.WEAKSET="[object WeakSet]",t.BOOLEAN_TYPEOF="boolean",t.FUNCTION_TYPEOF="function",t.NUMBER_TYPEOF="number",t.STRING_TYPEOF="string",t.UNDEFINED_TYPEOF="undefined",Object.prototype.toString);t.toFunctionString=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"function"+(t?"*":"")+" "+(e.name||"anonymous")+"("+new Array(e.length+1).join(",arg").slice(1)+"){}"},t.toString=function(e){return r.call(e)}}])})); |
@@ -16,3 +16,5 @@ 'use strict'; | ||
var hashIt = function hashIt(object) { | ||
return (0, _utils.getIntegerHashValue)((0, _utils.stringify)(object)); | ||
var stringifiedValue = (0, _utils.getStringifiedValue)(object); | ||
return (0, _utils.getIntegerHashValue)(stringifiedValue); | ||
}; | ||
@@ -86,3 +88,15 @@ | ||
/** | ||
* return the unique integer hash value for the object | ||
* | ||
* @param {*} object | ||
* @returns {number} | ||
*/ | ||
hashIt.withRecursion = function (object) { | ||
var stringifiedValue = (0, _utils.getStringifiedValueWithRecursion)(object); | ||
return (0, _utils.getIntegerHashValue)(stringifiedValue); | ||
}; | ||
exports.default = hashIt; | ||
module.exports = exports['default']; |
@@ -38,2 +38,10 @@ 'use strict'; | ||
var BOOLEAN_TYPEOF = exports.BOOLEAN_TYPEOF = 'boolean'; | ||
var FUNCTION_TYPEOF = exports.FUNCTION_TYPEOF = 'function'; | ||
var NUMBER_TYPEOF = exports.NUMBER_TYPEOF = 'number'; | ||
var STRING_TYPEOF = exports.STRING_TYPEOF = 'string'; | ||
var UNDEFINED_TYPEOF = exports.UNDEFINED_TYPEOF = 'undefined'; | ||
var objectToString = Object.prototype.toString; | ||
/** | ||
@@ -59,3 +67,3 @@ * get the generic string value of the function passed | ||
var toString = exports.toString = function toString(object) { | ||
return Object.prototype.toString.call(object); | ||
return objectToString.call(object); | ||
}; |
331
lib/utils.js
@@ -6,6 +6,8 @@ 'use strict'; | ||
}); | ||
exports.stringify = exports.replacer = exports.getIntegerHashValue = undefined; | ||
exports.replacer = exports.getStringifiedValueWithRecursion = exports.getStringifiedValue = exports.getIntegerHashValue = undefined; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _prune = require('./prune'); | ||
@@ -19,8 +21,12 @@ | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var HTML_ELEMENT_REGEXP = /\[object (HTML(.*)Element)\]/; | ||
var MATH_PROPERTIES = ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2']; | ||
var MATH_OBJECT = ['E', 'LN2', 'LN10', 'LOG2E', 'LOG10E', 'PI', 'SQRT1_2', 'SQRT2'].reduce(function (mathObject, property) { | ||
return _extends({}, mathObject, _defineProperty({}, property, Math[property])); | ||
}, {}); | ||
/** | ||
* get the string value of the buffer passed | ||
* | ||
* | ||
* @param {ArrayBuffer} buffer | ||
@@ -38,5 +44,22 @@ * @returns {string} | ||
/** | ||
* get the key,value pairs for maps and sets | ||
* | ||
* @param {Map|Set} iterable | ||
* @param {string} type | ||
* @returns {Array<Array>} | ||
*/ | ||
var getIterablePairs = function getIterablePairs(iterable, type) { | ||
var pairs = [getObjectType(type)]; | ||
iterable.forEach(function (item, key) { | ||
pairs.push([key, item]); | ||
}); | ||
return pairs; | ||
}; | ||
/** | ||
* strip away [object and ] from return of toString() | ||
* to get the object class | ||
* | ||
* | ||
* @param {string} type | ||
@@ -51,3 +74,3 @@ * @returns {string} | ||
* prepend type to string value | ||
* | ||
* | ||
* @param {string} string | ||
@@ -74,103 +97,65 @@ * @param {string} type | ||
var _ret = function () { | ||
switch (type) { | ||
case _toString.ARGUMENTS: | ||
case _toString.ARRAY: | ||
case _toString.BOOLEAN: | ||
case _toString.NUMBER: | ||
case _toString.STRING: | ||
return { | ||
v: object | ||
}; | ||
switch (typeof object === 'undefined' ? 'undefined' : _typeof(object)) { | ||
case _toString.STRING_TYPEOF: | ||
case _toString.NUMBER_TYPEOF: | ||
return object; | ||
case _toString.OBJECT: | ||
return { | ||
v: !!object ? object : prependTypeToString(object, type) | ||
}; | ||
case _toString.BOOLEAN_TYPEOF: | ||
case _toString.UNDEFINED_TYPEOF: | ||
return prependTypeToString(object, type); | ||
case _toString.ERROR: | ||
case _toString.NULL: | ||
case _toString.REGEXP: | ||
case _toString.UNDEFINED: | ||
return { | ||
v: prependTypeToString(object, type) | ||
}; | ||
case _toString.FUNCTION_TYPEOF: | ||
return (0, _toString.toFunctionString)(object, type === _toString.GENERATOR); | ||
case _toString.DATE: | ||
return { | ||
v: prependTypeToString(object.valueOf(), type) | ||
}; | ||
default: | ||
switch (type) { | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
case _toString.ARGUMENTS: | ||
return object; | ||
case _toString.FUNCTION: | ||
case _toString.GENERATOR: | ||
return { | ||
v: (0, _toString.toFunctionString)(object, type === _toString.GENERATOR) | ||
}; | ||
case _toString.ERROR: | ||
case _toString.NULL: | ||
case _toString.REGEXP: | ||
return prependTypeToString(object, type); | ||
case _toString.SYMBOL: | ||
return { | ||
v: object.toString() | ||
}; | ||
case _toString.DATE: | ||
return prependTypeToString(object.valueOf(), type); | ||
case _toString.PROMISE: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return { | ||
v: prependTypeToString('NOT_ENUMERABLE', type) | ||
}; | ||
case _toString.SYMBOL: | ||
return object.toString(); | ||
case _toString.MAP: | ||
case _toString.SET: | ||
var pairs = [getObjectType(type)]; | ||
case _toString.PROMISE: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return prependTypeToString('NOT_ENUMERABLE', type); | ||
object.forEach(function (item, key) { | ||
pairs.push([key, item]); | ||
}); | ||
case _toString.MAP: | ||
case _toString.SET: | ||
return getIterablePairs(object, type); | ||
return { | ||
v: pairs | ||
}; | ||
case _toString.ARRAY_BUFFER: | ||
return prependTypeToString(arrayBufferToString(object), type); | ||
case _toString.ARRAY_BUFFER: | ||
return { | ||
v: prependTypeToString(arrayBufferToString(object), type) | ||
}; | ||
case _toString.DATA_VIEW: | ||
return prependTypeToString(arrayBufferToString(object.buffer), type); | ||
case _toString.DATA_VIEW: | ||
return { | ||
v: prependTypeToString(arrayBufferToString(object.buffer), type) | ||
}; | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
return prependTypeToString(object.join(','), type); | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
return { | ||
v: prependTypeToString(object.join(','), type) | ||
}; | ||
case _toString.MATH: | ||
return MATH_OBJECT; | ||
case _toString.MATH: | ||
var mathObject = {}; | ||
MATH_PROPERTIES.forEach(function (prop) { | ||
mathObject[prop] = object[prop]; | ||
}); | ||
return { | ||
v: mathObject | ||
}; | ||
default: | ||
return { | ||
v: HTML_ELEMENT_REGEXP.test(type) ? 'HTMLElement ' + object.textContent : object | ||
}; | ||
} | ||
}(); | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
default: | ||
return HTML_ELEMENT_REGEXP.test(type) ? 'HTMLElement ' + object.textContent : object; | ||
} | ||
} | ||
}; | ||
@@ -184,3 +169,3 @@ | ||
return function (key, value) { | ||
if (key === '') { | ||
if (!key) { | ||
stack = [value]; | ||
@@ -194,58 +179,67 @@ recursiveCounter = 0; | ||
switch (type) { | ||
case _toString.ARGUMENTS: | ||
case _toString.BOOLEAN: | ||
case _toString.NUMBER: | ||
case _toString.STRING: | ||
switch (typeof value === 'undefined' ? 'undefined' : _typeof(value)) { | ||
case _toString.STRING_TYPEOF: | ||
case _toString.NUMBER_TYPEOF: | ||
case _toString.BOOLEAN_TYPEOF: | ||
return value; | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
if (!value) { | ||
return prependTypeToString(value, type); | ||
} | ||
case _toString.UNDEFINED_TYPEOF: | ||
case _toString.FUNCTION_TYPEOF: | ||
return getValueForStringification(value); | ||
if (++recursiveCounter > 255) { | ||
return 'Undefined undefined'; | ||
} | ||
default: | ||
switch (type) { | ||
case _toString.ARRAY: | ||
case _toString.OBJECT: | ||
if (!value) { | ||
return prependTypeToString(value, type); | ||
} | ||
index = stack.indexOf(value); | ||
if (++recursiveCounter > 255) { | ||
return 'Undefined undefined'; | ||
} | ||
if (!~index) { | ||
stack.push(value); | ||
index = stack.indexOf(value); | ||
return value; | ||
} | ||
if (!~index) { | ||
stack.push(value); | ||
return '*Recursive-' + index; | ||
return value; | ||
} | ||
case _toString.ARRAY_BUFFER: | ||
case _toString.DATA_VIEW: | ||
case _toString.DATE: | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.FUNCTION: | ||
case _toString.GENERATOR: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.ERROR: | ||
case _toString.MAP: | ||
case _toString.MATH: | ||
case _toString.NULL: | ||
case _toString.PROMISE: | ||
case _toString.REGEXP: | ||
case _toString.SET: | ||
case _toString.SYMBOL: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
case _toString.UNDEFINED: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return getValueForStringification(value); | ||
return '*Recursive-' + index; | ||
default: | ||
return value; | ||
case _toString.ARGUMENTS: | ||
return value; | ||
case _toString.DATE: | ||
case _toString.FUNCTION: | ||
case _toString.MAP: | ||
case _toString.SET: | ||
case _toString.PROMISE: | ||
case _toString.REGEXP: | ||
case _toString.NULL: | ||
case _toString.ARRAY_BUFFER: | ||
case _toString.DATA_VIEW: | ||
case _toString.FLOAT_32_ARRAY: | ||
case _toString.FLOAT_64_ARRAY: | ||
case _toString.GENERATOR: | ||
case _toString.INT_8_ARRAY: | ||
case _toString.INT_16_ARRAY: | ||
case _toString.INT_32_ARRAY: | ||
case _toString.ERROR: | ||
case _toString.MATH: | ||
case _toString.SYMBOL: | ||
case _toString.UINT_8_ARRAY: | ||
case _toString.UINT_8_CLAMPED_ARRAY: | ||
case _toString.UINT_16_ARRAY: | ||
case _toString.UINT_32_ARRAY: | ||
case _toString.UNDEFINED: | ||
case _toString.WEAKMAP: | ||
case _toString.WEAKSET: | ||
return getValueForStringification(value); | ||
default: | ||
return value; | ||
} | ||
} | ||
@@ -267,7 +261,9 @@ }; | ||
var length = string.length; | ||
var hashValue = 5381, | ||
index = string.length; | ||
index = -1; | ||
while (index) { | ||
hashValue = hashValue * 33 ^ string.charCodeAt(--index); | ||
while (++index < length) { | ||
hashValue = (hashValue << 5) + hashValue + string.charCodeAt(index); | ||
} | ||
@@ -278,6 +274,14 @@ | ||
var stringify = function stringify(value) { | ||
return JSON.stringify(value, REPLACER); | ||
}; | ||
var prune = function prune(value) { | ||
return _prune2.default.prune(value); | ||
}; | ||
/** | ||
* move try/catch to standalone function as any function that contains a try/catch | ||
* is not optimized (this allows optimization for as much as possible) | ||
* | ||
* fac | ||
* @param {*} value | ||
@@ -288,5 +292,5 @@ * @returns {string} | ||
try { | ||
return JSON.stringify(value, REPLACER); | ||
return stringify(value, REPLACER); | ||
} catch (exception) { | ||
return _prune2.default.prune(value); | ||
return prune(value); | ||
} | ||
@@ -296,3 +300,4 @@ }; | ||
/** | ||
* stringify the object passed leveraging the REPLACER | ||
* stringify the object passed leveraging JSON.stringify | ||
* with REPLACER, falling back to prune | ||
* | ||
@@ -302,3 +307,26 @@ * @param {*} object | ||
*/ | ||
var stringify = function stringify(object) { | ||
var getStringifiedValue = function getStringifiedValue(object) { | ||
var valueForStringification = getValueForStringification(object); | ||
if (typeof valueForStringification === 'string') { | ||
return valueForStringification; | ||
} | ||
return stringify(valueForStringification); | ||
}; | ||
/** | ||
* stringify the object passed leveraging JSON.stringify | ||
* with REPLACER | ||
* | ||
* @param {*} object | ||
* @returns {string} | ||
*/ | ||
var getStringifiedValueWithRecursion = function getStringifiedValueWithRecursion(object) { | ||
var valueForStringification = getValueForStringification(object); | ||
if (typeof valueForStringification === 'string') { | ||
return valueForStringification; | ||
} | ||
return tryCatch(getValueForStringification(object)); | ||
@@ -308,3 +336,4 @@ }; | ||
exports.getIntegerHashValue = getIntegerHashValue; | ||
exports.replacer = REPLACER; | ||
exports.stringify = stringify; | ||
exports.getStringifiedValue = getStringifiedValue; | ||
exports.getStringifiedValueWithRecursion = getStringifiedValueWithRecursion; | ||
exports.replacer = REPLACER; |
@@ -13,8 +13,6 @@ { | ||
}, | ||
"concurrency": 5, | ||
"failFast": true, | ||
"files": [ | ||
"./test/toString.js", | ||
"./test/prune.js", | ||
"./test/utils.js", | ||
"./test/index.js" | ||
"test/*.js" | ||
], | ||
@@ -25,3 +23,4 @@ "require": [ | ||
"./test/helpers/setup-browser-env.js" | ||
] | ||
], | ||
"verbose": true | ||
}, | ||
@@ -84,7 +83,7 @@ "bugs": { | ||
"prepublish": "in-publish && npm run compile-for-publish || in-install", | ||
"test": "NODE_ENV=test ava --no-cache --verbose", | ||
"test:watch": "NODE_ENV=test ava --no-cache --verbose --watch", | ||
"test": "NODE_ENV=test ava --no-cache", | ||
"test:watch": "NODE_ENV=test ava --verbose --watch", | ||
"transpile": "./node_modules/babel-cli/lib/babel/index.js -d lib/ src/" | ||
}, | ||
"version": "1.3.1" | ||
"version": "2.0.0" | ||
} |
@@ -86,2 +86,6 @@ # hashIt | ||
**withRecursion(object)** *returns `Number`* | ||
Performs the same kind of hashing, but handles very deep recursion on objects (such as the `window` object). | ||
**isEmpty(object)** *returns `Boolean`* | ||
@@ -88,0 +92,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91870
1344
156