Namespace-It - Apply a namespace to any block of code contained inside a function, or in a javascript file.
Grab the scope variables of a function or a file.
const NamespaceIt = require('namespaceit');
function someFunction() {
const number = 1;
const string = 'string';
const array = [1,2];
const object = {
hey: 'you',
fn: function() {
return 1;
}
};
function functionStatement() {
return 'I\'m a function statement';
};
const functionExpression = function() {
return 'I\'m a function expression';
};
}
const namespaceIt = new NamespaceIt('A', someFunction);
namespaceIt.applyNamespace();
A.object.fn(); //1
A.array; //[1,2]
namespaceIt.clearNamespace();
//A is no longer defined!
- Does not currently support arrow function syntax
- Code must be properly linted with semi colons after each line
- Functions with arguments are not yet supported
- Variable declared as a reference to another variable in scope is not yet supported
All points under Limitations are being worked on until they are no longer limitations. If this project excites you, feel free to submit a pull request.
- esprima: npm module for parsing
- Jasmine: javascript framework for unit testing
Nikhil Bhaskar