pragma

v1.0.0
Parse pragma and its content from JavaScript comments

pragma

NPM version NPM downloads Build Status donate

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

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. 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

npm i pragma

Metadata

  • MIT
  • Whatever
  • egoist
  • released 2/14/2017

Downloads

Maintainers