🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

fpdi

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fpdi

Minimalistic dependency injection module

latest
Source
npmnpm
Version
1.4.0
Version published
Maintainers
1
Created
Source

FPDI - minimalistic dependency injection module

Mission: build convenient and lightweight dependency injection library.

Why FPDI?

  • No dependencies
  • No requirements to use unsopported language features such as decorators
  • Framework and language agnostic (both Typescript and Javascript supported)
  • Typescript support (optional)
  • Convenience and simplicity (inspired by react hooks)
  • Throwing exception if your dependency not found or same dependency overriden (can be disabled)

Examples

Typescript

import fpdi from 'fpdi'

fpdi.provide('db', 'Database instance')
fpdi.provide('constant', 3.14)

const [ db, constant ] = fpdi.inject<string, number>('db', 'constant')

Javascript

const fpdi = require('fpdi')

fpdi.provide('db', 'Database instance')
fpdi.provide('constant', 3.14)

// Line below use type annotation for returned array. Works at least in vscode

/** @type {[string, number]} */
const [ db, constant ] = fpdi.inject('db', 'constant')

Bigger example stored in /src/examples/basic.ts

Keywords

di

FAQs

Package last updated on 22 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts