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

inversime

v1.1.0

Published

Simple reactive library

Readme

Inversime

npm version downloads download size

About

Inversime is simple inject dependencies library.

Installation

You can install inversime using npm:

$ npm install inversime

Usage

type Container = {
  service: IBookService
  bookApiClient: BookApiClient
  useCase: GetBooksUseCase
};

type Book = {
  name: string
  read: boolean
}

class BookApiClient {
  async get (): Promise<Book[]> {
    return [
      { name: 'The name of the wind', read: true },
      { name: "The Wise Man's Fear", read: false },
      { name: 'The way of kings', read: true },
      { name: 'Word of radiance', read: false }
    ]
  }
}

class BookService {
  constructor (private deps: Pick<Container, 'bookApiClient'>) {}

  async get () {
    const books = await this.deps.bookApiClient.get()
    return books
  }
}

class GetBooksUseCase {
  constructor (private deps: Pick<Container, 'service'>) {}
  execute () {
    return this.deps.service.get()
  }
}

const container = inversime<Container>({
  service: Inversime.fromClass(BookService),
  bookApiClient: Inversime.fromClass(BookApiClient),
  useCase: Inversime.fromClass(GetBooksUseCase)
})

const books = await container.get('useCase').execute()
console.log(books.length) // 4

Singleton

You can add a book store in the previous code and you need keep a singleton instance.

type Container = {
  // Add store in the container type
  store: BookStore;
  service: IBookService
  bookApiClient: BookApiClient
  useCase: GetBooksUseCase
};

// Create the store
class BookStore {
  books: Book[]
  set (books: Book[]) {
    this.books = books
  }

  get () {
    return this.books
  }
}

class BookService {
  constructor (private deps: Pick<Container, 'bookApiClient'>) {}

  async get () {
    const books = await this.deps.bookApiClient.get()
    // Save books in the store
    this.deps.books.store.set(books)
    return books
  }
}

const container = inversime<Container>({
  service: Inversime.fromClass(BookService),
  bookApiClient: Inversime.fromClass(BookApiClient),
  useCase: Inversime.fromClass(GetBooksUseCase)
})

await container.get('useCase').execute()
const store = container.get('books').store

console.log(store.books.length) // 4

Context

Yo can group dependencies by differents contexts. For example we can create a book context.

type Container = {
  // Create group in the container type
  books: {
    apiClient: BookApiClient
    service: BookService
  },
  useCase: GetBooksUseCase
}

class BookService {
  // Use the books context
  constructor (private deps: Pick<Container, 'books'>) {}
  async get () {
    const books = await this.deps.books.apiClient.get()
    return books
  }
}

class GetBooksUseCase {
  // Use the books context
  constructor (private deps: Pick<Container, 'books'>) {}
  execute () {
    return this.deps.books.service.get()
  }
}

const container = inversime<Container>({
  // Create the context 
  books: Inversime.context({
    service: Inversime.fromClass(BookService),
    apiClient: Inversime.fromClass(BookApiClient),
  }),
  useCase: Inversime.fromClass(GetBooksUseCase)
})

const books = await container.get('useCase').execute()
console.log(store.books.length) // 4

Extract dependencies

You can have a class with dependencies as arguments and you don't have to modify the class.

type Container = {
  books: {
    store: BookStore;
  },
  apiClient: BookApiClient
  service: BookService
  useCase: GetBooksUseCase
}

class BookService implements IBookService {
  // Split dependencies in two arguments
  constructor (private apiClient: BookApiClient, private store: BookStore) {}

  async get () {
    const books = await this.apiClient.get()
    this.store.set(books)
    return books
  }
}

const container = inversime<Container>({
  books: Inversime.context({
    store: Inversime.singleton(() => new BookStore())
  }),
  apiClient: Inversime.fromClass(BookApiClient),
  // Extract dependencies with `Inversime.extract`
  service: Inversime.extract(Inversime.fromClass(BookService), ['apiClient', 'books.store']),
  useCase: Inversime.fromClass(GetBooksUseCase)
})

const books = await container.get('useCase').execute()
console.log(books.length) // 4