1.1.0 • Published 9 years ago

trunk v1.1.0

Weekly downloads
11
License
(MIT OR Apache-2....
Repository
github
Last release
9 years ago

trunk

Dependency solver / container.

How ?

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 !');
});
1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.2

9 years ago

0.0.0

9 years ago

0.0.1

11 years ago