https://github.com/netgusto/trunk
Dependency solver / container. Works great with koa.
https://github.com/netgusto/trunk
Last synced: 10 months ago
JSON representation
Dependency solver / container. Works great with koa.
- Host: GitHub
- URL: https://github.com/netgusto/trunk
- Owner: netgusto
- License: other
- Created: 2015-06-29T09:56:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-20T21:49:57.000Z (almost 9 years ago)
- Last Synced: 2025-03-01T18:38:51.073Z (11 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trunk
Dependency solver / container.
## How ?
```js
import { Trunk } from 'trunk';
import { Mailer, MockupMailer } from '...somepackage';
const trunk = new Trunk();
trunk
.add('isprod', ['env'], (env) => env.ENVIRONMENT === 'prod')
.add('env', () => process.env)
.add('smtpcreds', ['env'], (env) => {
return {
host: env.SMTP_HOST,
port: env.SMTP_PORT,
user: env.SMTP_LOGIN,
password: env.SMTP_PASSWORD
};
})
.add('mailer', ['smtpcreds', 'isprod'], (smtpcreds, isprod) => {
// promise will be resolved on open
if(isprod) {
return new Promise((resolve, reject) => {
mailerlib(function(initializedmailer) {
resolve(initializedmailer);
});
});
} else {
return Promise.resolve(new MockupMailer());
}
});
trunk.open().then(() => {
const mailer = trunk.get('mailer');
mailer.send('example@example.com', 'Hello, World !', 'This is trunk !');
});
```