Tools for parsing hint comments in Javascript code
npm install hints




Parses Javascript code for hint comments.
#### hints(code, identifier [, options])
``js
function x(a, b) {
// testhint a:1 b.c:2 b.d e
}
var hints = require('hints');
var h = hints(x.toString(), 'testhint');
// h = {a: 1, b: {c: 2, d: true}, e: true}
`
Hints can be separated with spaces or commas.
Both these are equivalent:
`js`
// testhint a:1 b.c:2 b.d e
// testhint a:1, b.c:2, b.d, e
#### hints.full(code, identifier)
Uses acorn internally to parse the code. You can get the AST (abstract syntax tree) returned too.
`js
function x(a, b) {
// testhint a:1
}
var result = hints.full(x.toString(), 'testhint');
// result.hints = {a: 1}
// result.hintsPos = {a: {value: 1, start: 20, end: 36}}
// result.tree = { / AST / }
`
#### pos
Returns character positions of the comments with the hints.
Default: false
`js
function x(a, b) {
// testhint a:1
}
var h = hints(x.toString(), 'testhint', {pos: true});
// h = {a: {value: 1, start: 20, end: 36}}
`
Use npm test to run the tests. Use npm run cover` to check coverage.
See changelog.md
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/hints/issues
Pull requests are very welcome. Please:
* ensure all tests pass before submitting PR
* add an entry to changelog
* add tests for new features
* document new functionality/API additions in README