npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dekorator

v0.2.3

Published

Ultra light weight dependency injection library using ES7 (2016) decorators.

Downloads

3

Readme

Dekorator

wercker status

Simple dependency injection lib exposing inject and singleton decorators. Dekorator can be used with Node or in browser with an ES6 transpiler such as (Babel)[https://babeljs.io/].

Dekorator is an extremely stripped down dependency injection library. It is meant to provide a lightweight solution for embedding into other libraries. If you are looking for a robust solution with lots of features this isn't it. It has a very specific use case. This doesn't mean it won't work exactly as indicated but rather you may need additional features it does not provide.

Install

For use with Node

$ npm install dekorator

For use in browser & JSPM

NOTE: jspm is a package manager which sets up your project for use with System.js, the ES6 module loader system. You can read more on (jspm here)[http://jspm.io].

jspm install npm:dekorator

or

jspm install github:origin1tech/dekorator

Getting Started

Using dekorator is very simple. You need merely decorate an ES6 class to have it's dependency(s) injected into the constructor or specify the class as a singleton.

Injecting

// NOTE: import below shown using System.js if you
// reference typings (dist/index.d.ts) you can import
// as ... from 'dekorator';
import {inject, invoke} from 'origin1tech/dekorator';

class Vehicle {
	constructor() {
	}
}

@inject(Vehicle)
class Car {
	constructor(vehicle) {
		this.vehicle = vehicle;
	}
	getVehicle() {
		return this.vehicle;
	}
}

// Invoke the class.
let car = invoke(Car);

// do something with car and
// injected vehicle.
let vehicle = car.getVehicle();

singleton

Nothing special here simply decorate your class with "@singleton" and it just works. Decorating with this decorator will ensure the class is a singleton in turn it will return the same instance when injected in other classes.

@singleton
class MyClass {
	constructor() {}
}

Additional Notes

One thing that trips up devs when first using decorators, well at least for those that actually use semi colons is that when using an ES7/ES2016 decorator you DO NOT use a semi colon after the decoration. Think of it in terms of a fluent api where you wouldn't terminate as you're using dot notation to further define some class/function etc.

What NOT to do

The below example with fail and not work

@inject(OtherClass);
class MyClass {
	constructor() {}
}

Testing

You will notice a few specs in the test folder which can be run using Mocha. Simply type mocha in your terminal from the root of the project or run:

npm test

License

Basically you can do just about anything you like. Enjoy!

See LICENSE.md