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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fioc/strict

v1.1.0

Published

Type-safe DI for JS/TS with strict compile-time validation — an extension of @fioc/core for robust dependency management.

Readme

@fioc/strict

@fioc/strict is an extension of FIoC (Fluid Inversion Of Control) providing stricter type checking and compile-time validation for dependency injection in TypeScript/JavaScript applications. It enhances @fioc/core by enforcing safety rules to prevent runtime errors and type mismatches.


🔑 Key Advantages

  • 🔒 Compile-time validation: Detect unregistered dependencies or duplicate tokens at compile time.
  • 🛡️ Safe resolution: Resolving unregistered dependencies returns type never.
  • 🚀 Strict factory validation: Ensure factory parameters match registered dependencies.
  • 🧩 Composable containers: Merge strict containers while preserving type safety.
  • 🛠️ Controlled replacements: Safely replace existing registrations with replace or replaceFactory.

Unlike @fioc/core, @fioc/strict focuses solely on compile-time guarantees and validation.


Installation

npm install @fioc/core @fioc/strict
# or
yarn add @fioc/core @fioc/strict
# or
pnpm add @fioc/core @fioc/strict

Quick Example: Strict Registration & Resolving

import { buildStrictDIContainer } from "@fioc/strict";
import { createDIToken } from "@fioc/core";

interface ApiService {
  getData: () => string;
}

const ApiServiceToken = createDIToken<ApiService>().as("ApiService");

const HttpApiService: ApiService = { getData: () => "Hello, World!" };

const container = buildStrictDIContainer()
  .register(ApiServiceToken, HttpApiService)
  .getResult();

const apiService = container.resolve(ApiServiceToken); // Type `never` if not registered
apiService.getData(); // "Hello, World!"

Advanced Usage

Factories with Strict Validation

import { buildStrictDIContainer } from "@fioc/strict";
import { createDIToken } from "@fioc/core";

export const getDataUseCaseToken =
  createDIToken<() => string>().as("getDataUseCase");

const getDataUseCaseFactory = (apiService: ApiService) => () =>
  apiService.getData();

const container = buildStrictDIContainer()
  .register(ApiServiceToken, HttpApiService)
  .registerFactory(getDataUseCaseToken, {
    // Type error if the token is already registered
    dependencies: [ApiServiceToken], // Type error if not registered
    factory: getDataUseCaseFactory,
  })
  .getResult();

const useCase = container.resolve(getDataUseCaseToken); // Type `never` if not registered
useCase();

Replacing Registrations Safely

const newImplementation: ApiService = { getData: () => "New Data!" };

const container = buildStrictDIContainer()
  .register(ApiServiceToken, HttpApiService)
  .replace(ApiServiceToken, newImplementation) // Won't give type error
  .replaceFactory(getDataUseCaseToken, {
    dependencies: [ApiServiceToken],
    factory: getDataUseCaseFactory,
  })
  .getResult();

Contributing

Open issues or submit pull requests on GitHub. Include tests for behavioral changes.

License

MIT License. See LICENSE.