{"library":"simple-code-frame","title":"Simple Code Frame","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install simple-code-frame"],"cli":null},"imports":["import { createCodeFrame } from 'simple-code-frame';","const { createCodeFrame } = require('simple-code-frame');","import type { CodeFrameOptions } from 'simple-code-frame';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createCodeFrame } from 'simple-code-frame';\n\nconst sourceCode = `function greet(name) {\n  console.log('Hello, ' + name + '!');\n  throw new Error('Something went wrong');\n}\n\ngreet('World');`;\n\n// Simulate an error at line 3, column 9\nconst errorFrame = createCodeFrame(sourceCode, 3, 9, {\n  highlightColor: 'red',\n  message: 'Error here!'\n});\n\nconsole.log(errorFrame);\n\n// Example with maxWidth and no message\nconst longLineCode = `const veryLongVariableName = 'This is a very long string that should be truncated by maxWidth.';\nconsole.log(veryLongVariableName);`;\nconst truncatedFrame = createCodeFrame(longLineCode, 1, 1, { maxWidth: 50 });\nconsole.log('\\n--- Truncated Frame ---\\n');\nconsole.log(truncatedFrame);","lang":"typescript","description":"Demonstrates generating a code frame for a specific line and column, including options for highlighting and message, and usage of `maxWidth` for truncation.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}