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

babel-plugin-inject-args

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-inject-args

Babel plugin that makes function argument names accessible at runtime

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
81
increased by15.71%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-inject-args

Babel plugin that processes specially annotated functions or classes and exposes the names of their parameters as runtime-accessible metadata. This can be used by dependency injection containers to call the function or instantiate the class and automatically resolve dependencies.

To enable this metadata for a function or class, add the string @inject in a leading comment. The plugin will add a $inject property to the object which contains an array of parameter names. For example, this source:

// @inject
function createThing(paramA, paramB) {
}

Is transformed into:

// @inject
function createThing(paramA, paramB) {
}

myService.$inject = ['paramA', 'paramB'];

ES classes are also supported:

// @inject
class Thing {
  constructor(paramA, paramB) { … }
}

Is transformed into:

// @inject
class Thing {
  constructor(paramA, paramB) { … }
}

Thing.$inject = ['paramA', 'paramB'];

Usage

To use the plugin, first add the dependency to your project:

npm install --save-dev babel-plugin-inject-args

Then enable the plugin in your Babel configuration, for example in a .babelrc file:

{
  "plugins": ["inject-args"]
}

Further reading

For information on understanding the plugin implementation, see https://github.com/jamiebuilds/babel-handbook.

FAQs

Package last updated on 04 Nov 2020

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