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-ts-container

v0.0.8

Published

This container liberay for ts

Downloads

54

Readme

pretty-ts-container一款提供装饰器风格的类型依赖注入方式的类管理容器,所用的类型最后都会被注册到一个全局的container对象里面。

安装
  • npm install pretty-ts-container --save
  • npm i pretty-ts-container --save
API介绍(Typescript)
  • register(alias: string = null) 将一个类注册到容器内
  • singleton(alias: string = null) 将一个类型注册成为单例
  • factory(alias: string|T) 通过别名或者类获取注册的对象
  • makeWith(alias: string|T, ... args: any[]) 通过别名或者类型获取注册对象,同时可以想构造函数提供参数,单例模式只有在系统第一次获取对象时才会调用构造函数,所以可以把单例模式对象在系统启动时提供参数完成对象创建
import {register, singleton, makeWith, factory} from "pretty-ts-container";
@register // @register()一样的效果
 class T1 {
   constructor ( public a: number = 0){}
 }
 @singleton // @singleton()一样的效果
  class T2 {
    constructor ( public a: number = 0){}
  }
// 注册Test类,Test将拥有别名的
@register('test')
 class Test {
   constructor ( public a: number = 0){}
 }
 // 注册Test1类,没有别名
 @register()
 class Test1 {
   constructor(public b: number){}
 }
 // 注册Test3类,Test3将拥有别名的
 @singleton('test3')
 class Test2 {
   constructor ( public a: number = 0){}
 }
 // 注册Test3类单例,没有别名
 @singleton()
 class Test3 {
   constructor(public b: number){}
 }
 
 
 // 获取注册对象
 (factory('test') as Test).a; // 0
 (makeWith(Test1, 9) as Test1).b // 9
API介绍(javascript)
  • register(alias = null, constructorParamTypes) 将一个类注册到容器内, alias别名,不填写第一个参数为数组时其值会赋给constructorParamTypes(构造函数参数类型数组,定义构造函数参数类型),constructorParamTypes数组类型
  • singleton(alias = null, constructorParamTypes) 将一个类型注册成为单例, alias别名,不填写第一个参数为数组时其值会赋给constructorParamTypes(构造函数参数类型数组,定义构造函数参数类型)constructorParamTypes数组类型
  • factory(alias: string|T) 通过别名或者类获取注册的对象
  • makeWith(alias: string|T, ... args: any[]) 通过别名或者类型获取注册对象,同时可以想构造函数提供参数,单例模式只有在系统第一次获取对象时才会调用构造函数,所以可以把单例模式对象在系统启动时提供参数完成对象创建
import {register, singleton, makeWith, factory} from "pretty-ts-container";
@register // @register()一样的效果
 class T1 {
   constructor (  a = 0){this.a = a;}
 }
 @singleton // @singleton()一样的效果
  class T2 {
    constructor (  a = 0){this.a = a;}
  }
// 注册Test类,Test将拥有别名的
@register('test', [Number])
 class Test {
   constructor (  a = 0){
       this.a = a;
   }
 }
 // 注册Test1类,没有别名
 @register([Number])
 class Test1 {
   constructor(b){ this.b = b;}
 }
 // 注册Test3类,Test3将拥有别名的
 @singleton('test3', [Number])
 class Test2 {
   constructor (a = 0){this.a = a;}
 }
 // 注册Test3类单例,没有别名
 @singleton([String])
 class Test3 {
   constructor( b){this.b = b;}
 }
 
 
 // 获取注册对象
 (factory('test')).a; // 0
 (makeWith(Test1, 9)).b // 9