Parse pragma and its content from JavaScript comments
yarn add pragma
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.
Type: string
Required: true
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.
- 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
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