Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/identifier / dist / stateTreeIdentifier.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chain_1 = require("chain");
const IDENTIFIER_REGISTRY_1 = require("./IDENTIFIER_REGISTRY");
const uuid_1 = require("./uuid");
// eslint-disable-next-line
function concatIdentifier(obj) {
    let identifier = '';
    if (obj.userid) {
        identifier += obj.userid;
    }
    else if (obj.orderid) {
        identifier += obj.orderid;
    }
    else if (obj.identifier) {
        identifier += obj.identifier;
    }
    else if (obj.cardid) {
        identifier += obj.cardid;
    }
    else if (obj.itemid) {
        identifier += obj.itemid;
    }
    else if (obj.skuid) {
        identifier += obj.skuid;
    }
    else if (obj.addressid) {
        identifier += obj.addressid;
    }
    else if (obj.id) {
        identifier += obj.id;
    }
    return identifier;
}
// eslint-disable-next-line
function stateTreeIdentifier(obj = {}, old) {
    if (obj.__identifier) {
        return obj.__identifier;
    }
    const identifier = concatIdentifier(old || obj);
    if (identifier !== '') {
        return identifier;
    }
    if (IDENTIFIER_REGISTRY_1.IDENTIFIER_STRING_REGISTRY.has(obj)) {
        return IDENTIFIER_REGISTRY_1.IDENTIFIER_STRING_REGISTRY.get(obj);
    }
    const string = chain_1.stringify(obj);
    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_1.fliphash(unique);
    IDENTIFIER_REGISTRY_1.IDENTIFIER_REFERENCE_REGISTRY.set(string, hashstring);
    IDENTIFIER_REGISTRY_1.IDENTIFIER_STRING_REGISTRY.set(obj, hashstring);
    return hashstring;
}
exports.stateTreeIdentifier = stateTreeIdentifier;
exports.default = stateTreeIdentifier;
//# sourceMappingURL=stateTreeIdentifier.js.map