magic-variables
v0.10.0
Published
Magic variables for Node.js
Downloads
13
Maintainers
Readme
magic-variables
Magic variables for Node.js
Installation
npm install --save magic-variables
Usage
Simply add this to your top-most file, something like bootloader. No need to assign it to a variable, it can be accessible globally.
Basic variables:
require('magic-variables');
console.log(__magic.package); // => /Users/gokaygurcan/Projects/magic-variables/package.json
// or
console.log(require(__magic.package).version); // => 0.10.0
console.log(__magic.base); // => /Users/gokaygurcan/Projects/magic-variables/
console.log(__magic.filename); // => magic-variables.js
console.log(__magic.file); // => /Users/gokaygurcan/Projects/magic-variables/magic-variables.js
console.log(__magic.extension); // => js
console.log(__magic.line); // => 38
// | where column number points
// V
console.log(__magic.column); // => 13
// |
// V
console.log(__magic.info); // => /Users/gokaygurcan/Projects/magic-variables/magic-variables.js:46:13
console.log(__magic.function); // => (anonymous) || function_name
Mapping:
Create .magicrc
file in your application root and put these lines in it:
{
"api" : "routes/api",
"config" : "config.js",
"lib" : "lib/"
}
Note: Do not use the reserved words: package, base, filename, file, extension, line, column, info and function. Also, not class or method too which are reserved for planned features.
console.log(__magic.api); // => /Users/gokaygurcan/Projects/magic-variables/routes/api
console.log(__magic.config); // => /Users/gokaygurcan/Projects/magic-variables/config.js
console.log(__magic.lib); // => /Users/gokaygurcan/Projects/magic-variables/lib/
TODO
Planned features:
__magic.class // => null || class_name
__magic.method // => null || method_name
Contribution
Any contributions are more than welcome!