Repository URL to install this package:
|
Version:
1.3.0 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chain_able_1 = require("chain-able");
const IDENTIFIER_REGISTRY_1 = require("./IDENTIFIER_REGISTRY");
const uuid_1 = 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_1.IDENTIFIER_STRING_REGISTRY.has(small)) {
return IDENTIFIER_REGISTRY_1.IDENTIFIER_STRING_REGISTRY.get(small);
}
const string = chain_able_1.stringify(small);
if (IDENTIFIER_REGISTRY_1.IDENTIFIER_REFERENCE_REGISTRY.has(string)) {
return IDENTIFIER_REGISTRY_1.IDENTIFIER_REFERENCE_REGISTRY.get(string);
}
const unique = uuid_1.uuid() + string;
const hashstring = '__' + chain_able_1.fliphash(unique);
IDENTIFIER_REGISTRY_1.IDENTIFIER_REFERENCE_REGISTRY.set(string, hashstring);
IDENTIFIER_REGISTRY_1.IDENTIFIER_STRING_REGISTRY.set(small, hashstring);
return hashstring;
}
exports.toIdentityHash = toIdentityHash;
exports.default = toIdentityHash;
//# sourceMappingURL=toIdentityHash.js.map