pragma
v1.0.0
Published
Parse pragma and its content from JavaScript comments
Downloads
651
Readme
pragma
Parse pragma and its content from JavaScript comments
Install
yarn add pragma
Usage
const pragma = require('pragma')
pragma(`
function foo() {}
/* @babel {
presets: ['es2015']
} */
function bar() {}
/* @server {
port: 3000
}
*/
`)
//=> what you get:
{
babel: {
presets: ['es2015']
},
server: {
port: 3000
}
}
Both multi-line /* ... */
and single-line // ...
comments are supported.
API
pragma(input, [options])
input
Type: string
Required: true
options
parseContent
Type: function
Default: source => new Function(`return ${source}`)()
The function to process source content, for example: //@server {port: 1}
, the source content is {port: 1}
and it will be evaluated.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
pragma © egoist, Released under the MIT License. Authored and maintained by egoist with help from contributors (list).
egoistian.com · GitHub @egoist · Twitter @rem_rin_rin