1.0.1 • Published 8 months ago

piqure v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Piqure

Just a dependency injection system in JavaScript.

Prerequisites

Install

npm i piqure

Usage

Classic usage:

import { key, piqure } from './Piqure';

const { provide, inject } = piqure();

// Create an injection key with a type and a description
const KEY_TO_INJECT = key<string>('Key to inject');

// Register a text using provide
provide(KEY_TO_INJECT, 'Injected text');

// Use your text
const injected = inject(KEY_TO_INJECT);

console.log(injected); // Injected text

Attach piqure to the map you want:

import { piqure } from './Piqure';

const memory = new Map();

const { provide, inject } = piqure(memory); // Now, the injected values will be inside "memory"

// […]

Attach piqure to a wrapper like window:

import { piqureWrapper } from './Piqure';

const { provide, inject } = piqureWrapper(window, 'piqure'); // This will reuse or create a "piqure" field

// […]

To expose provide and inject globally with the window (if you're in a browser environment), just create a file in your project with:

import { piqureWrapper } from './Piqure';

const { provide, inject } = piqureWrapper(window, 'piqure');

export { provide, inject };

Contribute

Install with:

npm i

Launch tests with:

npm test

Then start coding and don't hesitate to send PR.

1.0.1

8 months ago

1.0.0

9 months ago