js-namespace

A lightweight JavaScript helper checking for or creating namespace objects.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
js-namespace
502.0.24 years ago7 years agoMinified + gzip package size for js-namespace in KB

Readme

namespace-js
Build Status npm version
Namespace-js is a lightweight JavaScript helper checking for or creating namespace objects.

Install

npm install js-namespace --save

Usage

You can create an object chain with
import Namespace from 'js-namespace'
// or
// const Namespace = require('js-namespace')

Namespace.create('be.awesome'); // => be: Object { awesome: Object }

// or direct assignment

Namespace.create('be.awesome').Magic = function() {
  // your magic code
}; // => function be.awesome.Magic()

Check if a namespace exists
Namespace.is('be.awesome'); // => false
Namespace.create('be.awesome');
Namespace.is('be.awesome'); // => true

Check if namespace on a local object exists
var localObj = {
  be: {
    awesome: 'bam'
  }
};

if (Namespace.is(localObj, 'be.awesome')) {
  Namespace.create('be.awesome');
}

Deployment

A node module package will be published by setting a new version. (Make sure you are logged in via npm registry)
npm version <version> -m '%s – <reason>'

Licensing

MIT