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

pretty-container

v0.0.9

Published

This container liberay for ts

Downloads

3

Readme

Chinese

pretty-container is a container which can makes classes and objects to be organized and managed easier, and which provides a decorator-style IOC for programming.And also all classes finally will be registered into a global object (which is a Container type constant.).

Install
  • npm install pretty-container --save
  • npm i pretty-container --save
API Introduction
Typescript
  • register(alias: string = null) It will register a class to the container.
  • singleton(alias: string = null) It will register a singleton for a class
  • factory(alias: string|T) Creating a object by a alias or a class which has been registered into the container.
  • makeWith(alias: string|T, ... args: any[]) Creating a object by a alias or a class which has been registered into the container which you can pass some parameters to the class's constructor function.
import {register, singleton, makeWith, factory} from "pretty-container";
@register // @register() same
 class T1 {
   constructor ( public a: number = 0){}
 }
 @singleton // @singleton() same
  class T2 {
    constructor ( public a: number = 0){}
  }
// register Test,test will be can to a alias for Test
@register('test')
 class Test {
   constructor ( public a: number = 0){}
 }
 // register Test1
 @register()
 class Test1 {
   constructor(public b: number){}
 }
// register a singleton for Test2,test3 will be can to a alias for Test2
 @singleton('test3')
 class Test2 {
   constructor ( public a: number = 0){}
 }
// register a singleton Test3
 @singleton()
 class Test3 {
   constructor(public b: number){}
 }
 
 
 // create object
 (factory('test') as Test).a; // 0
 (makeWith(Test1, 9) as Test1).b // 9
Javascript(es6)
  • register(alias = null, constructorParamTypes) It will register a class to the container. The first parameter is the alias of the register class .If the first parameter is a array data , and the second parameter is null or not be pass , the first parameter's value will assign to the second parameter(constructorParamTypes is a array which defined the registered class's constructor parameter types)
  • singleton(alias = null, constructorParamTypes) It will register a singleton for a class
  • factory(alias)
  • makeWith(alias, ... args)
import {register, singleton, makeWith, factory} from "pretty-container";
@register // same as @register()
 class T1 {
   constructor (  a = 0){this.a = a;}
 }
 @singleton // same as @singleton()
  class T2 {
    constructor (  a = 0){this.a = a;}
  }
// register Test as test, Number is the first parameter's type
@register('test', [Number])
 class Test {
   constructor (  a = 0){
       this.a = a;
   }
 }
 // register Test1
 @register([Number])
 class Test1 {
   constructor(b){ this.b = b;}
 }
 // register a singleton for Test2 , and using `test3` as a alias
 @singleton('test3', [Number])
 class Test2 {
   constructor (a = 0){this.a = a;}
 }
 //
 @singleton([String])
 class Test3 {
   constructor( b){this.b = b;}
 }
 
 
 // 
 (factory('test')).a; // 0
 (makeWith(Test1, 9)).b // 9