A Babel plugin that enhances JavaScript functions with custom attributes, providing additional metadata and annotations.
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__" } ] }