https://github.com/web-pacotes/vault
A small, token based container designed for dependency injection 🫙
https://github.com/web-pacotes/vault
angular container dependency-injection di nodejs react svelte typescript vault vue web-pacotes
Last synced: 3 months ago
JSON representation
A small, token based container designed for dependency injection 🫙
- Host: GitHub
- URL: https://github.com/web-pacotes/vault
- Owner: web-pacotes
- License: mit
- Created: 2023-07-11T22:53:40.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-16T15:36:50.000Z (almost 3 years ago)
- Last Synced: 2025-05-31T10:42:20.199Z (about 1 year ago)
- Topics: angular, container, dependency-injection, di, nodejs, react, svelte, typescript, vault, vue, web-pacotes
- Language: TypeScript
- Homepage: https://web-pacotes.github.io/vault
- Size: 138 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vault
A small, token based container designed for dependency injection 🫙
  
---
## How to use
Using Vault to store and lookup dependencies is as simple as:
```typescript
// Create a vault
const vault = new Vault();
// Create some tokens
const token = 'my cool token';
// Store dependencies!
vault.store('my secret message', token);
// Look them up at some point in your program
const dependency = vault.lookup(token);
// It should print "just lookup this dependency: my secret message"
console.info(`just lookup this dependency: ${dependency}`);
```
## Features
- Store primitive and non-primitive dependencies
- Prevent store nullable or undefined values
- Type inferred lookups
## Why should I use Vault?
If you're working in a _context_ based environment and you want to retrieve dependencies based on the context state, then Vault was designed for you. Simply register the vault instance to your context and get the dependencies in some point in your app after. Here's an example on how you can use it in SvelteKit:
```typescript
// src/routes/+page.ts
export const load = (async () => {
const dependency = new AuthenticationRepositoryImpl(...);
const vault = new Vault();
vault.store(dependency, 'AuthenticationRepository');
setContext('vault', dependency);
});
...
// src/lib/components/AuthenticationStore.ts
const { value } = getContext('vault');
const authenticationRepo = vault.lookup('AuthenticationRepository');
const store = writable();
return {
store.subscribe,
authenticate: () => authenticationRepo.loginAnonymously(),
};
```
---
## Bugs and Contributions
Found any bug (including typos) in the package? Do you have any suggestion
or feature to include for future releases? Please create an issue via
GitHub in order to track each contribution. Also, pull requests are very
welcome!
To contribute, start by setting up your local development environment. The [setup.md](setup.md) document will onboard you on how to do so!