hints

Tools for parsing hint comments in Javascript code

Usage no npm install needed!

<script type="module">
  import hints from 'https://cdn.skypack.dev/hints';
</script>

README

hints.js

Tools for parsing hint comments in Javascript code

Current status

NPM version Build Status Dependency Status Dev dependency Status Coverage Status

Usage

Parses Javascript code for hint comments.

hints(code, identifier [, options])

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:

// 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.

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 */ }

Options

pos

Returns character positions of the comments with the hints. Default: false

function x(a, b) {
    // testhint a:1
}

var h = hints(x.toString(), 'testhint', {pos: true});
// h = {a: {value: 1, start: 20, end: 36}}

Tests

Use npm test to run the tests. Use npm run cover to check coverage.

Changelog

See changelog.md

Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/hints/issues

Contribution

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