Repository URL to install this package:
|
Version:
3.0.0 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable max-statements */
/* eslint-disable brace-style */
/* @lint ^ 1 is for tests, 1 is for readable long conditionals */
const exotic_1 = require("exotic");
// import { toComponentName, toIdentity } from 'view-container/deps'
const toComponentName_1 = __importDefault(require("./toComponentName"));
const uuid_1 = __importDefault(require("./uuid"));
let identityWeakmap = new WeakMap();
const IS_TEST = process.env.NODE_ENV === 'test';
/**
* @todo hashnumber here
* @todo id based on CLASS + INSTANCE
* @todo selectors ^
* @todo use this to also cache identifiers for things alternative from weakmap
*
* @param {Object | string | number} [optionalClassOrInstance=undefined]
* @param {string | *} [hash='']
* @return {String}
*/
function toIdentifier(instance, hash = '') {
if (exotic_1.isObj(instance) === false && exotic_1.isFunction(instance) === false) {
if (exotic_1.isString(instance) || exotic_1.isNumber(instance) || exotic_1.isBoolean(instance)) {
return instance;
}
else if (IS_TEST === true) {
return '@@uuid--test';
}
else {
return uuid_1.default();
}
}
else if (identityWeakmap.has(instance)) {
return identityWeakmap.get(instance);
}
else {
const hashedId = hash + toComponentName_1.default(instance);
if (IS_TEST === true) {
return '@@uuid--test--' + hashedId;
}
const id = hashedId + uuid_1.default();
identityWeakmap.set(instance, id);
return id;
}
}
exports.toIdentifier = toIdentifier;
exports.default = toIdentifier;
//# sourceMappingURL=toIdentifier.js.map