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 🙏

© 2026 – Pkg Stats / Ryan Hefner

zego-injector

v1.0.3

Published

> ## Factory.createConstructor 直接创建一个实例/如果已经被创建 则直接返回. 注意传入的class必须被@Injectable > ## Factory.getInstance 检查当前模块是否已经被实例化过,如果已经实例化过就直接返回实例 否则返回null > ### 使用方法 ``` import { Factory, Injectable } from 'zego-injector'

Readme

zego nodejs端的Injector工具

注意Inject的对象是全局唯一的

Factory.createConstructor 直接创建一个实例/如果已经被创建 则直接返回. 注意传入的class必须被@Injectable

Factory.getInstance 检查当前模块是否已经被实例化过,如果已经实例化过就直接返回实例 否则返回null

使用方法

import { Factory, Injectable } from 'zego-injector'

@Injectable()
class TestInjectA{
    sayBy(){ return "By" }
}
@Injectable()
class TestInjectB{
    constructor(private testA:TestInjectA){}
    log(){
        const testASay = this.testA.sayBy()
        console.log(testASay)
    }
}

Factory.createConstructor<TestInjectB>(TestInjectB).log()
Factpry.getInstance(TestInjectB).log()

Factory.createFactory 根据你传递的function返回的结果 当作实例. 这样其他地方也可以拿到当前实例

使用方法

import { Factory, Injectable } from 'zego-injector'

@Injectable()
class TestInjectA{
    sayBy(){ return "By" }
}

const instance = Factory.createFactory(
    // 你需要传递的方法 必须返回一个结果 用于当作实例
    function (testA:TestInjectA){
        return testA.sayBy()
    },
    // 你的key 方便其他地方可以根据key inject到你
    "MYTEST",
    // 你需要依赖的对象 传递给你的function
    [TestInjectA]
)

console.log(instance)

Factory.create 是Factory.createConstructor 与 Factory.createFactory的集合 动态判断需要哪种创建方式

Factory.useValue 注册一个module

使用方法

import { Factory, Injectable } from 'zego-injector'
class TestValueA{
    sayBy(){ return "By" }
}

// 注册一个module
Factory.useValue({
    useValue:new TestValueA(),
    // 你的key 方便其他地方可以根据key inject到你
    provide:"MYVALUE"
})

console.log(Factory.create("MYVALUE").sayBy())

Factory.useFactory 根据你传递的Function 注册一个module

使用方法

import { Factory, Injectable } from 'zego-injector'
@Injectable()
class TestFactoryA{
    sayBy(){ return "By" }
}

Factory.useFactory({
     useFactory(testA:TestFactoryA){
        return testA
    },
    inject:[TestFactoryA],
    provide:"MYFACTORY"
})

console.log(Factory.create("MYFACTORY").sayBy())

Factory.useClass 给一个@Injectable的class 进行别名

使用方法

@Injectable()
class TestClassA{
    sayBy(){ return "By" }
}

// 定义一个module 这时候是不会创建的
Factory.useClass({
    // 必须是@Injectable
    useClass:TestClassA,
    // 你的key 方便其他地方可以根据key inject到你
    provide:"MYCLASS"
})

expect(Factory.create("MYCLASS").sayBy()).toBe("By")

const GetMyClass = function (){
    return createParamDecorator({
        factory(myclass:any){ return myclass },
        inject:["MYCLASS"]
    })
}

@Injectable()
class TestClassB{
    log(
        @GetMyClass()
        myclass:any
    ){
        return myclass.sayBy()
    }
}

console.log(Factory.create<TestClassB>("TestClassB").log())