Comparing version 4.0.4 to 4.0.5
# hashIt CHANGELOG | ||
## 4.0.5 | ||
- Fix issues related to string encoding and collisions | ||
[#23](https://github.com/planttheidea/hash-it/issues/23) | ||
## 4.0.4 | ||
@@ -14,3 +19,5 @@ | ||
- Fix [#18](https://github.com/planttheidea/hash-it/pull/18) - IE11 not allowing global `toString` to be used, instead using `Object.prototype.toString` (thanks [@JorgenEvens](https://github.com/JorgenEvens)) | ||
- Fix [#18](https://github.com/planttheidea/hash-it/pull/18) - IE11 not allowing global `toString` | ||
to be used, instead using `Object.prototype.toString` (thanks | ||
[@JorgenEvens](https://github.com/JorgenEvens)) | ||
@@ -23,11 +30,14 @@ ## 4.0.1 | ||
Rewrite! Lots of changes under-the-hood for a much more consistent hash, and circular object handling out of the box. | ||
Rewrite! Lots of changes under-the-hood for a much more consistent hash, and circular object | ||
handling out of the box. | ||
#### BREAKING CHANGES | ||
- `isEmpty`, `isEqual`,`isNull`, and `isUndefined` have been removed (all can be reproduced with new `is` and `is.all` functions) | ||
- `isEmpty`, `isEqual`,`isNull`, and `isUndefined` have been removed (all can be reproduced with new | ||
`is` and `is.all` functions) | ||
- `hash.isNull` => `hash.is(null)` | ||
- `hash.isUndefined` => `hash.is(undefined)` | ||
- `hash.isEqual` => `hash.is.all` | ||
- `hash.isEmpty` => `(object) => hash.is.any(object, undefined, null, '', 0, [], {}, new Map(), new Set())` | ||
- `hash.isEmpty` => | ||
`(object) => hash.is.any(object, undefined, null, '', 0, [], {}, new Map(), new Set())` | ||
- `Error` hashes now based on `error.stack` instead of `error.message` | ||
@@ -37,8 +47,11 @@ | ||
- Circular objects are now handled out of the box, thanks to [`fast-stringify`](https://github.com/planttheidea/fast-stringify) | ||
- Circular objects are now handled out of the box, thanks to | ||
[`fast-stringify`](https://github.com/planttheidea/fast-stringify) | ||
- Collision rates are near-zero (previously used traditional DJB2, which has small collision rates) | ||
- Better `ArrayBuffer` support with the use of `Buffer.from` when supported | ||
- SVG elements, DocumentFragments, and Events are now supported | ||
- `is` partial-application function allows for easy creation of any type of `isEqual` comparison method | ||
- `is.any` performs the same multiple-object check that `is.all` does, but only checks if one of the other objects is equal | ||
- `is` partial-application function allows for easy creation of any type of `isEqual` comparison | ||
method | ||
- `is.any` performs the same multiple-object check that `is.all` does, but only checks if one of the | ||
other objects is equal | ||
- `is.not` performs the same comparison that `is` does, but checks for non-equality | ||
@@ -74,6 +87,8 @@ | ||
- If using CommonJS, you need to specify `require('hash-it').default` instead of just `require('hash-it')` | ||
- If using CommonJS, you need to specify `require('hash-it').default` instead of just | ||
`require('hash-it')` | ||
- Hashes themselves may have changed (especially for circular objects) | ||
- Removed `isRecursive` method on `hashIt` object (which was wrongly named to begin with) | ||
- To specifically handle _circular_ objects (which is what it really did), pass `true` as the second parameter to `hashIt` | ||
- To specifically handle _circular_ objects (which is what it really did), pass `true` as the | ||
second parameter to `hashIt` | ||
@@ -99,3 +114,4 @@ ## 2.1.2 | ||
- 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`) | ||
- 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 | ||
@@ -111,3 +127,4 @@ - Leverage typeof in switch statements when possible for performance | ||
- Add hashIt.isUndefined, hashIt.isNull, and hashIt.isEmpty methods | ||
- Reorder switch statements in replacer and getValueForStringification to reflect most likely to least likely (improves performance a touch) | ||
- Reorder switch statements in replacer and getValueForStringification to reflect most likely to | ||
least likely (improves performance a touch) | ||
- Remove "Number" from number stringification | ||
@@ -125,3 +142,4 @@ - Leverage prependTypeToString whereever possible | ||
- Add hashIt.isEqual method to test for equality | ||
- Prepend all values not string or number with object class name to help avoid collision with equivalent string values | ||
- Prepend all values not string or number with object class name to help avoid collision with | ||
equivalent string values | ||
@@ -128,0 +146,0 @@ ## 1.1.0 |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = global || self, factory(global.hashIt = {})); | ||
}(this, function (exports) { 'use strict'; | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -23,56 +23,61 @@ /** | ||
*/ | ||
var recursiveCurry = function (fn, arity, args) { | ||
return function () { | ||
var length = args.length; | ||
var newArgs = arguments; | ||
var newArgsLength = newArgs.length; | ||
var combined = []; | ||
var newArgsIndex = 0; | ||
var remaining = arity; | ||
var value; | ||
if (length) { | ||
for (var index = 0; index < length; index++) { | ||
value = combined[index] = | ||
args[index] === __ && newArgsIndex < newArgsLength | ||
? newArgs[newArgsIndex++] | ||
: args[index]; | ||
if (value !== __) { | ||
--remaining; | ||
function getCurried(fn, arity) { | ||
function _curried(args) { | ||
return function () { | ||
var length = args.length; | ||
var newArgs = arguments; | ||
var newArgsLength = newArgs.length; | ||
var combined = []; | ||
var newArgsIndex = 0; | ||
var remaining = arity; | ||
var value; | ||
if (length) { | ||
var index = -1; | ||
while (++index < length) { | ||
combined[index] = value = | ||
args[index] === __ && newArgsIndex < newArgsLength | ||
? newArgs[newArgsIndex++] | ||
: args[index]; | ||
if (value !== __) { | ||
--remaining; | ||
} | ||
} | ||
} | ||
} | ||
if (newArgsIndex < newArgsLength) { | ||
for (; newArgsIndex < newArgsLength; newArgsIndex++) { | ||
value = newArgs[newArgsIndex]; | ||
combined.push(value); | ||
if (value !== __ && newArgsIndex < arity) { | ||
--remaining; | ||
if (newArgsIndex < newArgsLength) { | ||
while (newArgsIndex < newArgsLength) { | ||
combined[combined.length] = value = newArgs[newArgsIndex]; | ||
if (value !== __ && newArgsIndex < arity) { | ||
--remaining; | ||
} | ||
++newArgsIndex; | ||
} | ||
} | ||
} | ||
return remaining > 0 | ||
? recursiveCurry(fn, arity, combined) | ||
: fn.apply(this, combined); | ||
}; | ||
}; | ||
return remaining > 0 ? _curried(combined) : fn.apply(this, combined); | ||
}; | ||
} | ||
return _curried([]); | ||
} | ||
// utils | ||
function curry(fn, arityOverride) { | ||
var arity = typeof arityOverride === 'number' ? arityOverride : fn.length; | ||
var curried = getCurried(fn, arity); | ||
curried.arity = arity; | ||
curried.fn = fn; | ||
return curried; | ||
} | ||
curry.__ = __; | ||
/** | ||
* @function curry | ||
* @function isPlaceholder | ||
* | ||
* @description | ||
* get the method passed as a curriable method based on its parameters | ||
* is the value passed a placeholder | ||
* | ||
* @param fn the method to make curriable | ||
* @param arity the arity of the curried method | ||
* @returns the fn passed as a curried function | ||
* @param value the value to test | ||
* @returns whether the value is a placeholder | ||
*/ | ||
var curry = function (fn, arity) { | ||
if (arity === void 0) { arity = fn.length; } | ||
var curried = recursiveCurry(fn, arity, []); | ||
curried.arity = arity; | ||
curried.fn = fn; | ||
return curried; | ||
}; | ||
curry.__ = __; | ||
function isPlaceholder(value) { | ||
return value === __; | ||
} | ||
curry.isPlaceholder = isPlaceholder; | ||
/** | ||
@@ -87,125 +92,9 @@ * @function uncurry | ||
*/ | ||
var uncurry = function (curried) { return curried.fn; }; | ||
function uncurry(curried) { | ||
return curried.fn; | ||
} | ||
curry.uncurry = uncurry; | ||
/** | ||
* @function first | ||
* | ||
* @description | ||
* get the first n number of items from the array as a new array (faster than native splice) | ||
* | ||
* @param {Array<any>} array the array to get the items from | ||
* @param {number} length the length to limit the size to | ||
* @returns {Array<any>} the array limited in size | ||
*/ | ||
var first = function first(array, length) { | ||
var newArray = new Array(length); | ||
for (var index = 0; index < length; index++) { | ||
newArray[index] = array[index]; | ||
} | ||
return newArray; | ||
}; | ||
/** | ||
* @function getCircularValue | ||
* | ||
* @description | ||
* create a method that will get a placeholder for the circular value based | ||
* on the value saved in the cache for it | ||
* | ||
* @param {any} key the key of the object to stringify | ||
* @param {any} value the value of the object at key | ||
* @param {number} refCount the index of the ref | ||
* @returns {string} the circular value | ||
*/ | ||
var getCircularValue = function getCircularValue(key, value, refCount) { | ||
return "[ref-" + refCount + "]"; | ||
}; | ||
/** | ||
* @function indexOf | ||
* | ||
* @description | ||
* get the index of the value in the array (faster than native indexOf) | ||
* | ||
* @param {Array<any>} array the array to get the index of the value at | ||
* @param {any} value the value to match | ||
* @returns {number} the index of the value in array | ||
*/ | ||
var indexOf = function indexOf(array, value) { | ||
for (var index = 0; index < array.length; index++) { | ||
if (array[index] === value) { | ||
return index; | ||
} | ||
} | ||
return -1; | ||
}; | ||
/** | ||
* @function createReplacer | ||
* | ||
* @description | ||
* create a replacer method that handles circular values | ||
* | ||
* @param {function} [replacer] a custom replacer to use for non-circular values | ||
* @param {function} [circularReplacer] a custom replacer to use for circular methods | ||
* @returns {any} the value to stringify | ||
*/ | ||
var createReplacer = function createReplacer(replacer, circularReplacer) { | ||
var getCircularReplacer = circularReplacer || getCircularValue; | ||
var hasReplacer = typeof replacer === 'function'; | ||
var cache = [], | ||
locationOfThis, | ||
locationOfValue; | ||
return function (key, value) { | ||
if (cache.length) { | ||
locationOfThis = indexOf(cache, this); | ||
if (~locationOfThis) { | ||
cache = first(cache, locationOfThis + 1); | ||
} else { | ||
cache[cache.length] = this; | ||
} | ||
locationOfValue = indexOf(cache, value); | ||
if (~locationOfValue) { | ||
return getCircularReplacer.call(this, key, value, locationOfValue); | ||
} | ||
} else { | ||
cache[0] = value; | ||
} | ||
return hasReplacer ? replacer.call(this, key, value) : value; | ||
}; | ||
}; | ||
// utils | ||
/** | ||
* @function stringify | ||
* | ||
* @description | ||
* strinigifer that handles circular values | ||
* | ||
* @param {any} value the value to stringify | ||
* @param {function} [replacer] a custom replacer function for stringifying standard values | ||
* @param {number} [indent] the number of spaces to indent the output by | ||
* @param {function} [circularReplacer] a custom replacer function for stringifying circular values | ||
* @returns {string} the stringified output | ||
*/ | ||
function stringify(value, replacer, indent, circularReplacer) { | ||
return JSON.stringify(value, createReplacer(replacer, circularReplacer), indent); | ||
} | ||
var _SELF_TAGS, _TOSTRING_TAGS, _TYPEDARRAY_TAGS, _UNPARSEABLE_TAGS; | ||
/** | ||
* @constant {string} CIRCULAR_VALUE | ||
*/ | ||
var CIRCULAR_VALUE = '~'; | ||
/** | ||
* @constant {boolean} HAS_BUFFER_FROM_SUPPORT | ||
@@ -268,2 +157,3 @@ */ | ||
// external dependencies | ||
var SEPARATOR = '|'; | ||
var charCodeAt = String.prototype.charCodeAt; | ||
@@ -282,18 +172,6 @@ var toString = Object.prototype.toString; | ||
var getFunctionName = function getFunctionName(fn) { | ||
function getFunctionName(fn) { | ||
return fn.name || (fn.toString().match(/^\s*function\s*([^\(]*)/i) || [])[1] || 'anonymous'; | ||
}; | ||
} | ||
/** | ||
* @function getCircularValue | ||
* | ||
* @description | ||
* get the value used when circular references are found | ||
* | ||
* @returns {string} the value for stringification | ||
*/ | ||
var getCircularValue$1 = function getCircularValue() { | ||
return CIRCULAR_VALUE; | ||
}; | ||
/** | ||
* @function getIntegerHashValue | ||
@@ -310,3 +188,3 @@ * | ||
var getIntegerHashValue = function getIntegerHashValue(string) { | ||
function getIntegerHashValue(string) { | ||
var index = string.length, | ||
@@ -324,3 +202,3 @@ hashA = 5381, | ||
return (hashA >>> 0) * 4096 + (hashB >>> 0); | ||
}; | ||
} | ||
/** | ||
@@ -346,28 +224,17 @@ * @function getSortedEvent | ||
var getSortedEvent = function getSortedEvent(_ref) { | ||
var bubbles = _ref.bubbles, | ||
cancelBubble = _ref.cancelBubble, | ||
cancelable = _ref.cancelable, | ||
composed = _ref.composed, | ||
currentTarget = _ref.currentTarget, | ||
defaultPrevented = _ref.defaultPrevented, | ||
eventPhase = _ref.eventPhase, | ||
isTrusted = _ref.isTrusted, | ||
returnValue = _ref.returnValue, | ||
target = _ref.target, | ||
type = _ref.type; | ||
function getSortedEvent(event) { | ||
return { | ||
bubbles: bubbles, | ||
cancelBubble: cancelBubble, | ||
cancelable: cancelable, | ||
composed: composed, | ||
currentTarget: currentTarget, | ||
defaultPrevented: defaultPrevented, | ||
eventPhase: eventPhase, | ||
isTrusted: isTrusted, | ||
returnValue: returnValue, | ||
target: target, | ||
type: type | ||
bubbles: event.bubbles, | ||
cancelBubble: event.cancelBubble, | ||
cancelable: event.cancelable, | ||
composed: event.composed, | ||
currentTarget: event.currentTarget, | ||
defaultPrevented: event.defaultPrevented, | ||
eventPhase: event.eventPhase, | ||
isTrusted: event.isTrusted, | ||
returnValue: event.returnValue, | ||
target: event.target, | ||
type: event.type | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -384,5 +251,5 @@ * @function shouldSort | ||
var shouldSort = function shouldSort(valueA, valueB) { | ||
function shouldSort(valueA, valueB) { | ||
return valueA > valueB; | ||
}; | ||
} | ||
/** | ||
@@ -399,20 +266,6 @@ * @function shouldSortPair | ||
var shouldSortPair = function shouldSortPair(pairA, pairB) { | ||
function shouldSortPair(pairA, pairB) { | ||
return shouldSort(pairA[0], pairB[0]); | ||
}; | ||
} | ||
/** | ||
* @function getPrefixedValue | ||
* | ||
* @description | ||
* get the value prefixed by the tag | ||
* | ||
* @param {string} tag the object tag | ||
* @param {any} value the value to stringify | ||
* @returns {string} the prefixed stringified value | ||
*/ | ||
var getPrefixedValue = function getPrefixedValue(tag, value) { | ||
return tag + "|" + value; | ||
}; | ||
/** | ||
* @function sort | ||
@@ -428,3 +281,3 @@ * | ||
var sort = function sort(array, fn) { | ||
function sort(array, fn) { | ||
var subIndex, value; | ||
@@ -443,3 +296,3 @@ | ||
return array; | ||
}; | ||
} | ||
/** | ||
@@ -455,20 +308,32 @@ * @function getIterablePairs | ||
var getSortedIterablePairs = function getSortedIterablePairs(iterable) { | ||
function getSortedIterablePairs(iterable, cache, keys) { | ||
var isMap = typeof iterable.get === 'function'; | ||
var pairs = []; | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push(isMap ? [stringify$1(key), stringify$1(value)] : [stringify$1(value)]); | ||
}); | ||
if (isMap) { | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(key, cache, keys), stringify(value, cache, keys)]); | ||
}); | ||
} else { | ||
iterable.forEach(function (value) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(value, cache, keys)]); | ||
}); | ||
} | ||
sort(pairs, shouldSortPair); | ||
var finalPairs = new Array(iterable.size); | ||
var length = pairs.length; | ||
var lastIndex = length - 1; | ||
var _final = '['; | ||
var pair; | ||
for (var index = 0; index < iterable.size; index++) { | ||
for (var index = 0; index < length; index++) { | ||
pair = pairs[index]; | ||
finalPairs[index] = isMap ? "[" + pair[0] + "," + pair[1] + "]" : pair[0]; | ||
_final += isMap ? '[' + pair[0] + ',' + pair[1] + ']' : pair[0]; | ||
_final += index === lastIndex ? ']' : ','; | ||
} | ||
return getPrefixedValue(getFunctionName(iterable.constructor), "[" + finalPairs.join(',') + "]"); | ||
}; | ||
return getFunctionName(iterable.constructor) + SEPARATOR + _final; | ||
} | ||
/** | ||
@@ -484,3 +349,3 @@ * @function getSortedObject | ||
var getSortedObject = function getSortedObject(object) { | ||
function getSortedObject(object) { | ||
var objectKeys = sort(keys(object), shouldSort); | ||
@@ -496,3 +361,3 @@ var newObject = {}; | ||
return newObject; | ||
}; | ||
} | ||
/** | ||
@@ -508,5 +373,5 @@ * @function getStringifiedArrayBufferFallback | ||
var getStringifiedArrayBufferFallback = function getStringifiedArrayBufferFallback(buffer) { | ||
function getStringifiedArrayBufferFallback(buffer) { | ||
return String.fromCharCode.apply(null, new Uint16Array(buffer)); | ||
}; | ||
} | ||
/** | ||
@@ -522,5 +387,5 @@ * @function getStringifiedArrayBufferModern | ||
var getStringifiedArrayBufferModern = function getStringifiedArrayBufferModern(buffer) { | ||
function getStringifiedArrayBufferModern(buffer) { | ||
return Buffer.from(buffer).toString('utf8'); | ||
}; | ||
} | ||
/** | ||
@@ -535,5 +400,5 @@ * @function getStringifiedArrayBufferNoSupport | ||
var getStringifiedArrayBufferNoSupport = function getStringifiedArrayBufferNoSupport() { | ||
function getStringifiedArrayBufferNoSupport() { | ||
return ''; | ||
}; | ||
} | ||
/** | ||
@@ -570,3 +435,3 @@ * @function getStringifiedArrayBuffer | ||
var getStringifiedDocumentFragment = function getStringifiedDocumentFragment(fragment) { | ||
function getStringifiedDocumentFragment(fragment) { | ||
var children = fragment.children; | ||
@@ -580,23 +445,24 @@ var innerHTML = ''; | ||
return innerHTML; | ||
}; | ||
} | ||
/** | ||
* @function indexOf | ||
* @function getCutoffIndex | ||
* | ||
* @description | ||
* get the index of the value in the array (faster than native indexOf) | ||
* get the index after that of the value match in the array (faster than | ||
* native indexOf) to determine the cutoff index for the `splice()` call. | ||
* | ||
* @param {Array<any>} array the array to get the index of the value at | ||
* @param {any} value the value to match | ||
* @returns {number} the index of the value in array | ||
* @returns {number} the index after the value match in the array | ||
*/ | ||
var indexOf$1 = function indexOf(array, value) { | ||
function getCutoffIndex(array, value) { | ||
for (var index = 0; index < array.length; index++) { | ||
if (array[index] === value) { | ||
return index; | ||
return index + 1; | ||
} | ||
} | ||
return -1; | ||
}; | ||
return 0; | ||
} | ||
/** | ||
@@ -614,16 +480,12 @@ * @function getNormalizedValue | ||
var getNormalizedValue = function getNormalizedValue(value, sortedCache, passedTag) { | ||
function getNormalizedValue(value, cache, keys, passedTag) { | ||
if (passedTag === void 0) { | ||
var type = typeof value; | ||
if (type === 'string') { | ||
return value; | ||
if (type === 'string' || PRIMITIVE_TAGS[type]) { | ||
return type + SEPARATOR + value; | ||
} | ||
if (PRIMITIVE_TAGS[type]) { | ||
return getPrefixedValue(type, value); | ||
} | ||
if (value === null) { | ||
return getPrefixedValue('null', value); | ||
return 'null' + SEPARATOR + value; | ||
} | ||
@@ -639,29 +501,19 @@ } | ||
if (tag === OBJECT_CLASS_TYPE_MAP.OBJECT) { | ||
if (~indexOf$1(sortedCache, value)) { | ||
return CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedObject(value, sortedCache); | ||
return getSortedObject(value); | ||
} | ||
if (TOSTRING_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.toString()); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.toString(); | ||
} | ||
if (ITERABLE_TAGS[tag]) { | ||
if (~indexOf$1(sortedCache, value)) { | ||
return CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedIterablePairs(value); | ||
return getSortedIterablePairs(value, cache, keys); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATE) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.getTime()); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.getTime(); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.ERROR) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.stack); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.stack; | ||
} | ||
@@ -674,27 +526,27 @@ | ||
if (UNPARSEABLE_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], 'NOT_ENUMERABLE'); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + 'NOT_ENUMERABLE'; | ||
} | ||
if (HTML_ELEMENT_REGEXP.test(tag) || SVG_ELEMENT_REGEXP.test(tag)) { | ||
return getPrefixedValue(tag.slice(8, -1), value.outerHTML); | ||
return tag.slice(8, -1) + SEPARATOR + value.outerHTML; | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DOCUMENTFRAGMENT) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedDocumentFragment(value)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedDocumentFragment(value); | ||
} | ||
if (TYPEDARRAY_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.join(',')); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.join(','); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.ARRAYBUFFER) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATAVIEW) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value.buffer)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value.buffer); | ||
} | ||
return value; | ||
}; | ||
} | ||
/** | ||
@@ -710,7 +562,45 @@ * @function replacer | ||
var createReplacer$1 = function createReplacer(sortedCache) { | ||
function createReplacer(cache, keys) { | ||
if (cache === void 0) { | ||
cache = []; | ||
} | ||
if (keys === void 0) { | ||
keys = []; | ||
} | ||
return function (key, value) { | ||
return getNormalizedValue(value, sortedCache); | ||
if (typeof value === 'object') { | ||
if (cache.length) { | ||
var thisCutoff = getCutoffIndex(cache, this); | ||
if (thisCutoff === 0) { | ||
cache.push(this); | ||
} else { | ||
cache.splice(thisCutoff); | ||
keys.splice(thisCutoff); | ||
} | ||
keys.push(key); | ||
var valueCutoff = getCutoffIndex(cache, value); | ||
if (valueCutoff !== 0) { | ||
var ref = keys.slice(0, valueCutoff).join('.') || '.'; | ||
return "[~" + ref + "]"; | ||
} | ||
cache.push(value); | ||
} else { | ||
cache[0] = value; | ||
keys[0] = key; | ||
} | ||
} | ||
if (key && this[key] instanceof Date) { | ||
return getNormalizedValue(this[key], cache, keys, OBJECT_CLASS_TYPE_MAP.DATE); | ||
} | ||
return getNormalizedValue(value, cache, keys); | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -726,9 +616,14 @@ * @function stringify | ||
function stringify$1(value) { | ||
function stringify(value, cache, keys) { | ||
if (!value || typeof value !== 'object') { | ||
return getNormalizedValue(value); | ||
return getNormalizedValue(value, cache, keys); | ||
} | ||
var tag = toString.call(value); | ||
return tag === OBJECT_CLASS_TYPE_MAP.DATE || tag === OBJECT_CLASS_TYPE_MAP.REGEXP ? getNormalizedValue(value, void 0, tag) : stringify(value, createReplacer$1([]), null, getCircularValue$1); | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATE || tag === OBJECT_CLASS_TYPE_MAP.REGEXP) { | ||
return getNormalizedValue(value, cache, keys, tag); | ||
} | ||
return JSON.stringify(value, createReplacer(cache, keys)); | ||
} | ||
@@ -747,5 +642,5 @@ | ||
var hash = function hash(value) { | ||
return getIntegerHashValue(stringify$1(value)); | ||
}; | ||
function hash(value) { | ||
return getIntegerHashValue(stringify(value)); | ||
} | ||
/** | ||
@@ -828,8 +723,8 @@ * @function hash.is | ||
exports.default = hash; | ||
exports.hash = hash; | ||
exports.default = hash; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
}))); | ||
//# sourceMappingURL=hash-it.js.map |
@@ -1,1 +0,1 @@ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r=r||self).hashIt={})}(this,function(r){"use strict";var s="function"==typeof Symbol?Symbol("curriable placeholder"):60881,A=function(a,c,l){return function(){var r,n=l.length,t=arguments,e=t.length,u=[],o=0,f=c;if(n)for(var i=0;i<n;i++)(r=u[i]=l[i]===s&&o<e?t[o++]:l[i])!==s&&--f;if(o<e)for(;o<e;o++)r=t[o],u.push(r),r!==s&&o<c&&--f;return 0<f?A(a,c,u):a.apply(this,u)}},n=function(r,n){void 0===n&&(n=r.length);var t=A(r,n,[]);return t.arity=n,t.fn=r,t};n.__=s;n.uncurry=function(r){return r.fn};var t,e,u,o,a=function(r,n,t){return"[ref-"+t+"]"},c=function(r,n){for(var t=0;t<r.length;t++)if(r[t]===n)return t;return-1},f=function(t,r){var e,u,o=r||a,f="function"==typeof t,i=[];return function(r,n){if(i.length){if(~(e=c(i,this))?i=function(r,n){for(var t=new Array(n),e=0;e<n;e++)t[e]=r[e];return t}(i,e+1):i[i.length]=this,~(u=c(i,n)))return o.call(this,r,n,u)}else i[0]=n;return f?t.call(this,r,n):n}};var i="undefined"!=typeof Buffer&&"function"==typeof Buffer.from,l="function"==typeof Uint16Array,y=/\[object (HTML(.*)Element)\]/,h=/\[object (SVG(.*)Element)\]/,p=["Arguments","Array","ArrayBuffer","Boolean","DataView","Date","DocumentFragment","Error","Event","Float32Array","Float64Array","Function","Generator","GeneratorFunction","HTMLElement","Int8Array","Int16Array","Int32Array","Map","Null","Number","Object","Promise","RegExp","Set","String","Symbol","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","Undefined","WeakMap","WeakSet","Window"].reduce(function(r,n){return r["[object "+n+"]"]=n,r},{}),d=Object.keys(p).reduce(function(r,n){return r[p[n].toUpperCase()]=n,r},{}),R={"[object Map]":!0,"[object Set]":!0},g={boolean:!0,function:!0,number:!0,string:!0,undefined:!0},v=((t={})[d.ARGUMENTS]=!0,t[d.ARRAY]=!0,t),b=((e={})[d.REGEXP]=!0,e[d.SYMBOL]=!0,e),E=((u={})[d.FLOAT32ARRAY]=!0,u[d.FLOAT64ARRAY]=!0,u[d.INT8ARRAY]=!0,u[d.INT16ARRAY]=!0,u[d.INT32ARRAY]=!0,u[d.UINT8ARRAY]=!0,u[d.UINT8CLAMPEDARRAY]=!0,u[d.UINT16ARRAY]=!0,u[d.UINT32ARRAY]=!0,u),T=((o={})[d.GENERATOR]=!0,o[d.PROMISE]=!0,o[d.WEAKMAP]=!0,o[d.WEAKSET]=!0,o),m=String.prototype.charCodeAt,S=Object.prototype.toString,N=Object.keys,M=function(){return"~"},U=function(r,n){return n<r},O=function(r,n){return U(r[0],n[0])},j=function(r,n){return r+"|"+n},I=function(r,n){for(var t,e,u=0;u<r.length;u++){for(e=r[u],t=u-1;~t&&n(r[t],e);t--)r[t+1]=r[t];r[t+1]=e}return r},Y=i?function(r){return Buffer.from(r).toString("utf8")}:l?function(r){return String.fromCharCode.apply(null,new Uint16Array(r))}:function(){return""},B=function(r,n){for(var t=0;t<r.length;t++)if(r[t]===n)return t;return-1},P=function(r,n,t){if(void 0===t){var e=typeof r;if("string"===e)return r;if(g[e])return j(e,r);if(null===r)return j("null",r)}var u,o=t||S.call(r);return v[o]?r:o===d.OBJECT?~B(n,r)?"~":(n.push(r),function(r){for(var n,t=I(N(r),U),e={},u=0;u<t.length;u++)e[n=t[u]]=r[n];return e}(r)):b[o]?j(p[o],r.toString()):R[o]?~B(n,r)?"~":(n.push(r),function(r){var t="function"==typeof r.get,e=[];r.forEach(function(r,n){e.push(t?[L(n),L(r)]:[L(r)])}),I(e,O);for(var n,u,o=new Array(r.size),f=0;f<r.size;f++)n=e[f],o[f]=t?"["+n[0]+","+n[1]+"]":n[0];return j((u=r.constructor).name||(u.toString().match(/^\s*function\s*([^\(]*)/i)||[])[1]||"anonymous","["+o.join(",")+"]")}(r)):o===d.DATE?j(p[o],r.getTime()):o===d.ERROR?j(p[o],r.stack):o===d.EVENT?{bubbles:(u=r).bubbles,cancelBubble:u.cancelBubble,cancelable:u.cancelable,composed:u.composed,currentTarget:u.currentTarget,defaultPrevented:u.defaultPrevented,eventPhase:u.eventPhase,isTrusted:u.isTrusted,returnValue:u.returnValue,target:u.target,type:u.type}:T[o]?j(p[o],"NOT_ENUMERABLE"):y.test(o)||h.test(o)?j(o.slice(8,-1),r.outerHTML):o===d.DOCUMENTFRAGMENT?j(p[o],function(r){for(var n=r.children,t="",e=0;e<n.length;e++)t+=n[e].outerHTML;return t}(r)):E[o]?j(p[o],r.join(",")):o===d.ARRAYBUFFER?j(p[o],Y(r)):o===d.DATAVIEW?j(p[o],Y(r.buffer)):r},F=function(t){return function(r,n){return P(n,t)}};function L(r){if(!r||"object"!=typeof r)return P(r);var n,t,e,u,o=S.call(r);return o===d.DATE||o===d.REGEXP?P(r,void 0,o):(n=r,t=F([]),e=null,u=M,JSON.stringify(n,f(t,u),e))}var C=function(r){return function(r){for(var n,t=r.length,e=5381,u=52711;t--;)e=33*e^(n=m.call(r,t)),u=33*u^n;return 4096*(e>>>0)+(u>>>0)}(L(r))};(C.is=n(function(r,n){return C(r)===C(n)})).all=n(function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];for(var e=C.is(n.shift()),u=0;u<n.length;u++)if(!e(n[u]))return!1;return!0},2),C.is.any=n(function(){for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];for(var e=C.is(n.shift()),u=0;u<n.length;u++)if(e(n[u]))return!0;return!1},2),C.is.not=n(function(r,n){return C(r)!==C(n)}),r.hash=C,r.default=C,Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).hashIt={})}(this,(function(t){"use strict";var e,n,r,o,u="function"==typeof Symbol?Symbol("curriable placeholder"):60881;function i(t,e){var n="number"==typeof e?e:t.length,r=function(t,e){return function n(r){return function(){var o,i=r.length,f=arguments,a=f.length,c=[],l=0,s=e;if(i)for(var A=-1;++A<i;)c[A]=o=r[A]===u&&l<a?f[l++]:r[A],o!==u&&--s;if(l<a)for(;l<a;)c[c.length]=o=f[l],o!==u&&l<e&&--s,++l;return s>0?n(c):t.apply(this,c)}}([])}(t,n);return r.arity=n,r.fn=t,r}i.__=u,i.isPlaceholder=function(t){return t===u},i.uncurry=function(t){return t.fn};var f="undefined"!=typeof Buffer&&"function"==typeof Buffer.from,a="function"==typeof Uint16Array,c=/\[object (HTML(.*)Element)\]/,l=/\[object (SVG(.*)Element)\]/,s=["Arguments","Array","ArrayBuffer","Boolean","DataView","Date","DocumentFragment","Error","Event","Float32Array","Float64Array","Function","Generator","GeneratorFunction","HTMLElement","Int8Array","Int16Array","Int32Array","Map","Null","Number","Object","Promise","RegExp","Set","String","Symbol","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","Undefined","WeakMap","WeakSet","Window"].reduce((function(t,e){return t["[object "+e+"]"]=e,t}),{}),A=Object.keys(s).reduce((function(t,e){return t[s[e].toUpperCase()]=e,t}),{}),y={"[object Map]":!0,"[object Set]":!0},p={boolean:!0,function:!0,number:!0,string:!0,undefined:!0},h=((e={})[A.ARGUMENTS]=!0,e[A.ARRAY]=!0,e),d=((n={})[A.REGEXP]=!0,n[A.SYMBOL]=!0,n),R=((r={})[A.FLOAT32ARRAY]=!0,r[A.FLOAT64ARRAY]=!0,r[A.INT8ARRAY]=!0,r[A.INT16ARRAY]=!0,r[A.INT32ARRAY]=!0,r[A.UINT8ARRAY]=!0,r[A.UINT8CLAMPEDARRAY]=!0,r[A.UINT16ARRAY]=!0,r[A.UINT32ARRAY]=!0,r),b=((o={})[A.GENERATOR]=!0,o[A.PROMISE]=!0,o[A.WEAKMAP]=!0,o[A.WEAKSET]=!0,o),g=String.prototype.charCodeAt,E=Object.prototype.toString,v=Object.keys;function T(t,e){return t>e}function m(t,e){return T(t[0],e[0])}function S(t,e){for(var n,r,o=0;o<t.length;o++){for(r=t[o],n=o-1;~n&&e(t[n],r);n--)t[n+1]=t[n];t[n+1]=r}return t}function N(t){for(var e,n=S(v(t),T),r={},o=0;o<n.length;o++)r[e=n[o]]=t[e];return r}function M(t){return String.fromCharCode.apply(null,new Uint16Array(t))}function U(t){return Buffer.from(t).toString("utf8")}function j(){return""}var O=f?U:a?M:j;function I(t,e){for(var n=0;n<t.length;n++)if(t[n]===e)return n+1;return 0}function P(t,e,n,r){if(void 0===r){var o=typeof t;if("string"===o||p[o])return o+"|"+t;if(null===t)return"null|"+t}var u,i=r||E.call(t);return h[i]?t:i===A.OBJECT?N(t):d[i]?s[i]+"|"+t.toString():y[i]?function(t,e,n){var r="function"==typeof t.get,o=[];r?t.forEach((function(t,r){o.push([Y(r,e,n),Y(t,e,n)])})):t.forEach((function(t){o.push([Y(t,e,n)])})),S(o,m);for(var u,i,f=o.length,a=f-1,c="[",l=0;l<f;l++)u=o[l],c+=r?"["+u[0]+","+u[1]+"]":u[0],c+=l===a?"]":",";return((i=t.constructor).name||(i.toString().match(/^\s*function\s*([^\(]*)/i)||[])[1]||"anonymous")+"|"+c}(t,e,n):i===A.DATE?s[i]+"|"+t.getTime():i===A.ERROR?s[i]+"|"+t.stack:i===A.EVENT?{bubbles:(u=t).bubbles,cancelBubble:u.cancelBubble,cancelable:u.cancelable,composed:u.composed,currentTarget:u.currentTarget,defaultPrevented:u.defaultPrevented,eventPhase:u.eventPhase,isTrusted:u.isTrusted,returnValue:u.returnValue,target:u.target,type:u.type}:b[i]?s[i]+"|NOT_ENUMERABLE":c.test(i)||l.test(i)?i.slice(8,-1)+"|"+t.outerHTML:i===A.DOCUMENTFRAGMENT?s[i]+"|"+function(t){for(var e=t.children,n="",r=0;r<e.length;r++)n+=e[r].outerHTML;return n}(t):R[i]?s[i]+"|"+t.join(","):i===A.ARRAYBUFFER?s[i]+"|"+O(t):i===A.DATAVIEW?s[i]+"|"+O(t.buffer):t}function Y(t,e,n){if(!t||"object"!=typeof t)return P(t,e,n);var r=E.call(t);return r===A.DATE||r===A.REGEXP?P(t,e,n,r):JSON.stringify(t,function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=[]),function(n,r){if("object"==typeof r)if(t.length){var o=I(t,this);0===o?t.push(this):(t.splice(o),e.splice(o)),e.push(n);var u=I(t,r);if(0!==u)return"[~"+(e.slice(0,u).join(".")||".")+"]";t.push(r)}else t[0]=r,e[0]=n;return n&&this[n]instanceof Date?P(this[n],t,e,A.DATE):P(r,t,e)}}(e,n))}function B(t){return function(t){for(var e,n=t.length,r=5381,o=52711;n--;)r=33*r^(e=g.call(t,n)),o=33*o^e;return 4096*(r>>>0)+(o>>>0)}(Y(t))}B.is=i((function(t,e){return B(t)===B(e)})),B.is.all=i((function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var r=B.is(e.shift()),o=0;o<e.length;o++)if(!r(e[o]))return!1;return!0}),2),B.is.any=i((function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var r=B.is(e.shift()),o=0;o<e.length;o++)if(r(e[o]))return!0;return!1}),2),B.is.not=i((function(t,e){return B(t)!==B(e)})),t.default=B,t.hash=B,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -15,5 +15,5 @@ // external dependencies | ||
export var hash = function hash(value) { | ||
export function hash(value) { | ||
return getIntegerHashValue(stringify(value)); | ||
}; | ||
} | ||
/** | ||
@@ -20,0 +20,0 @@ * @function hash.is |
257
es/utils.js
// external dependencies | ||
import fastStringify from 'fast-stringify'; // constants | ||
import { CIRCULAR_VALUE, HAS_BUFFER_FROM_SUPPORT, HAS_UINT16ARRAY_SUPPORT, HTML_ELEMENT_REGEXP, ITERABLE_TAGS, OBJECT_CLASS_MAP, OBJECT_CLASS_TYPE_MAP, PRIMITIVE_TAGS, SELF_TAGS, SVG_ELEMENT_REGEXP, TOSTRING_TAGS, TYPEDARRAY_TAGS, UNPARSEABLE_TAGS } from './constants'; | ||
// constants | ||
import { HAS_BUFFER_FROM_SUPPORT, HAS_UINT16ARRAY_SUPPORT, HTML_ELEMENT_REGEXP, ITERABLE_TAGS, OBJECT_CLASS_MAP, OBJECT_CLASS_TYPE_MAP, PRIMITIVE_TAGS, SELF_TAGS, SVG_ELEMENT_REGEXP, TOSTRING_TAGS, TYPEDARRAY_TAGS, UNPARSEABLE_TAGS } from './constants'; | ||
var SEPARATOR = '|'; | ||
var charCodeAt = String.prototype.charCodeAt; | ||
@@ -18,18 +18,6 @@ var toString = Object.prototype.toString; | ||
export var getFunctionName = function getFunctionName(fn) { | ||
export function getFunctionName(fn) { | ||
return fn.name || (fn.toString().match(/^\s*function\s*([^\(]*)/i) || [])[1] || 'anonymous'; | ||
}; | ||
} | ||
/** | ||
* @function getCircularValue | ||
* | ||
* @description | ||
* get the value used when circular references are found | ||
* | ||
* @returns {string} the value for stringification | ||
*/ | ||
export var getCircularValue = function getCircularValue() { | ||
return CIRCULAR_VALUE; | ||
}; | ||
/** | ||
* @function getIntegerHashValue | ||
@@ -46,3 +34,3 @@ * | ||
export var getIntegerHashValue = function getIntegerHashValue(string) { | ||
export function getIntegerHashValue(string) { | ||
var index = string.length, | ||
@@ -60,3 +48,3 @@ hashA = 5381, | ||
return (hashA >>> 0) * 4096 + (hashB >>> 0); | ||
}; | ||
} | ||
/** | ||
@@ -82,28 +70,17 @@ * @function getSortedEvent | ||
export var getSortedEvent = function getSortedEvent(_ref) { | ||
var bubbles = _ref.bubbles, | ||
cancelBubble = _ref.cancelBubble, | ||
cancelable = _ref.cancelable, | ||
composed = _ref.composed, | ||
currentTarget = _ref.currentTarget, | ||
defaultPrevented = _ref.defaultPrevented, | ||
eventPhase = _ref.eventPhase, | ||
isTrusted = _ref.isTrusted, | ||
returnValue = _ref.returnValue, | ||
target = _ref.target, | ||
type = _ref.type; | ||
export function getSortedEvent(event) { | ||
return { | ||
bubbles: bubbles, | ||
cancelBubble: cancelBubble, | ||
cancelable: cancelable, | ||
composed: composed, | ||
currentTarget: currentTarget, | ||
defaultPrevented: defaultPrevented, | ||
eventPhase: eventPhase, | ||
isTrusted: isTrusted, | ||
returnValue: returnValue, | ||
target: target, | ||
type: type | ||
bubbles: event.bubbles, | ||
cancelBubble: event.cancelBubble, | ||
cancelable: event.cancelable, | ||
composed: event.composed, | ||
currentTarget: event.currentTarget, | ||
defaultPrevented: event.defaultPrevented, | ||
eventPhase: event.eventPhase, | ||
isTrusted: event.isTrusted, | ||
returnValue: event.returnValue, | ||
target: event.target, | ||
type: event.type | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -120,5 +97,5 @@ * @function shouldSort | ||
export var shouldSort = function shouldSort(valueA, valueB) { | ||
export function shouldSort(valueA, valueB) { | ||
return valueA > valueB; | ||
}; | ||
} | ||
/** | ||
@@ -135,20 +112,6 @@ * @function shouldSortPair | ||
export var shouldSortPair = function shouldSortPair(pairA, pairB) { | ||
export function shouldSortPair(pairA, pairB) { | ||
return shouldSort(pairA[0], pairB[0]); | ||
}; | ||
} | ||
/** | ||
* @function getPrefixedValue | ||
* | ||
* @description | ||
* get the value prefixed by the tag | ||
* | ||
* @param {string} tag the object tag | ||
* @param {any} value the value to stringify | ||
* @returns {string} the prefixed stringified value | ||
*/ | ||
export var getPrefixedValue = function getPrefixedValue(tag, value) { | ||
return tag + "|" + value; | ||
}; | ||
/** | ||
* @function sort | ||
@@ -164,3 +127,3 @@ * | ||
export var sort = function sort(array, fn) { | ||
export function sort(array, fn) { | ||
var subIndex, value; | ||
@@ -179,3 +142,3 @@ | ||
return array; | ||
}; | ||
} | ||
/** | ||
@@ -191,20 +154,32 @@ * @function getIterablePairs | ||
export var getSortedIterablePairs = function getSortedIterablePairs(iterable) { | ||
export function getSortedIterablePairs(iterable, cache, keys) { | ||
var isMap = typeof iterable.get === 'function'; | ||
var pairs = []; | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push(isMap ? [stringify(key), stringify(value)] : [stringify(value)]); | ||
}); | ||
if (isMap) { | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(key, cache, keys), stringify(value, cache, keys)]); | ||
}); | ||
} else { | ||
iterable.forEach(function (value) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(value, cache, keys)]); | ||
}); | ||
} | ||
sort(pairs, shouldSortPair); | ||
var finalPairs = new Array(iterable.size); | ||
var length = pairs.length; | ||
var lastIndex = length - 1; | ||
var _final = '['; | ||
var pair; | ||
for (var index = 0; index < iterable.size; index++) { | ||
for (var index = 0; index < length; index++) { | ||
pair = pairs[index]; | ||
finalPairs[index] = isMap ? "[" + pair[0] + "," + pair[1] + "]" : pair[0]; | ||
_final += isMap ? '[' + pair[0] + ',' + pair[1] + ']' : pair[0]; | ||
_final += index === lastIndex ? ']' : ','; | ||
} | ||
return getPrefixedValue(getFunctionName(iterable.constructor), "[" + finalPairs.join(',') + "]"); | ||
}; | ||
return getFunctionName(iterable.constructor) + SEPARATOR + _final; | ||
} | ||
/** | ||
@@ -220,3 +195,3 @@ * @function getSortedObject | ||
export var getSortedObject = function getSortedObject(object) { | ||
export function getSortedObject(object) { | ||
var objectKeys = sort(keys(object), shouldSort); | ||
@@ -232,3 +207,3 @@ var newObject = {}; | ||
return newObject; | ||
}; | ||
} | ||
/** | ||
@@ -244,5 +219,5 @@ * @function getStringifiedArrayBufferFallback | ||
export var getStringifiedArrayBufferFallback = function getStringifiedArrayBufferFallback(buffer) { | ||
export function getStringifiedArrayBufferFallback(buffer) { | ||
return String.fromCharCode.apply(null, new Uint16Array(buffer)); | ||
}; | ||
} | ||
/** | ||
@@ -258,5 +233,5 @@ * @function getStringifiedArrayBufferModern | ||
export var getStringifiedArrayBufferModern = function getStringifiedArrayBufferModern(buffer) { | ||
export function getStringifiedArrayBufferModern(buffer) { | ||
return Buffer.from(buffer).toString('utf8'); | ||
}; | ||
} | ||
/** | ||
@@ -271,5 +246,5 @@ * @function getStringifiedArrayBufferNoSupport | ||
export var getStringifiedArrayBufferNoSupport = function getStringifiedArrayBufferNoSupport() { | ||
export function getStringifiedArrayBufferNoSupport() { | ||
return ''; | ||
}; | ||
} | ||
/** | ||
@@ -306,3 +281,3 @@ * @function getStringifiedArrayBuffer | ||
export var getStringifiedDocumentFragment = function getStringifiedDocumentFragment(fragment) { | ||
export function getStringifiedDocumentFragment(fragment) { | ||
var children = fragment.children; | ||
@@ -316,23 +291,24 @@ var innerHTML = ''; | ||
return innerHTML; | ||
}; | ||
} | ||
/** | ||
* @function indexOf | ||
* @function getCutoffIndex | ||
* | ||
* @description | ||
* get the index of the value in the array (faster than native indexOf) | ||
* get the index after that of the value match in the array (faster than | ||
* native indexOf) to determine the cutoff index for the `splice()` call. | ||
* | ||
* @param {Array<any>} array the array to get the index of the value at | ||
* @param {any} value the value to match | ||
* @returns {number} the index of the value in array | ||
* @returns {number} the index after the value match in the array | ||
*/ | ||
export var indexOf = function indexOf(array, value) { | ||
export function getCutoffIndex(array, value) { | ||
for (var index = 0; index < array.length; index++) { | ||
if (array[index] === value) { | ||
return index; | ||
return index + 1; | ||
} | ||
} | ||
return -1; | ||
}; | ||
return 0; | ||
} | ||
/** | ||
@@ -350,16 +326,12 @@ * @function getNormalizedValue | ||
export var getNormalizedValue = function getNormalizedValue(value, sortedCache, passedTag) { | ||
export function getNormalizedValue(value, cache, keys, passedTag) { | ||
if (passedTag === void 0) { | ||
var type = typeof value; | ||
if (type === 'string') { | ||
return value; | ||
if (type === 'string' || PRIMITIVE_TAGS[type]) { | ||
return type + SEPARATOR + value; | ||
} | ||
if (PRIMITIVE_TAGS[type]) { | ||
return getPrefixedValue(type, value); | ||
} | ||
if (value === null) { | ||
return getPrefixedValue('null', value); | ||
return 'null' + SEPARATOR + value; | ||
} | ||
@@ -375,29 +347,19 @@ } | ||
if (tag === OBJECT_CLASS_TYPE_MAP.OBJECT) { | ||
if (~indexOf(sortedCache, value)) { | ||
return CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedObject(value, sortedCache); | ||
return getSortedObject(value); | ||
} | ||
if (TOSTRING_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.toString()); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.toString(); | ||
} | ||
if (ITERABLE_TAGS[tag]) { | ||
if (~indexOf(sortedCache, value)) { | ||
return CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedIterablePairs(value); | ||
return getSortedIterablePairs(value, cache, keys); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATE) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.getTime()); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.getTime(); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.ERROR) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.stack); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.stack; | ||
} | ||
@@ -410,27 +372,27 @@ | ||
if (UNPARSEABLE_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], 'NOT_ENUMERABLE'); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + 'NOT_ENUMERABLE'; | ||
} | ||
if (HTML_ELEMENT_REGEXP.test(tag) || SVG_ELEMENT_REGEXP.test(tag)) { | ||
return getPrefixedValue(tag.slice(8, -1), value.outerHTML); | ||
return tag.slice(8, -1) + SEPARATOR + value.outerHTML; | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DOCUMENTFRAGMENT) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedDocumentFragment(value)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedDocumentFragment(value); | ||
} | ||
if (TYPEDARRAY_TAGS[tag]) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], value.join(',')); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + value.join(','); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.ARRAYBUFFER) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value); | ||
} | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATAVIEW) { | ||
return getPrefixedValue(OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value.buffer)); | ||
return OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value.buffer); | ||
} | ||
return value; | ||
}; | ||
} | ||
/** | ||
@@ -446,7 +408,45 @@ * @function replacer | ||
export var createReplacer = function createReplacer(sortedCache) { | ||
export function createReplacer(cache, keys) { | ||
if (cache === void 0) { | ||
cache = []; | ||
} | ||
if (keys === void 0) { | ||
keys = []; | ||
} | ||
return function (key, value) { | ||
return getNormalizedValue(value, sortedCache); | ||
if (typeof value === 'object') { | ||
if (cache.length) { | ||
var thisCutoff = getCutoffIndex(cache, this); | ||
if (thisCutoff === 0) { | ||
cache.push(this); | ||
} else { | ||
cache.splice(thisCutoff); | ||
keys.splice(thisCutoff); | ||
} | ||
keys.push(key); | ||
var valueCutoff = getCutoffIndex(cache, value); | ||
if (valueCutoff !== 0) { | ||
var ref = keys.slice(0, valueCutoff).join('.') || '.'; | ||
return "[~" + ref + "]"; | ||
} | ||
cache.push(value); | ||
} else { | ||
cache[0] = value; | ||
keys[0] = key; | ||
} | ||
} | ||
if (key && this[key] instanceof Date) { | ||
return getNormalizedValue(this[key], cache, keys, OBJECT_CLASS_TYPE_MAP.DATE, cache, keys); | ||
} | ||
return getNormalizedValue(value, cache, keys); | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -462,9 +462,14 @@ * @function stringify | ||
export function stringify(value) { | ||
export function stringify(value, cache, keys) { | ||
if (!value || typeof value !== 'object') { | ||
return getNormalizedValue(value); | ||
return getNormalizedValue(value, cache, keys); | ||
} | ||
var tag = toString.call(value); | ||
return tag === OBJECT_CLASS_TYPE_MAP.DATE || tag === OBJECT_CLASS_TYPE_MAP.REGEXP ? getNormalizedValue(value, void 0, tag) : fastStringify(value, createReplacer([]), null, getCircularValue); | ||
if (tag === OBJECT_CLASS_TYPE_MAP.DATE || tag === OBJECT_CLASS_TYPE_MAP.REGEXP) { | ||
return getNormalizedValue(value, cache, keys, tag); | ||
} | ||
return JSON.stringify(value, createReplacer(cache, keys)); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = exports.hash = void 0; | ||
exports.hash = hash; | ||
exports.default = void 0; | ||
@@ -22,5 +23,5 @@ var _curriable = require("curriable"); | ||
*/ | ||
var hash = function hash(value) { | ||
function hash(value) { | ||
return (0, _utils.getIntegerHashValue)((0, _utils.stringify)(value)); | ||
}; | ||
} | ||
/** | ||
@@ -37,3 +38,2 @@ * @function hash.is | ||
exports.hash = hash; | ||
hash.is = (0, _curriable.curry)(function (object, otherObject) { | ||
@@ -40,0 +40,0 @@ return hash(object) === hash(otherObject); |
307
lib/utils.js
"use strict"; | ||
exports.__esModule = true; | ||
exports.getFunctionName = getFunctionName; | ||
exports.getIntegerHashValue = getIntegerHashValue; | ||
exports.getSortedEvent = getSortedEvent; | ||
exports.shouldSort = shouldSort; | ||
exports.shouldSortPair = shouldSortPair; | ||
exports.sort = sort; | ||
exports.getSortedIterablePairs = getSortedIterablePairs; | ||
exports.getSortedObject = getSortedObject; | ||
exports.getStringifiedArrayBufferFallback = getStringifiedArrayBufferFallback; | ||
exports.getStringifiedArrayBufferModern = getStringifiedArrayBufferModern; | ||
exports.getStringifiedArrayBufferNoSupport = getStringifiedArrayBufferNoSupport; | ||
exports.getStringifiedDocumentFragment = getStringifiedDocumentFragment; | ||
exports.getCutoffIndex = getCutoffIndex; | ||
exports.getNormalizedValue = getNormalizedValue; | ||
exports.createReplacer = createReplacer; | ||
exports.stringify = stringify; | ||
exports.createReplacer = exports.getNormalizedValue = exports.indexOf = exports.getStringifiedDocumentFragment = exports.getStringifiedArrayBuffer = exports.getStringifiedArrayBufferNoSupport = exports.getStringifiedArrayBufferModern = exports.getStringifiedArrayBufferFallback = exports.getSortedObject = exports.getSortedIterablePairs = exports.sort = exports.getPrefixedValue = exports.shouldSortPair = exports.shouldSort = exports.getSortedEvent = exports.getIntegerHashValue = exports.getCircularValue = exports.getFunctionName = void 0; | ||
exports.getStringifiedArrayBuffer = void 0; | ||
var _fastStringify = _interopRequireDefault(require("fast-stringify")); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// external dependencies | ||
// constants | ||
var SEPARATOR = '|'; | ||
var charCodeAt = String.prototype.charCodeAt; | ||
@@ -28,21 +40,6 @@ var toString = Object.prototype.toString; | ||
var getFunctionName = function getFunctionName(fn) { | ||
function getFunctionName(fn) { | ||
return fn.name || (fn.toString().match(/^\s*function\s*([^\(]*)/i) || [])[1] || 'anonymous'; | ||
}; | ||
} | ||
/** | ||
* @function getCircularValue | ||
* | ||
* @description | ||
* get the value used when circular references are found | ||
* | ||
* @returns {string} the value for stringification | ||
*/ | ||
exports.getFunctionName = getFunctionName; | ||
var getCircularValue = function getCircularValue() { | ||
return _constants.CIRCULAR_VALUE; | ||
}; | ||
/** | ||
* @function getIntegerHashValue | ||
@@ -60,5 +57,3 @@ * | ||
exports.getCircularValue = getCircularValue; | ||
var getIntegerHashValue = function getIntegerHashValue(string) { | ||
function getIntegerHashValue(string) { | ||
var index = string.length, | ||
@@ -76,3 +71,3 @@ hashA = 5381, | ||
return (hashA >>> 0) * 4096 + (hashB >>> 0); | ||
}; | ||
} | ||
/** | ||
@@ -99,30 +94,17 @@ * @function getSortedEvent | ||
exports.getIntegerHashValue = getIntegerHashValue; | ||
var getSortedEvent = function getSortedEvent(_ref) { | ||
var bubbles = _ref.bubbles, | ||
cancelBubble = _ref.cancelBubble, | ||
cancelable = _ref.cancelable, | ||
composed = _ref.composed, | ||
currentTarget = _ref.currentTarget, | ||
defaultPrevented = _ref.defaultPrevented, | ||
eventPhase = _ref.eventPhase, | ||
isTrusted = _ref.isTrusted, | ||
returnValue = _ref.returnValue, | ||
target = _ref.target, | ||
type = _ref.type; | ||
function getSortedEvent(event) { | ||
return { | ||
bubbles: bubbles, | ||
cancelBubble: cancelBubble, | ||
cancelable: cancelable, | ||
composed: composed, | ||
currentTarget: currentTarget, | ||
defaultPrevented: defaultPrevented, | ||
eventPhase: eventPhase, | ||
isTrusted: isTrusted, | ||
returnValue: returnValue, | ||
target: target, | ||
type: type | ||
bubbles: event.bubbles, | ||
cancelBubble: event.cancelBubble, | ||
cancelable: event.cancelable, | ||
composed: event.composed, | ||
currentTarget: event.currentTarget, | ||
defaultPrevented: event.defaultPrevented, | ||
eventPhase: event.eventPhase, | ||
isTrusted: event.isTrusted, | ||
returnValue: event.returnValue, | ||
target: event.target, | ||
type: event.type | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -140,7 +122,5 @@ * @function shouldSort | ||
exports.getSortedEvent = getSortedEvent; | ||
var shouldSort = function shouldSort(valueA, valueB) { | ||
function shouldSort(valueA, valueB) { | ||
return valueA > valueB; | ||
}; | ||
} | ||
/** | ||
@@ -158,25 +138,6 @@ * @function shouldSortPair | ||
exports.shouldSort = shouldSort; | ||
var shouldSortPair = function shouldSortPair(pairA, pairB) { | ||
function shouldSortPair(pairA, pairB) { | ||
return shouldSort(pairA[0], pairB[0]); | ||
}; | ||
} | ||
/** | ||
* @function getPrefixedValue | ||
* | ||
* @description | ||
* get the value prefixed by the tag | ||
* | ||
* @param {string} tag the object tag | ||
* @param {any} value the value to stringify | ||
* @returns {string} the prefixed stringified value | ||
*/ | ||
exports.shouldSortPair = shouldSortPair; | ||
var getPrefixedValue = function getPrefixedValue(tag, value) { | ||
return tag + "|" + value; | ||
}; | ||
/** | ||
* @function sort | ||
@@ -193,5 +154,3 @@ * | ||
exports.getPrefixedValue = getPrefixedValue; | ||
var sort = function sort(array, fn) { | ||
function sort(array, fn) { | ||
var subIndex, value; | ||
@@ -210,3 +169,3 @@ | ||
return array; | ||
}; | ||
} | ||
/** | ||
@@ -223,22 +182,32 @@ * @function getIterablePairs | ||
exports.sort = sort; | ||
var getSortedIterablePairs = function getSortedIterablePairs(iterable) { | ||
function getSortedIterablePairs(iterable, cache, keys) { | ||
var isMap = typeof iterable.get === 'function'; | ||
var pairs = []; | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push(isMap ? [stringify(key), stringify(value)] : [stringify(value)]); | ||
}); | ||
if (isMap) { | ||
iterable.forEach(function (value, key) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(key, cache, keys), stringify(value, cache, keys)]); | ||
}); | ||
} else { | ||
iterable.forEach(function (value) { | ||
// eslint-disable-next-line no-use-before-define | ||
pairs.push([stringify(value, cache, keys)]); | ||
}); | ||
} | ||
sort(pairs, shouldSortPair); | ||
var finalPairs = new Array(iterable.size); | ||
var length = pairs.length; | ||
var lastIndex = length - 1; | ||
var _final = '['; | ||
var pair; | ||
for (var index = 0; index < iterable.size; index++) { | ||
for (var index = 0; index < length; index++) { | ||
pair = pairs[index]; | ||
finalPairs[index] = isMap ? "[" + pair[0] + "," + pair[1] + "]" : pair[0]; | ||
_final += isMap ? '[' + pair[0] + ',' + pair[1] + ']' : pair[0]; | ||
_final += index === lastIndex ? ']' : ','; | ||
} | ||
return getPrefixedValue(getFunctionName(iterable.constructor), "[" + finalPairs.join(',') + "]"); | ||
}; | ||
return getFunctionName(iterable.constructor) + SEPARATOR + _final; | ||
} | ||
/** | ||
@@ -255,5 +224,3 @@ * @function getSortedObject | ||
exports.getSortedIterablePairs = getSortedIterablePairs; | ||
var getSortedObject = function getSortedObject(object) { | ||
function getSortedObject(object) { | ||
var objectKeys = sort(keys(object), shouldSort); | ||
@@ -269,3 +236,3 @@ var newObject = {}; | ||
return newObject; | ||
}; | ||
} | ||
/** | ||
@@ -282,7 +249,5 @@ * @function getStringifiedArrayBufferFallback | ||
exports.getSortedObject = getSortedObject; | ||
var getStringifiedArrayBufferFallback = function getStringifiedArrayBufferFallback(buffer) { | ||
function getStringifiedArrayBufferFallback(buffer) { | ||
return String.fromCharCode.apply(null, new Uint16Array(buffer)); | ||
}; | ||
} | ||
/** | ||
@@ -299,7 +264,5 @@ * @function getStringifiedArrayBufferModern | ||
exports.getStringifiedArrayBufferFallback = getStringifiedArrayBufferFallback; | ||
var getStringifiedArrayBufferModern = function getStringifiedArrayBufferModern(buffer) { | ||
function getStringifiedArrayBufferModern(buffer) { | ||
return Buffer.from(buffer).toString('utf8'); | ||
}; | ||
} | ||
/** | ||
@@ -315,7 +278,5 @@ * @function getStringifiedArrayBufferNoSupport | ||
exports.getStringifiedArrayBufferModern = getStringifiedArrayBufferModern; | ||
var getStringifiedArrayBufferNoSupport = function getStringifiedArrayBufferNoSupport() { | ||
function getStringifiedArrayBufferNoSupport() { | ||
return ''; | ||
}; | ||
} | ||
/** | ||
@@ -332,4 +293,2 @@ * @function getStringifiedArrayBuffer | ||
exports.getStringifiedArrayBufferNoSupport = getStringifiedArrayBufferNoSupport; | ||
var getStringifiedArrayBuffer = function () { | ||
@@ -359,3 +318,3 @@ if (_constants.HAS_BUFFER_FROM_SUPPORT) { | ||
var getStringifiedDocumentFragment = function getStringifiedDocumentFragment(fragment) { | ||
function getStringifiedDocumentFragment(fragment) { | ||
var children = fragment.children; | ||
@@ -369,26 +328,25 @@ var innerHTML = ''; | ||
return innerHTML; | ||
}; | ||
} | ||
/** | ||
* @function indexOf | ||
* @function getCutoffIndex | ||
* | ||
* @description | ||
* get the index of the value in the array (faster than native indexOf) | ||
* get the index after that of the value match in the array (faster than | ||
* native indexOf) to determine the cutoff index for the `splice()` call. | ||
* | ||
* @param {Array<any>} array the array to get the index of the value at | ||
* @param {any} value the value to match | ||
* @returns {number} the index of the value in array | ||
* @returns {number} the index after the value match in the array | ||
*/ | ||
exports.getStringifiedDocumentFragment = getStringifiedDocumentFragment; | ||
var indexOf = function indexOf(array, value) { | ||
function getCutoffIndex(array, value) { | ||
for (var index = 0; index < array.length; index++) { | ||
if (array[index] === value) { | ||
return index; | ||
return index + 1; | ||
} | ||
} | ||
return -1; | ||
}; | ||
return 0; | ||
} | ||
/** | ||
@@ -407,18 +365,12 @@ * @function getNormalizedValue | ||
exports.indexOf = indexOf; | ||
var getNormalizedValue = function getNormalizedValue(value, sortedCache, passedTag) { | ||
function getNormalizedValue(value, cache, keys, passedTag) { | ||
if (passedTag === void 0) { | ||
var type = typeof value; | ||
if (type === 'string') { | ||
return value; | ||
if (type === 'string' || _constants.PRIMITIVE_TAGS[type]) { | ||
return type + SEPARATOR + value; | ||
} | ||
if (_constants.PRIMITIVE_TAGS[type]) { | ||
return getPrefixedValue(type, value); | ||
} | ||
if (value === null) { | ||
return getPrefixedValue('null', value); | ||
return 'null' + SEPARATOR + value; | ||
} | ||
@@ -434,29 +386,19 @@ } | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.OBJECT) { | ||
if (~indexOf(sortedCache, value)) { | ||
return _constants.CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedObject(value, sortedCache); | ||
return getSortedObject(value); | ||
} | ||
if (_constants.TOSTRING_TAGS[tag]) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], value.toString()); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + value.toString(); | ||
} | ||
if (_constants.ITERABLE_TAGS[tag]) { | ||
if (~indexOf(sortedCache, value)) { | ||
return _constants.CIRCULAR_VALUE; | ||
} | ||
sortedCache.push(value); | ||
return getSortedIterablePairs(value); | ||
return getSortedIterablePairs(value, cache, keys); | ||
} | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.DATE) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], value.getTime()); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + value.getTime(); | ||
} | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.ERROR) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], value.stack); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + value.stack; | ||
} | ||
@@ -469,27 +411,27 @@ | ||
if (_constants.UNPARSEABLE_TAGS[tag]) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], 'NOT_ENUMERABLE'); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + 'NOT_ENUMERABLE'; | ||
} | ||
if (_constants.HTML_ELEMENT_REGEXP.test(tag) || _constants.SVG_ELEMENT_REGEXP.test(tag)) { | ||
return getPrefixedValue(tag.slice(8, -1), value.outerHTML); | ||
return tag.slice(8, -1) + SEPARATOR + value.outerHTML; | ||
} | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.DOCUMENTFRAGMENT) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], getStringifiedDocumentFragment(value)); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedDocumentFragment(value); | ||
} | ||
if (_constants.TYPEDARRAY_TAGS[tag]) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], value.join(',')); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + value.join(','); | ||
} | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.ARRAYBUFFER) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value)); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value); | ||
} | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.DATAVIEW) { | ||
return getPrefixedValue(_constants.OBJECT_CLASS_MAP[tag], getStringifiedArrayBuffer(value.buffer)); | ||
return _constants.OBJECT_CLASS_MAP[tag] + SEPARATOR + getStringifiedArrayBuffer(value.buffer); | ||
} | ||
return value; | ||
}; | ||
} | ||
/** | ||
@@ -506,9 +448,45 @@ * @function replacer | ||
exports.getNormalizedValue = getNormalizedValue; | ||
function createReplacer(cache, keys) { | ||
if (cache === void 0) { | ||
cache = []; | ||
} | ||
var createReplacer = function createReplacer(sortedCache) { | ||
if (keys === void 0) { | ||
keys = []; | ||
} | ||
return function (key, value) { | ||
return getNormalizedValue(value, sortedCache); | ||
if (typeof value === 'object') { | ||
if (cache.length) { | ||
var thisCutoff = getCutoffIndex(cache, this); | ||
if (thisCutoff === 0) { | ||
cache.push(this); | ||
} else { | ||
cache.splice(thisCutoff); | ||
keys.splice(thisCutoff); | ||
} | ||
keys.push(key); | ||
var valueCutoff = getCutoffIndex(cache, value); | ||
if (valueCutoff !== 0) { | ||
var ref = keys.slice(0, valueCutoff).join('.') || '.'; | ||
return "[~" + ref + "]"; | ||
} | ||
cache.push(value); | ||
} else { | ||
cache[0] = value; | ||
keys[0] = key; | ||
} | ||
} | ||
if (key && this[key] instanceof Date) { | ||
return getNormalizedValue(this[key], cache, keys, _constants.OBJECT_CLASS_TYPE_MAP.DATE, cache, keys); | ||
} | ||
return getNormalizedValue(value, cache, keys); | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -525,11 +503,14 @@ * @function stringify | ||
exports.createReplacer = createReplacer; | ||
function stringify(value) { | ||
function stringify(value, cache, keys) { | ||
if (!value || typeof value !== 'object') { | ||
return getNormalizedValue(value); | ||
return getNormalizedValue(value, cache, keys); | ||
} | ||
var tag = toString.call(value); | ||
return tag === _constants.OBJECT_CLASS_TYPE_MAP.DATE || tag === _constants.OBJECT_CLASS_TYPE_MAP.REGEXP ? getNormalizedValue(value, void 0, tag) : (0, _fastStringify.default)(value, createReplacer([]), null, getCircularValue); | ||
if (tag === _constants.OBJECT_CLASS_TYPE_MAP.DATE || tag === _constants.OBJECT_CLASS_TYPE_MAP.REGEXP) { | ||
return getNormalizedValue(value, cache, keys, tag); | ||
} | ||
return JSON.stringify(value, createReplacer(cache, keys)); | ||
} |
@@ -28,11 +28,12 @@ { | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.2.2", | ||
"@babel/plugin-proposal-class-properties": "^7.2.3", | ||
"@babel/plugin-transform-runtime": "^7.2.0", | ||
"@babel/polyfill": "^7.2.5", | ||
"@babel/preset-env": "^7.2.3", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/register": "^7.0.0", | ||
"@babel/runtime": "^7.2.0", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.8.4", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-runtime": "^7.8.3", | ||
"@babel/polyfill": "^7.8.3", | ||
"@babel/preset-env": "^7.8.4", | ||
"@babel/preset-react": "^7.8.3", | ||
"@babel/register": "^7.8.3", | ||
"@babel/runtime": "^7.8.4", | ||
"@rollup/plugin-node-resolve": "^7.1.1", | ||
"ava": "^1.0.1", | ||
@@ -42,3 +43,3 @@ "babel-eslint": "^10.0.1", | ||
"benchmark": "^2.1.4", | ||
"browser-env": "^3.2.5", | ||
"browser-env": "^3.3.0", | ||
"eslint": "^5.12.0", | ||
@@ -52,18 +53,17 @@ "eslint-config-rapid7": "^3.1.0", | ||
"in-publish": "2.0.0", | ||
"node-object-hash": "^1.4.1", | ||
"nyc": "^13.1.0", | ||
"object-hash": "^1.3.1", | ||
"node-object-hash": "^2.0.0", | ||
"nyc": "^15.0.0", | ||
"object-hash": "^2.0.1", | ||
"optimize-js-plugin": "^0.0.4", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.0.2", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"rimraf": "^3.0.1", | ||
"rollup": "^1.31.0", | ||
"rollup-plugin-babel": "^4.2.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"sinon": "7.2.2", | ||
"uuid": "^3.3.2", | ||
"webpack": "^4.28.3", | ||
"webpack-cli": "^3.2.0", | ||
"webpack-dev-server": "3.1.14" | ||
"rollup-plugin-terser": "^5.2.0", | ||
"sinon": "8.1.1", | ||
"uuid": "^3.4.0", | ||
"webpack": "^4.41.5", | ||
"webpack-cli": "^3.3.10", | ||
"webpack-dev-server": "3.10.2" | ||
}, | ||
@@ -117,8 +117,6 @@ "homepage": "https://github.com/planttheidea/hash-it#readme", | ||
}, | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"dependencies": { | ||
"curriable": "^1.1.0", | ||
"fast-stringify": "^1.1.1", | ||
"json-prune": "^1.1.0" | ||
"curriable": "^1.1.0" | ||
} | ||
} |
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
1
117074
1739
- Removedfast-stringify@^1.1.1
- Removedjson-prune@^1.1.0
- Removedfast-stringify@1.1.2(transitive)
- Removedjson-prune@1.1.0(transitive)