Skip to content

A Babel plugin that enhances JavaScript functions with custom attributes, providing additional metadata and annotations.

Notifications You must be signed in to change notification settings

jan53n/babel-plugin-attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-attributes

A Babel plugin that enhances JavaScript functions with custom attributes, providing additional metadata and annotations.

Node.js CI

Example

Input

$attr(middlewares(['auth']), can(['create']))
function routeHandler(req, res) {
    // some code
}

Output

function routeHandler(req, res) {
    // some code
}

(function () {
  const attributes = new Map();
  attributes.set(middlewares, middlewares(['auth']));
  attributes.set(can, can(['create']));
  routeHandler.__attributes__ = attributes;
})();

Installation

You can install babel-plugin-attributes using npm:

npm install babel-plugin-attributes --save-dev

Plugin Options

Option Description Default Value
attrFunctionName Valid function name to be used to identify attribute calls $attr
attrPropertyName Valid object property name that is used to store attribute map __attributes__

Usage

{
  "plugins": [
    "babel-plugin-attributes",
    {
      "attrFunctionName": "$attr",
      "attrPropertyName": "__attributes__"
    }
  ]
}

About

A Babel plugin that enhances JavaScript functions with custom attributes, providing additional metadata and annotations.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published