wires-namespace

0.1.0 • Public • Published

Wires Namespace

Micro-library for namespacing objects.

Travis Status Code Climate Score Coverage Dependency Status

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

Fork and clone this repo.

git clone git@github.com: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.

Readme

Keywords

none

Package Sidebar

Install

npm i wires-namespace

Weekly Downloads

2

Version

0.1.0

License

ISC

Last publish

Collaborators

  • thejameskyle