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