UNPKG

@clawject/di

Version:

<p align="center"> <a href="https://clawject.com/" target="_blank"><img src="https://clawject.com/img/logo.svg" align="center" alt="Clawject Logo" width="120" height="120" /></a> </p>

57 lines (56 loc) 1.67 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.Utils = void 0; const ObjectStorage_1 = require("./ObjectStorage"); class Utils { static async getResolvedConstructorParameters(constructorParameters) { if (!constructorParameters) { return []; } if (typeof constructorParameters === 'function') { return constructorParameters(); } return constructorParameters; } } exports.Utils = Utils; _a = Utils; Utils.createVersionedStorageOrGetIfExisted = (key, version, defaultValue) => { const storages = ObjectStorage_1.ObjectStorage.getOrSetIfNotPresent(key, new Map()); let storage = storages.get(version); if (!storage) { storage = defaultValue; storages.set(version, storage); } return storage; }; Utils.getConstructorFromInstance = (element) => { if (!element) { return null; } const objectPrototype = Object.getPrototypeOf(element); if (!objectPrototype) { return null; } return objectPrototype.constructor; }; Utils.isObject = (value) => { const type = typeof value; return value !== null && (type === 'object' || type === 'function'); }; Utils.isFunction = (value) => { const type = typeof value; return value !== null && (type === 'function'); }; Utils.capitalizeFirstLetter = (value) => value.charAt(0).toUpperCase() + value.slice(1); Utils.isPromise = (value) => { return value instanceof Promise; }; Utils.EMPTY_VALUE = Symbol(); Utils.getValueSafe = (map, key) => { if (!map.has(key)) { return _a.EMPTY_VALUE; } return map.get(key); };