New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

micro-namespace

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-namespace

Wrap object into a namespace

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

micro-namespace

Wrap libraries into a namespace.

clone

repository

$ hg clone https://bitbucket.org/frostbane/micro-namespace

npm

$ npm install micro-namespace

usage

AMD require

var ns = require("micro-namespace");

include script

<script type="text/javascript"
        src="micro-namespace.js"></script>

examples

simple namespace

// create fb.common.util namespace
namespace("fb.common.util");

// add methods to fb.common.util
fb.common.util.formatDate = function(...){ ... };
fb.common.util.logError   = function(...){ ... };

// use the methods/classes
if(!fb.common.util.formatDate("2017/12/14")){
    fb.common.util.logError("format failed");
}

namespace and object

// create fb.common.extra namespace with methods
namespace("fb.common.extra", {
    getDateNow   :function(){ ... },
    getServerUrl :function(){ ... },
    AjaxParser   :function(){ ... },
});

// use the methods/classes
var now = fb.common.extra.getDateNow();

var host = fb.common.extra.getServerUrl();

var ax = new fb.common.extra.AjaxParser();

amd require

var ns = require("micro-namespace");

ns("fb.ajax", {
    getUsername :function(){ ... },
});

var user = fb.ajax.getUsername();

initialize object

the third parameter (init) is called under the context of the second parameter (obj) after the namespace is created.

namespace("fb.common.upload", {
    uploadFile   :function(){},
    initUploader :function(){},
    resetErrors  :function(){},
}, function(){
    // exported methods can be accessed with this
    this.initUploader();
    
    this.resetErrors();
    
    $(function(){
        $("#cal").datepicker();
    });
});

Keywords

namespace

FAQs

Package last updated on 07 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts