1.0.5 • Published 1 year ago

injecti v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Injecti is a simple dependency injection tool for typescript with the following features:

  • First class dependency injection without container
  • Fully written in TypeScript
  • Clean code compatible

Table of Contents:


Installation

To get started, install injecti using npm or yarn:

npm install injecti
# or
yarn add injecti

Usage

import { inject } from 'injecti';

const insertUserInDB = (name: string) => {
  return db.insert('user', { name });
};

const [createUser, createUserFactory] = inject(
  { insertUserInDB },
  (deps) => (name: string) => {
    return deps.insertUserInDB(name);
  }
);

// usage
await createUser('John');

// test
const fakeInsertUserInDB = () => {};
const createUser = createUserFactory({ insertUserInDB: fakeInsertUserInDB });
const result = createUser('John');

// assert fakeInsertUserInDB called once
// assert result is {name: 'John'}

That's it! You can now use injecti to create unit testable functions.

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago