This package provides a utility function, `isEventHandler`, to check if a given string represents a potential HTML event handler attribute name. It primarily identifies strings starting with 'on' and having a length of five or more characters (e.g., 'onclick', 'onmouseover'), without performing validation on the actual event handler's existence or validity. As part of the `unified` and `hast` ecosystem, it is designed for processing HTML Abstract Syntax Trees. The current stable version is `3.0.1`, maintained within the `rehypejs` monorepo, which generally coordinates major releases across its packages. It is ESM-only and requires Node.js 16 or newer. This tool differentiates itself by its focused scope within the `hast` ecosystem, offering a lightweight and specific check for attribute names.
npm install hast-util-is-event-handlerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the `isEventHandler` function to identify attribute names that conform to the basic pattern of an HTML event handler, emphasizing its `on` prefix and length criteria.
Upgrade your Node.js environment to version 16 or newer. Use `nvm install 16 && nvm use 16` or update your CI/CD configuration.
Update all imports to use ESM syntax: `import { isEventHandler } from 'hast-util-is-event-handler'`. Ensure your project is configured for ESM, potentially by setting `"type": "module"` in `package.json`.Always import symbols directly from the main package entry point (`'hast-util-is-event-handler'`) and avoid relying on deep imports to internal paths, as these are subject to change without major version bumps.
Do not rely on `isEventHandler` alone for security or strict HTML validation. If you need to verify against a list of actual HTML events, combine this utility with a separate, comprehensive schema check.
Always use `rehype-sanitize` or a similar sanitization plugin when processing untrusted HTML input to prevent XSS attacks in your `rehype` pipeline.
Change your import statement to use ESM syntax: `import { isEventHandler } from 'hast-util-is-event-handler';`. Ensure your `package.json` has `"type": "module"` or your file uses the `.mjs` extension for Node.js environments.Verify that `isEventHandler` is imported as a named export from `hast-util-is-event-handler`: `import { isEventHandler } from 'hast-util-is-event-handler';`. Do not use `import isEventHandler from 'hast-util-is-event-handler';` as there is no default export.The function `isEventHandler` is fully typed, and its return type (`boolean`) is simple. You typically do not need to import a specific type for this utility. If you're looking for a type related to AST nodes, refer to `@types/hast` or `hast` itself. For custom type definitions, you might need to declare them locally or extract them from the function's signature if complex.
No dependency data recorded yet.