{"_id":"@brainstaff/injector","_rev":"5-7326015d879a3fd2967c5fc71bb383a1","name":"@brainstaff/injector","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@brainstaff/injector","version":"1.0.0","author":{"name":"Alexey Kornilov","email":"alexey.kornilov@kavolorn.ru"},"license":"MIT","_id":"@brainstaff/injector@1.0.0","maintainers":[{"name":"alexey.kornilov","email":"alexey.kornilov@kavolorn.ru"},{"name":"ilyaleb","email":"ilyaleb@gmail.com"},{"name":"markin.io","email":"markin.io210@gmail.com"},{"name":"yakut","email":"a.yakutskiy@gmail.com"}],"dist":{"shasum":"bf0f8b2e7d361d471ff21bb14cf132523e1092ba","tarball":"https://registry.npmjs.org/@brainstaff/injector/-/injector-1.0.0.tgz","fileCount":17,"integrity":"sha512-8ZmeX2hk6smAePYyv/byOYTNbNY6eiWyKjUYinQP2rrmH2ZweKWXyDXCJ4U08Yr+BFHSbXmusarDwQt2Ahomeg==","signatures":[{"sig":"MEYCIQCuU5psBSbljpe7C6l0AW9oWB7PTGj6FmtZDNqsS6rzYAIhAIN0aHNBJFrpmM8R6NU1GzS83HXXNhRWirGjaHI2rskp","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16150},"main":"dist/injector.js","scripts":{"test":"NODE_ENV=production babel ./tests --out-dir ./dist && mocha dist/tests","build":"NODE_ENV=production webpack --progress --hide-modules","clean":"rm -rf dist","watch":"NODE_ENV=development webpack --progress --hide-modules --watch"},"_npmUser":{"name":"alexey.kornilov","email":"alexey.kornilov@kavolorn.ru"},"repository":{"url":"https://github.com/brainstaff/js-injector","type":"git"},"description":"Dependency Injector for JavaScript projects.","directories":{},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2017 Alexey Kornilov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^3.2.0","eslint":"^3.15.0","webpack":"^2.3.1","babel-cli":"^6.24.1","babel-core":"^6.24.0","babel-loader":"^6.4.1","eslint-loader":"^1.7.0","babel-preset-env":"^1.2.2"},"_npmOperationalInternal":{"tmp":"tmp/injector_1.0.0_1531862820259_0.14132409019255565","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@brainstaff/injector","version":"2.0.0","author":{"name":"Alexey Kornilov","email":"alexey.kornilov@kavolorn.ru"},"license":"MIT","_id":"@brainstaff/injector@2.0.0","maintainers":[{"name":"alexey.kornilov","email":"alexey.kornilov@kavolorn.ru"},{"name":"yakut","email":"a.yakutskiy@gmail.com"},{"name":"markin.io","email":"markin.io210@gmail.com"},{"name":"ilyaleb","email":"ilyaleb@gmail.com"}],"dist":{"shasum":"9e9daa9dc5c5ad2b65929a551b23d536dfa4cb43","tarball":"https://registry.npmjs.org/@brainstaff/injector/-/injector-2.0.0.tgz","fileCount":9,"integrity":"sha512-IHLHP/1AU02RyzJ62UuJhkmpeJlN3ZfNg9xJ6Z88bPKZSwaQx0fvWHKZvQT9TNfg0UC+WrqFcr/4DaPDszQAUg==","signatures":[{"sig":"MEQCIDV4DkWxTFZIGEbP9Xd8iW21jy/EY35xDSnmW2NR0tbQAiAdUX7bvbYhyyEMcka2eqML5/VbY11GRD4kqz6y8mlIiA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16433,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffe31CRA9TVsSAnZWagAAQrIP/1kQ8Y73+BlKwpT7tStJ\n52s6JasavQStM5cGPeXUvmI8v2e77cfaylcZyHEe/14LSVHf2m5GaxyQ1z7X\nczJyf+ZxMVnFcMszk6jYtb9AJufqy1KA3O+JmFbPhlppCWjNHrnL/xFv02ms\n35SqpPherXWKurc9n/Hxd09SdvQrMLVKOc2fMS19lbU4XgiIUmjL2jj43sxF\nInR9iiXndF3F/cOCmitMVb331gE2CDL2kF8jbzN+M+cT/ED9xbWnty2Of/p8\nNk2za4nK47fqMmiz4h2zDW9713qX8AOucoLnq2Wx//hpCaPhv8f9eYf5Ck1s\nUpfG9x1Mn1W6i9LCQDd1MOFi75eLPmJyg1dN6pESD85LqoHZcH3bFW0jrkte\nxiQ1HYQtMFo3J88LcQrFWGdlwQstTbHTpDb81s5zt9Pprn6qxT6oFp2VFGTB\niz1PAloOBRumD1LGpfGbSmyCehCtUyDbpnxCk+XvdwcL1LRQhnFIzhRtGztH\nUE3CjNZFo1vpes86jQAccgsujlfifimftFF8OiXoDAzCsn1xeWgheFxgHw66\ncJ+EX08iT1ZRq5HNOeRnSSR3mracdgoIcheD8bWBf8arWyz7sEX23vSxczHu\n3jlzkae+OhemjQOEtlMgb8yJMs2dXJ8ecoLOYKQJd6tsB9/0CXVxIMCyGQRc\nZrGL\r\n=Ck8w\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/injector.js","module":"dist/injector.es.js","scripts":{"test":"mocha --require @babel/register tests/tests.js","build":"NODE_ENV=production rollup -c","clean":"rm -rf dist"},"_npmUser":{"name":"alexey.kornilov","email":"alexey.kornilov@kavolorn.ru"},"repository":{"url":"https://github.com/brainstaff/js-injector","type":"git"},"description":"Dependency Injector for JavaScript projects.","directories":{},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2017 Alexey Kornilov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"@babel/runtime":"^7.8.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^7.1.0","rollup":"^1.32.0","@babel/cli":"^7.8.4","@babel/core":"^7.8.6","@babel/register":"^7.8.6","@babel/preset-env":"^7.8.6","rollup-plugin-babel":"^4.3.3","rollup-plugin-eslint":"^7.0.0","rollup-plugin-terser":"^5.2.0","@babel/plugin-transform-runtime":"^7.8.3"},"_npmOperationalInternal":{"tmp":"tmp/injector_2.0.0_1602088437342_0.5863725943465017","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-07-17T21:27:00.221Z","modified":"2024-11-26T12:32:30.368Z","1.0.0":"2018-07-17T21:27:00.334Z","2.0.0":"2020-10-07T16:33:57.440Z"},"author":{"name":"Alexey Kornilov","email":"alexey.kornilov@kavolorn.ru"},"license":"MIT","repository":{"url":"https://github.com/brainstaff/js-injector","type":"git"},"description":"Dependency Injector for JavaScript projects.","maintainers":[{"email":"alexey.kornilov@kavolorn.ru","name":"alexey.kornilov"},{"email":"a.yakutskiy@gmail.com","name":"yakut"},{"email":"markin.io210@gmail.com","name":"markin.io"},{"email":"ilyaleb@gmail.com","name":"ilyaleb"},{"email":"victor.v.dombrovskiy@gmail.com","name":"victordobry"}],"readme":"# Injector\n\n[![npm version](https://img.shields.io/npm/v/@brainstaff/injector.svg?style=flat-square)](https://www.npmjs.com/package/@brainstaff/injector)\n[![license](https://img.shields.io/badge/licence-MIT-green.svg?style=flat-square)](https://github.com/brainstaff/js-injector/blob/master/LICENSE)\n\nThis is dependency injector for JavaScript with support for ES6/ES2015. It can \nbe applied in both node and browser environments.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n\t- [Constructor Registration](#constructor-registration)\n\t- [Object Registration](#object-registration)\n\t- [Dependency Injection](#dependency-injection)\n- [Changelog](#changelog)\n\n## Installation\n\nExecute this command in your environment. \n\n```\nnpm install @brainstaff/injector --save\n```\nor\n\n```\nyarn add @brainstaff/injector\n```\n\n<small>[Table of Contents](#table-of-contents)</small>\n\n## Usage\n\n### Constructor Registration\n\nOne is able to register constructor for a particular class and create\ninstances of it:\n\n```js\nimport Injector from \"@brainstaff/injector\";\nimport { asClass } from \"@brainstaff/injector\";\n\nclass Foo {\n    constructor() {\n        console.log(\"Creating instance of Foo.\");\n    }\n    \n    get dependencies() {\n        return [];\n    }\n}\n\nconst injector = new Injector();\ninjector.register(\"foo\", asClass(Foo));\n\n// Resolve class by its registered name\nconst foo1 = injector.resolve(\"foo\");\n\n// Resolve class by its constructor reference\nconst foo2 = injector.resolve(Foo);\n```\n\nExpected output will be:\n\n```\n[Tue Mar 28 2017 08:39:53 GMT+0300 (MSK)] [Injector] Registering 'foo' component.\nCreating instance of Foo.\nCreating instance of Foo.\n```\n\n<small>[Table of Contents](#table-of-contents)</small>\n\n### Object Registration\n\nOne is able to register pure object.\n\n```js\nimport Injector from \"@brainstaff/injector\";\nimport { asValue } from \"@brainstaff/injector\";\n\nconst foo = {\n    name: \"Foo object \" + Math.round(Math.random() * 10)\n};\n\nconst injector = new Injector();\ninjector.register(\"foo\", asValue(foo));\n\n// Resolve registered object\nconst foo1 = injector.resolve(\"foo\");\nconsole.log(foo1);\n\n// Resolve registered object\nconst foo2 = injector.resolve(\"foo\");\nconsole.log(foo2);\n\n// We are expecting same object\nconsole.log(foo1 === foo2 ? \n    \"Same object resolved.\" : \n    \"WARNING: unexpected resolved object.\")\n```\n\nExpected output will be:\n\n```\n[Tue Mar 28 2017 08:46:31 GMT+0300 (MSK)] [Injector] Registering 'foo' component.\n{ name: 'Foo object 5' }\n{ name: 'Foo object 5' }\nSame object resolved.\n\n```\n\n<small>[Table of Contents](#table-of-contents)</small>\n\n### Dependency Injection\n\nNow it's time to demonstrate dependency injection.\n\n```js\nimport Injector from \"@brainstaff/injector\";\n\nclass Foo {\n    constructor() {\n        console.log(\"Creating instance of Foo.\");\n    }\n    \n    get dependencies() {\n        return [];\n    }\n}\n\nclass Bar {\n    constructor(dependencies) {\n        console.log(\"Creating instance of Bar.\");\n        Object.assign(this, dependencies);\n    }\n    \n    get dependencies() {\n        return [\n            \"foo\"\n        ];\n    }\n}\n\nconst injector = new Injector();\ninjector.register(\"foo\", Foo);\ninjector.register(\"bar\", Bar);\n\n// Resolve class by its registered name\nconst bar1 = injector.resolve(\"bar\");\n\n// Bar contains injected foo\nconsole.log(bar1);\n\n// Resolve class by its constructor reference\nconst bar2 = injector.resolve(Bar);\n\n// Bar contains injected foo\nconsole.log(bar2);\n```\n\nExpected output will be:\n\n```\n[Wed Mar 29 2017 15:27:08 GMT+0300 (MSK)] [Injector] Registering 'foo' component.\n[Wed Mar 29 2017 15:27:08 GMT+0300 (MSK)] [Injector] Registering 'bar' component.\nCreating instance of Foo.\nCreating instance of Bar.\nBar { foo: Foo {} }\nCreating instance of Foo.\nCreating instance of Bar.\nBar { foo: Foo {} }\n```\n\nAlso, usage examples can be found in `./examples` folder.\n\n<small>[Table of Contents](#table-of-contents)</small>\n\n## Changelog\n\n### v2.0.0\n\n- Introduced definitions (asValue, asClass, asFunction).\n- Switched to rollup from webpack.\n\n### v1.0.0\n\n- Initial injector implementation.\n\n<small>[Table of Contents](#table-of-contents)</small>\n","readmeFilename":"README.md"}