wires-namespace
v0.1.0
Published
A simple namespace class.
Downloads
3
Readme
Wires Namespace
Micro-library for namespacing objects.
Usage
Namespace
Namespaces are objects that you may add definitions by keypath.
import Namespace from 'wires-namespace';
let namespace = new Namespace();
namespace.add('greeting', function() {
return 'Hello World';
});
namespace.get('greeting')();
// >> 'Hello World'
namespace.greeting();
// >> 'Hello World'
add
Add a definition to a namespace, maintaining any existing definitions.
import Namespace from 'wires-namespace';
let locations = new Namespace();
locations.add('california.sanFrancisco.soma', {
type: 'neighborhood',
location: 'california.sanFrancisco'
});
locations.add('california.sanFrancisco', {
type: 'city',
location: 'california'
});
locations.california.sanFrancisco;
// >> { type: 'neighborhood', location: 'california.sanFrancisco', soma: {...} }
locations.california.sanFrancisco.soma;
// >> { type: 'city', location: 'california' }
get
Safely retrieve a definition by keypath, returning undefined
if definition does not exist.
import Namespace from 'wires-namespace';
let people = new Namespace();
people.add('jamesKyle', {
name: 'James Kyle',
type: 'Programmer'
});
people.get('jamesKyle.type');
// >> 'Programmer'
people.get('johnDoe.type');
// >> undefined
Contibuting
Getting Started
git clone [email protected]:marionette-wires/wires-namespace.git && cd wires-namespace
Make sure Node.js and npm are installed.
npm install
Running Tests
npm test
===
© 2014 James Kyle. Distributed under ISC license.