@shepherdorg/nano-inject
TypeScript icon, indicating that this package has built-in type declarations

5.1.0 • Public • Published

Nano dependency injection.

Minimalistic dependency injection library.

The tests are the best documentation in this case.

import {expect} from 'chai'
   import {inject} from './inject'
   
   describe('inject dependency injection', function(){
   
       it('should return injected dependency',function(){
           var deps = inject({
               foo:"bar"
           });
           expect(deps("foo")).to.equal('bar');
       });
   
       it('should fail on missing dependency',function(){
           try{
               var deps = inject({
                   foo:"bar"
               });
               deps("baz");
           }  catch (e){
               expect(e.message).to.eql('Required dependency <baz> is not provided.');
           }
       });
   
       it('should not fail on optional missing dependency', function(){
           var deps = inject({
               x:"bar"
           });
           expect(deps("foo", true)).to.equal(undefined);
       })
   
   });
   
   

/@shepherdorg/nano-inject/

    Package Sidebar

    Install

    npm i @shepherdorg/nano-inject

    Weekly Downloads

    29

    Version

    5.1.0

    License

    MIT

    Unpacked Size

    5.65 kB

    Total Files

    11

    Last publish

    Collaborators

    • stefaneg
    • nordfjord