{"_id":"hub","_rev":"25-e550f04b69edf3acf1ad0bd77b7e49be","name":"hub","dist-tags":{"latest":"6.1.3"},"versions":{"5.0.0":{"name":"hub","version":"5.0.0","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"hub@5.0.0","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"51ec742bd503f5f5669a1ae8d46430b3bb7c177d","tarball":"https://registry.npmjs.org/hub/-/hub-5.0.0.tgz","integrity":"sha512-9147GgJ0CJOXr5iqNzPSW8d6i5AFnbcahqv6HpTkIxIZ4LdmdoJEgf8WKE7TMVkKbCSx1EAUMGDzeO+OaoGnTg==","signatures":[{"sig":"MEUCIGb2RFFlKaz2hpxRPSkQZdEE+7vAHJrlid3DpVrk8/udAiEAnLQeBpM0bZakoQyf1E+VR4zoO/BMDBf5zQuo7uuh63A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"51ec742bd503f5f5669a1ae8d46430b3bb7c177d","engines":{"node":">= 0.6.0"},"gitHead":"bbd59eb27654a41fda8feb1d003cce91625a050b","scripts":{},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.3.9","description":"Service locator","_nodeVersion":"5.0.0","dependencies":{"async":"1.5.0","bluebird":"3.0.5"},"directories":{}},"5.0.1":{"name":"hub","version":"5.0.1","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"hub@5.0.1","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"9383ba90f326b03ab15e8b2569e91a3bc97554dd","tarball":"https://registry.npmjs.org/hub/-/hub-5.0.1.tgz","integrity":"sha512-zIegpf3g2Y2j2J1tknSWLYi0hqUI/CjJAO8Z7t5vJgefGRwzm0tLDN5VIFPnS6F7ID7koV44Dt3YAVabqD9Q0g==","signatures":[{"sig":"MEUCIQDth9+YL8JgJIUNLhBB3NqG7t4BGEkomV4tZMTfLbd0QwIgEVb140IcIm4xkqdTegXqnB7fC+mjaCjFIaynquMuLUc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"9383ba90f326b03ab15e8b2569e91a3bc97554dd","engines":{"node":">= 0.6.0"},"gitHead":"546d09faf13090114b0fd2e1981b4ca32f7ef666","scripts":{},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.3.9","description":"Service locator","_nodeVersion":"5.0.0","dependencies":{"async":"1.5.0","bluebird":"3.0.5"},"directories":{}},"5.0.2":{"name":"hub","version":"5.0.2","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"hub@5.0.2","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"a6ac6d64a7d3ffe96f81c3219d349a8e3a4c0fe3","tarball":"https://registry.npmjs.org/hub/-/hub-5.0.2.tgz","integrity":"sha512-hluIu0hTpaMYhxKb6tFFbspfXCOF5ULNL3ZaHdJ7m/PgqL1y8pQd1++mVVnLBghve/HKMwD1J0u8HreHbOMMKg==","signatures":[{"sig":"MEUCIBFR2zq/qFEJ6kj0Jr5CS05MXeKWbrmE0nye8KpLH1nVAiEAjQbfZILFmfY4Hb7KGTSfCScsIZ0OnPKCuaG5GBBrTl4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"a6ac6d64a7d3ffe96f81c3219d349a8e3a4c0fe3","engines":{"node":">= 0.6.0"},"gitHead":"0467fa1fc21c4abaf03717b2a3bf21aeb0e96d0f","scripts":{},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.3.9","description":"Service locator","_nodeVersion":"5.0.0","dependencies":{"async":"1.5.0","bluebird":"3.0.5"},"directories":{}},"5.0.3":{"name":"hub","version":"5.0.3","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"_id":"hub@5.0.3","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"fb297d0857532c73248f73823d2dcf2fd1ab13ea","tarball":"https://registry.npmjs.org/hub/-/hub-5.0.3.tgz","integrity":"sha512-78anyKkd4cuLkSdhbjd64pFCPQT3QZe1dqaQUCkI9seHWMkB3ZmuJpFLx7WCxKORPNPRJbgGoZGUy044agC7cw==","signatures":[{"sig":"MEQCIELTj8GqDveSTSpG6fYLA/aV86V+9BWBi1u7mKSR0MJVAiAu4u4iGImr2DljkxKkH8bF+M9jYBxid3S9mT6uBaScHQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"fb297d0857532c73248f73823d2dcf2fd1ab13ea","engines":{"node":">= 0.6.0"},"gitHead":"140dbd41d3382c815753c7c23499c050550b4cc5","scripts":{},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.3.9","description":"Service locator","_nodeVersion":"5.0.0","dependencies":{"async":"1.5.0","bluebird":"3.0.5"},"directories":{}},"6.0.0":{"name":"hub","version":"6.0.0","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"license":"MIT","_id":"hub@6.0.0","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"9d5dc9a5d62a2af5018ee1017abbeda0a64fb8bc","tarball":"https://registry.npmjs.org/hub/-/hub-6.0.0.tgz","integrity":"sha512-WiPBAX4vP5dyfNX48P/UlIKyzS6alCUk8GVWBqvE1RsAMLs75yEGFv78ZjvCy1V1S27VsNfJi87t3pyx0gCJ0Q==","signatures":[{"sig":"MEUCIQCnYY/Swdq2DGs1N8d0U2WOsNmHFJC/I7VdgT8SHvJU4QIgD0piM9qTZKaLkWT0usaeXP19bgKUp5Rz0ui2fVweMCA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"9d5dc9a5d62a2af5018ee1017abbeda0a64fb8bc","engines":{"node":">= 0.6.0"},"gitHead":"303e8caf3f9222e8f1b9b1c4aa0dc3a691e110d3","scripts":{"test":"mocha"},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.7.3","description":"Service locator","_nodeVersion":"5.8.0","dependencies":{"bluebird":"^3.3.4"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","chai-as-promised":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/hub-6.0.0.tgz_1457794060520_0.0337235985789448","host":"packages-13-west.internal.npmjs.com"},"directories":{}},"6.1.0":{"name":"hub","version":"6.1.0","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"license":"MIT","_id":"hub@6.1.0","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"626c166c8b4657b05cf99b8fa06bf4f50f6ead1e","tarball":"https://registry.npmjs.org/hub/-/hub-6.1.0.tgz","integrity":"sha512-8utTrGReOL68cLFjRJRWP+SrlAjOOcsIgylCaPhdukI58ZzqqJN+3ue9b78+O+ApxegFtwSdlumr55/R1p3E+A==","signatures":[{"sig":"MEUCIQCoOP3ds3YK+LUkmkhAqsHDhOrZvJeeHWA5xl94WyEO4QIgKYX7MZv9TsQF7yjxdNf5mzD4OnC9STg3w8gAb5weHzc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"626c166c8b4657b05cf99b8fa06bf4f50f6ead1e","engines":{"node":">= 0.6.0"},"gitHead":"dc45d07e9adb63933e51c8771660cde183245bb0","scripts":{"test":"mocha"},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.8.3","description":"Service locator","_nodeVersion":"5.10.1","dependencies":{"bluebird":"^3.3.4"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","chai-as-promised":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/hub-6.1.0.tgz_1460834360760_0.6321946543175727","host":"packages-16-east.internal.npmjs.com"},"directories":{}},"6.1.1":{"name":"hub","version":"6.1.1","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"license":"MIT","_id":"hub@6.1.1","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"6a459330bd9d935d60eb7bca7eb584631c31bdcb","tarball":"https://registry.npmjs.org/hub/-/hub-6.1.1.tgz","integrity":"sha512-y5EZQwXgzGkhIJ8+7jgtZKEFLYq+IxnNHxZBs1QSQVeI95I1ryljO50WLVmj7Vd8Ye/rdtJi/tZWkI99UQSM6A==","signatures":[{"sig":"MEUCIQDytRS+JWppS78iUkneunVRX3H8TBf1IZheGKgzX+cEOwIgbrDUTOYQmoM6/yvBDk4iT4eZkt3uZ2X+Gc4ApNZ4P6Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"6a459330bd9d935d60eb7bca7eb584631c31bdcb","engines":{"node":">= 0.6.0"},"gitHead":"52b288ffdbf8d660b0ac3d935e6dffeccfd1c30a","scripts":{"test":"mocha"},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.8.3","description":"Service locator","_nodeVersion":"5.10.1","dependencies":{"bluebird":"^3.3.4"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","chai-as-promised":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/hub-6.1.1.tgz_1460834998790_0.17243501939810812","host":"packages-12-west.internal.npmjs.com"},"directories":{}},"6.1.2":{"name":"hub","version":"6.1.2","keywords":["hub","container","dependency","service locator"],"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"license":"MIT","_id":"hub@6.1.2","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"homepage":"https://github.com/baryshev/hub#readme","bugs":{"url":"https://github.com/baryshev/hub/issues"},"dist":{"shasum":"b87314f90b84a8e191040ae25100cad39cb89b2f","tarball":"https://registry.npmjs.org/hub/-/hub-6.1.2.tgz","integrity":"sha512-X0uoTIuQUs/rr1o1/07hfshg64j3mdDUQSybeU9eK1gbZfZdk70ALAQYo2tMIqoDhYRdEeU7cadN0px66jrlcQ==","signatures":[{"sig":"MEYCIQC9gHb/tQ/ZSJQxCQKrdQUkPcrCQemSW9jTgPOYQJfcvQIhAK64ZCzJ9sIQHTWiZ0wh+uB5MEAUk63Mlg9JA/PcFmNs","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"index","_from":".","_shasum":"b87314f90b84a8e191040ae25100cad39cb89b2f","engines":{"node":">= 0.6.0"},"gitHead":"b16ac7efa8daa19a6bb82a8a6aad76ad54a39148","scripts":{"test":"mocha"},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"repository":{"url":"git://github.com/baryshev/hub.git","type":"git"},"_npmVersion":"3.8.3","description":"Service locator","_nodeVersion":"5.10.1","dependencies":{"bluebird":"^3.3.4"},"devDependencies":{"chai":"^3.5.0","mocha":"^2.4.5","chai-as-promised":"^5.2.0"},"_npmOperationalInternal":{"tmp":"tmp/hub-6.1.2.tgz_1460835315449_0.31636289483867586","host":"packages-16-east.internal.npmjs.com"},"directories":{}},"6.1.3":{"name":"hub","description":"Service locator","version":"6.1.3","author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"dependencies":{"bluebird":"^3.3.4"},"keywords":["hub","container","dependency","service locator"],"repository":{"type":"git","url":"git://github.com/baryshev/hub.git"},"scripts":{"test":"mocha"},"main":"index","engines":{"node":">= 0.6.0"},"license":"MIT","devDependencies":{"chai":"^3.5.0","chai-as-promised":"^5.2.0","mocha":"^2.4.5"},"_id":"hub@6.1.3","gitHead":"b31f7bff8afe6678ed2f36fb646e87e6e0b3a02b","bugs":{"url":"https://github.com/baryshev/hub/issues"},"homepage":"https://github.com/baryshev/hub#readme","_nodeVersion":"22.5.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-UZfND2V7WHrgjd3UrfXlYJJtDz/1FPJ+ji/vBdpw8r3SJOs/1vxfm/ADCZ9X/OjmW/aAbJqJOF5UITcdBin9kg==","shasum":"2678fe2b671d5fc935159ca81920169cafb9844a","tarball":"https://registry.npmjs.org/hub/-/hub-6.1.3.tgz","fileCount":5,"unpackedSize":11596,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIATONVMQ5edIjSihXKGuqQJpZTb5lCDMUMWah1WjfCB3AiBw7tuBB1M+W4fpvlRYNtEHIaXtyL5K62BQPCXY002LtA=="}]},"_npmUser":{"name":"baryshev","email":"vadimbaryshev@gmail.com"},"directories":{},"maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hub_6.1.3_1728538478583_0.13145983249290394"},"_hasShrinkwrap":false}},"time":{"created":"2012-01-20T07:05:16.637Z","modified":"2024-10-10T05:34:38.976Z","1.0.0":"2012-01-20T07:05:19.565Z","2.0.0":"2012-07-01T17:33:07.989Z","2.0.1":"2012-07-01T23:05:26.960Z","3.0.0":"2015-11-06T14:07:48.783Z","4.0.0":"2015-11-06T14:15:38.719Z","5.0.0":"2015-11-06T15:15:29.426Z","5.0.1":"2015-11-08T01:40:39.199Z","5.0.2":"2015-11-08T01:48:03.766Z","5.0.3":"2015-11-13T16:57:29.224Z","6.0.0":"2016-03-12T14:47:43.067Z","6.1.0":"2016-04-16T19:19:21.992Z","6.1.1":"2016-04-16T19:30:01.204Z","6.1.2":"2016-04-16T19:35:16.487Z","6.1.3":"2024-10-10T05:34:38.811Z"},"bugs":{"url":"https://github.com/baryshev/hub/issues"},"author":{"name":"Vadim M. Baryshev","email":"vadimbaryshev@gmail.com"},"license":"MIT","homepage":"https://github.com/baryshev/hub#readme","keywords":["hub","container","dependency","service locator"],"repository":{"type":"git","url":"git://github.com/baryshev/hub.git"},"description":"Service locator","maintainers":[{"name":"baryshev","email":"vadimbaryshev@gmail.com"}],"readme":"# Hub - A Node.js Service Locator Library\n\n`hub` is a lightweight service locator library for Node.js. It allows you to register, retrieve, and manage services, making dependency injection easier and decoupling your modules. This library supports asynchronous service initialization, de-initialization, and lazy-loading of services using promises.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Creating Hub Instance](#creating-hub-instance)\n  - [Registering Services](#registering-services)\n  - [Retrieving Services](#retrieving-services)\n  - [Destroying Services](#destroying-services)\n  - [Unregistering Services](#unregistering-services)\n  - [Checking Service Status](#checking-service-status)\n- [API](#api)\n  - [`register(name, constructor, destructor)`](#register)\n  - [`get(name, standalone)`](#get)\n  - [`destroy(name, service)`](#destroy)\n  - [`unregister(name)`](#unregister)\n  - [`isRegistered(name)`](#isregistered)\n  - [`getRegistered()`](#getregistered)\n  - [`isInitiated(name)`](#isinitiated)\n  - [`getInitiated()`](#getinitiated)\n  - [`standalone()`](#standalone)\n\n## Installation\n\nInstall via npm:\n\n```bash\nnpm install hub\n```\n\n## Usage\n\n### Creating Hub Instance\n\nTo initialize the service locator in your application, create a standalone instance of `hub` in the main entry point of your application:\n\n```js\nconst hub = require('hub').standalone();\n```\n\nIn all other files across your application, you can simply include `hub` using:\n\n```js\nconst hub = require('hub');\n```\n\nThis ensures that all parts of your application share the same `hub` instance.\n\n### Registering Services\n\nYou can register a service with the `register()` method. A service constructor should return a promise that resolves to the service object, and an optional destructor can be provided for clean-up. Here's an example using `async/await`:\n\n```js\nconst hub = require('hub');\n\n// Register a service\nhub.register('logger', async () => {\n    return {\n        log: (message) => console.log(message),\n    };\n});\n```\n\n### Retrieving Services\n\nOnce a service is registered, you can retrieve it using the `get()` method. The service will be lazily initialized the first time it's accessed:\n\n```js\nconst logger = await hub.get('logger');\nlogger.log('Service Locator Initialized!');\n```\n\n### Destroying Services\n\nTo properly clean up resources, you can destroy a service by calling `destroy()`. This will execute the optional destructor provided during registration:\n\n```js\nawait hub.destroy('logger');\nconsole.log('Logger service destroyed');\n```\n\n### Unregistering Services\n\nIf needed, services can be unregistered to remove them from the service locator. This will not destroy an already initiated service:\n\n```js\nhub.unregister('logger');\n```\n\n### Checking Service Status\n\nYou can check if a service is registered or initiated:\n\n```js\nconsole.log(hub.isRegistered('logger'));  // true/false\nconsole.log(hub.isInitiated('logger'));   // true/false\n```\n\n## API\n\n### `register(name, constructor, destructor)`\n\nRegisters a service with a given name.\n\n- **name**: `String` - The name of the service.\n- **constructor**: `Function` - A function that returns a promise resolving to the service instance.\n- **destructor** (optional): `Function` - A function that returns a promise for cleaning up the service.\n\nReturns `true` if successful.\n\n### `get(name, standalone)`\n\nRetrieves the service instance by its name. If `standalone` is true, it will not cache the service and will always invoke the constructor.\n\n- **name**: `String | Array` - Name of the service (or array of names).\n- **standalone**: `Boolean` (optional) - If true, the service will not be cached.\n\nReturns a `Promise` that resolves to the service instance.\n\n### `destroy(name, service)`\n\nDestroys a service and calls the registered destructor (if provided).\n\n- **name**: `String | Array` - Name of the service or array of services.\n- **service** (optional): The service instance to destroy.\n\nReturns a `Promise`.\n\n### `unregister(name)`\n\nUnregisters a service by its name.\n\n- **name**: `String` - Name of the service.\n\nThrows an error if the service is not registered. Returns `true` if successful.\n\n### `isRegistered(name)`\n\nChecks if a service is registered.\n\n- **name**: `String` - Name of the service.\n\nReturns `true` if the service is registered, otherwise `false`.\n\n### `getRegistered()`\n\nRetrieves a list of all registered services.\n\nReturns an array of service names.\n\n### `isInitiated(name)`\n\nChecks if a service has been initiated.\n\n- **name**: `String` - Name of the service.\n\nReturns `true` if the service is initiated, otherwise `false`.\n\n### `getInitiated()`\n\nRetrieves a list of all initiated services.\n\nReturns an array of initiated service names.\n\n### `standalone()`\n\nReturns a new instance of the Hub that is not cached by the `require` system. Useful for creating isolated service locators.","readmeFilename":"README.md"}