base-namespace

Plugin that adds a `namespace` getter to a Base instance.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
base-namespace
0.2.08 years ago8 years agoMinified + gzip package size for base-namespace in KB

Readme

base-namespace NPM version NPM downloads Build Status
Plugin that adds a namespace getter to a Base instance.

Install

Install with npm:
$ npm install base-namespace --save

Usage

var namespace = require('base-namespace');
var Base = require('base');
var base = new Base();

base.use(namespace());

Default
By default, namespace uses the app._name property, which is uses the constructor name (set in base):
console.log(base.namespace);
//=> 'base'

Alias
If alias is defined, it will be used instead of app._name:
base.alias = 'foo';
console.log(base.namespace);
//=> 'foo'

Parent namespace
If a parent instance is defined, namespace is created from parent.namespace + alias:
var foo = new Base();
foo.alias = 'whatever';
base.parent = foo;

base.alias = 'foo';
console.log(base.namespace);
//=> 'whatever.foo'

Multiple ancestors
When an app has multiple ancestors, its namespace might look something like this:
var foo = new Base();
foo.alias = 'foo';

var bar = new Base();
bar.alias = 'bar';
bar.parent = foo;

var baz = new Base();
baz.alias = 'baz';
baz.parent = bar;

var qux = new Base();
qux.alias = 'qux';
qux.parent = baz;

console.log(qux.namespace);
//=> 'foo.bar.baz.qux'

Related projects

You might also be interested in these projects:

Contributing

This document was generated by verb, please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:
$ npm install -g verb verb-readme-generator && verb

Running tests

Install dev dependencies:
$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.

This file was generated by verb
, v0.9.0, on June 05, 2016.