Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic-variables

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-variables

Magic variables for Node.js

  • 0.10.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

magic-variables

Magic variables for Node.js

npm version npm downloads travis ci npm devDependencies github license

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!

License

MIT © Gökay Gürcan

Keywords

FAQs

Package last updated on 22 Jun 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc