Skip to content
/ pragma Public

Parse pragma and its content from JavaScript comments

License

Notifications You must be signed in to change notification settings

egoist/pragma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Parse pragma and its content from JavaScript comments

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published