`character-parser` is a focused JavaScript utility library designed for parsing JavaScript code snippets, particularly within template languages like EJS or Jade. Its primary function is to robustly handle bracket nesting, strings, and comments, allowing for the reliable extraction of delimited JavaScript sections without performing a full syntax validation or abstract syntax tree (AST) generation. The current stable version is 4.0.0, which introduced significant changes including native ES module support and updated package export configurations. This library differentiates itself by offering a lightweight, character-by-character parsing mechanism and state management, providing functions to parse entire strings or single characters, track nesting depth, and find code segments based on custom delimiters while intelligently ignoring content within nested structures or comments. It does not aim to be a comprehensive JavaScript parser but rather a precise tool for template-driven code extraction.
npm install character-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `character-parser` to find delimited expressions and manage parsing state across multiple string segments, including handling nested structures and escaped characters.
Migrate to TypeScript for type safety, or rely on custom Flow definitions if still using Flow.
Ensure all imports are from the main package path: `import { NamedExport } from 'character-parser'`. Do not attempt to import from internal directories.Wrap parsing operations in `try...catch` blocks to gracefully handle and identify syntax errors. Inspect the `error.code` property for specific error types.
Always chain `parse()` calls by passing the state: `let state = parse(firstPart); state = parse(secondPart, state);`.
Change the import path to reference only the main package: `import { someExport } from 'character-parser'`.Use ES module named imports: `import { parse, parseUntil } from 'character-parser'`. Ensure your environment supports ES Modules or transpile accordingly.Review the input string for syntax errors, specifically ensuring all string delimiters (single quotes, double quotes, backticks) are properly matched and escaped where necessary.
No dependency data recorded yet.