annotate-code
beautifully annotate source code with a message, given an index, like a parser or compiler
🔧 Install
· 🧩 Example
· 📜 API docs
· 🔥 Releases
· 💪🏼 Contribute
· 🖐️ Help
Install
$ npm i annotate-code
Example
import { annotate } from 'annotate-code'
console.log(
annotate({
message: 'some error message',
index: 48,
size: 6,
code,
}).message
)
API
Table of Contents
annotate
src/index.ts:44-160
Annotates a source code string given an index and a message.
Parameters
-
settings
{message: string, code: string, index: number, linesBefore: number?, linesAfter: number?, size: number?, showLineNumbers: boolean?}
settings.message
The message to displaysettings.code
The code to annotatesettings.index
The index positionsettings.linesBefore
How many lines before to show (optional, default 3
)settings.linesAfter
How many lines after to show (optional, default 3
)settings.size
The size of the arrows ^^^^ (optional, default 1
)settings.showLineNumbers
Whether to show line numbers (optional, default true
)
Returns {line: number?, col: number?, message: string}
Contribute
Fork or
edit and submit a PR.
All contributions are welcome!
License
MIT © 2021
stagas