hast-util-is-css-style is a focused utility from the unified ecosystem, specifically designed to inspect HAST (HTML Abstract Syntax Tree) nodes. Its primary function is to determine whether a given HAST node represents an HTML <style> element that is intended to contain CSS. This utility is currently stable at version 3.0.1 and is part of a larger monorepo (rehypejs/rehype-minify) which tends to release updates synchronously across related packages, especially for major ecosystem changes (e.g., Node.js version support, ESM-only shifts). Its key differentiator lies in its deep integration with the hast specification, ensuring accurate identification of CSS style elements based on their type attribute, including default cases and various text/css variations, which is crucial for tools that parse, transform, or optimize HTML content.
npm install hast-util-is-css-styleVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `isCssStyle` to identify HTML `<style>` elements containing CSS, handling various `type` attribute scenarios and non-style elements.
Ensure your project is configured for ESM, or use dynamic `import()` if you must load it from a CommonJS module. Upgrade to Node.js 16+.
Upgrade your Node.js runtime to version 16 or higher.
Only use public import paths like `hast-util-is-css-style` for module imports.
When processing untrusted HTML, always use a sanitizer like `rehype-sanitize` in your processing pipeline to ensure the generated output is safe.
Change `const {isCssStyle} = require('hast-util-is-css-style')` to `import {isCssStyle} from 'hast-util-is-css-style'` and ensure your Node.js environment supports ESM (e.g., by using `"type": "module"` in `package.json` or by using `.mjs` file extensions).As `hast-util-is-css-style` is ESM-only, ensure you are using `import {isCssStyle} from 'hast-util-is-css-style'` within an ESM context.Refactor your code to use `import` statements instead of `require` for all module dependencies. If you need to load CommonJS modules from ESM, consider `import pkg from 'some-cjs-package';` or `const cjsModule = await import('some-cjs-package');`.No dependency data recorded yet.