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

@nicolawealth/ioc

v1.0.1

Published

![Tests Passing](https://github.com/NicolaWealth/ioc/actions/workflows/auto_test_main_badge.yml/badge.svg) ![Code Cov](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgithub.com%2Fnicolawealth%2Fioc%2Fraw%2Fmain%2Fcodecov/badge.json&query=%24.

Readme

Tests Passing Code Cov

Introduction

The ioc (Inversion of Control) package simplifies developer testing by allowing for decoupling of code from its dependencies. With ioc, dependencies can be overridden with stubs in test cases such that the original dependencies are not invoked during testing.

Installation

This package should be installed via npm. You must have npm installed first. The following can be run on the commandline to install the ioc package with npm:

npm install @nicolawealth/ioc

Usage

This package provides functionality to easily manage dependencies during testing. In order to use ioc in testing, the real dependencies in your code must be implemented with ioc so they can later be overridden and restored.

Some common use cases may include testing code without invoking:

  • database calls
  • network calls
  • file system access
  • cloud services
  • etc.

Interface

The package provides two ways of implementing ioc in your code, the dep implementation and the default implementation. The dep pattern is implemented with the ioc.dep() function. The default pattern is implemented with the ioc.setDefault(), ioc.setDeps(), and ioc.get() methods. The ioc.productionMode() and ioc.reset() functions are shared amongst the two patterns. The default ioc style allows for a "universal" setting of application-wide dependencies such that they can be registered just once. Whereas the dep ioc style is preferable more for component-level dependencies, providing more granular control. The ioc package provides the instance of the ioc object in ioc.ts. For proper functionality ensure this shared instance is used amongst all your files and do not use the function iocFactory() provided in ioc_factory.ts.

Dep Pattern

  • dep({dependencies}); provides the primary functionality of overriding dependencies through the following function:
    • dep.set({dependencies}); overrides the component level dependencies with the provided stubs.
    • dep.reset(); resets all component level dependencies to their original values.
  • productionMode(); disables the use of ioc and forces the use of the original dependencies regardless of if they have been overridden or not.

Default Pattern

  • setDefault(dependencyObject: {'name': dependency}); registers a unique name and sets it as a real dependency under the given name. Returns a get() wrapper to the given dependency.
  • setDeps({dependenciesObject}); overrides the current value of a list of dependencies with the given names until reset is called.
    • Note: expectDefault is an optional parameter which defaults to false thus not requiring all setMany dependencies to have been previously registered with setDefault
  • get('name'); validates the existence of a registered dependency and returns the current dependency under the given name.
  • reset(); resets all registered dependencies to their set defaults regardless of current values as well as resetting all component level dependencies (dep pattern dependencies).
  • productionMode(); disables the use of set and forces the use of the default dependency values regardless (cannot be undone).

Note: be aware the original dependencies are still imported when using ioc in tests and any side effects of those imports are run during tests

Testing

Tests can be found in ioc.test.ts located in ioc/src and should be run with sinon, mocha and nyc.