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

@favy/di

v2.0.3

Published

[![codecov](https://codecov.io/gh/favyorg/di/branch/master/graph/badge.svg?token=P42D5R2C14)](https://codecov.io/gh/favyorg/di) [![npm version](https://badge.fury.io/js/@favy%2Fdi.svg)](https://badge.fury.io/js/@favy%2Fdi) ![npm bundle size](https://img.s

Downloads

9

Readme

@favy/di

codecov npm version npm bundle size GitHub

A lightweight and powerful dependency injection library for TypeScript.

Features

  • 🚀 Create modules as easily as functions
  • 🔧 Easily replace any dependency at any level
  • 🌟 Simple integration into any project
  • 💪 Full TypeScript support with type inference
  • 🧩 High extensibility and support for Higher Kinded Types
  • 🎯 Caching and lazy initialization

Why @favy/di?

Unlike many other solutions, @favy/di offers:

  • Minimal syntax: No need for decorators or complex configurations.
  • Easy integration: A module is just a function, so it can be integrated anywhere.
  • Performance: Minimal runtime overhead.
  • Flexibility: Easily adapts to different programming styles and patterns.

Installation

npm install @favy/di

Quick Start

import { Module } from '@favy/di';

const SimpleModule = Module()('SimpleModule', () => 'Hello, DI!');
console.log(SimpleModule()); // Output: Hello, DI!

// Simple module combination
const ModuleA = Module()('ModuleA', () => 10);
const ModuleB = Module()('ModuleB', () => 5);
const CombinedModule = Module()('CombinedModule', ($) => $.ModuleA + $.ModuleB);
console.log(CombinedModule({ ModuleA, ModuleB })); // Output: 15

Advanced Usage

Partial Application with .provide()

const CalculatorModule = Module<{ x: number, y: number }>()('Calculator', ({ x, y }) => x + y);
const PartialCalculator = CalculatorModule.provide({ x: 5 });
console.log(PartialCalculator({ y: 3 })); // Output: 8

Lazy Initialization

const LazyModule = Module({ lazy: true })('LazyModule', () => {
  console.log('LazyModule initialized');
  return 42;
});

const Consumer = Module()('Consumer', ($) => {
  setTimeout(() => $.LazyModule, 1000);
});

Consumer({ LazyModule }); 
// Prints "LazyModule initialized" after 1 second

Cache Management

const CachedModule = Module({ cache: 'module' })('CachedModule', () => Math.random());
console.log(CachedModule()); // Random number
console.log(CachedModule()); // Same number

Module.flushCache(); // Clear cache
console.log(CachedModule()); // New random number

Documentation

For more detailed information about the library's capabilities and usage examples, please refer to our full documentation.

Contributing

We welcome community contributions! If you have suggestions for improvements or have found a bug, please create an issue or submit a pull request.

License

@favy/di is distributed under the MIT license. See the LICENSE file for more information.