Simple Code Frame is a lightweight JavaScript utility designed for generating structured code frames, primarily used in error reporting or diagnostic tools. Its current stable version is 1.3.0. Unlike more comprehensive alternatives like `@babel/code-frame`, `simple-code-frame` distinguishes itself by operating directly on raw string input without requiring an AST parser. This focused design makes it exceptionally small and performant for tasks that only involve highlighting specific lines and columns within arbitrary text. The library ships with TypeScript types, providing a good developer experience for both JavaScript and TypeScript projects. Releases appear to follow a moderate cadence, adding features like `maxWidth` for line truncation and colored output in recent minor versions. It is suitable for environments where parsing overhead is undesirable, focusing solely on visual presentation of code context.
npm install simple-code-frameVerified import paths — ran on the pinned version, not inferred.
Demonstrates generating a code frame for a specific line and column, including options for highlighting and message, and usage of `maxWidth` for truncation.
Always use 1-based indexing for line and column arguments to ensure correct highlighting.
Validate line and column inputs against the actual content length or lines count if precise highlighting is critical.
Ensure the terminal supports ANSI colors or avoid using `highlightColor` option in environments where color support is uncertain or undesired.
Test different `maxWidth` values to find an appropriate balance between readability and conciseness for your specific use case.
Ensure the first argument passed to `createCodeFrame` is always a string containing the source code.
Verify that the `code` input parameter is a valid string before calling `createCodeFrame`.
No dependency data recorded yet.