Repository URL to install this package:
|
Version:
1.2.8 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toIdentityHash = toIdentityHash;
exports.default = void 0;
var _index = require("../chain-able/index.js");
var _IDENTIFIER_REGISTRY = require("./IDENTIFIER_REGISTRY");
var _uuid = require("./uuid");
/**
* @example for why `id` in part of a variable name sucks
* @see https://bitbucket.org/skava-admin/skreact/commits/fbdc931637a385f99a802f9cce5ef3c7c8953632?at=dev
*/
/**
* different than the other to identifiers -.-
* value-equals-identity
* one day, easy to wicked optimize this => trie
*/
function toIdentityHash(small, ignoreReference = false) {
// `a === b`
if (ignoreReference === false && _IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.has(small)) {
return _IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.get(small);
}
const string = (0, _index.stringify)(small);
if (_IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.has(string)) {
return _IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.get(string);
}
const unique = (0, _uuid.uuid)() + string;
const hashstring = '__' + (0, _index.fliphash)(unique);
_IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.set(string, hashstring);
_IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.set(small, hashstring);
return hashstring;
} // no reference check
// const one = toIdentityHash({eh: 1}, true)
// const two = toIdentityHash({eh: 1}, true)
// one === two
// // // value ??
// // value
// const one = toIdentityHash({eh: 1, no: 1})
// const two = toIdentityHash({eh: 1})
// one === two
// one === 'en10'
// // reference
// const obj = {eh: 1}
// const one = toIdentityHash(obj)
// const two = toIdentityHash(obj)
// one === two
var _default = toIdentityHash;
exports.default = _default;