bootstrap-events

0.2.0 • Public • Published

bootstrap-events

Build Status devDependency Status Coverage Status


NOTE: This is still experimental code.

Bootstraps events based on the directory tree and found modules' exported methods.

Installing

You can install this module through:

npm install --save bootstrap-events

Usage

var path = require('path');
var events = require('events');
var bootstrapEvents = require('bootstrap-events');
 
var emitter = new events.EventEmitter();
var path = path.join(__dirname, 'root');
bootstrapEvents(emitter, path)

See the example directory for more information.

Public API

bootstrapEvents(emitter, targetDir)

Bootstraps a directories modules methods recursivelly into an event emitter.

Params:

  • EventEmitter emitter The EventEmitter to attach listeners to
  • String targetDir The directory to start the search in
  • Object [options] An options object
  • Function|Mixed|RegExp|Array [options.ignore] A file ignore pattern
  • Boolean [options.moduleWildcards=true] Whether to set functions

Return:

  • EventEmitter The emitter parameter

Private API

_bootstrapObject(emitter, baseEventName, obj)

Bootstraps an object obj's methods recursivelly to the EventEmitter emitter based on a base event name baseEventName.

Params:

  • EventEmitter emitter The event emitter to attach listeners to
  • String baseEventName The base event name
  • Object obj An object to scan for handlers

Return:

  • EventEmitter The emitter parameter

_walk(dir)

Recursively walks a directory and returns paths to all found files.

Params:

  • String dir The directory to walk

Return:

  • Array. paths All the found files' paths

_matches(pred, value)

Checks if a file matches a predicate, value, regexp or Array of any of the preceding.

Params:

  • Function|Mixed|RegExp|Array pred
  • Mixed value

Return:

  • Boolean matches

License

This code is licensed under the MIT license. See the LICENSE file for more information.

Package Sidebar

Install

npm i bootstrap-events

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • yamadapc