context-parser is a robust and compact HTML5 context parser library designed to analyze web pages and report the execution context of each character, primarily for security purposes like preventing Cross-Site Scripting (XSS). The current stable version is 2.0.1. It differentiates itself by adhering strictly to the HTML5 WHATWG specification for accurate context determination, offering two distinct parser classes: `FastParser` for performance-critical scenarios and `Parser` for feature-rich analysis. The library is event-driven and focuses on the tokenization process to provide precise context reporting without unnecessary overhead, making it suitable for server-side HTML analysis. Its design emphasizes security, simplicity, and straightforward code for easier review and smaller footprint.
npm install context-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the `Parser` class, read an HTML file, and use the `contextualize` method to analyze its execution context in a Node.js environment.
Review your code for direct usage of v1.x parsing methods. Migrate to instantiating either `Parser` or `FastParser` and calling the `contextualize()` method on the instance for context analysis.
Ensure your code handles `null` values when accessing attribute values, especially in scenarios where attributes might be present but without an explicit value (e.g., boolean attributes). Add `null` checks where appropriate.
Use object destructuring for CommonJS imports: `const { Parser } = require('context-parser');`Run `npm install context-parser` in your project directory to install the package.
If your project is CommonJS, switch to `const { Parser } = require('context-parser');`. If your project is ESM, verify if the package has a `type: 'module'` in its `package.json` or provides an `exports` field for ESM compatibility.No dependency data recorded yet.