{"id":11005,"library":"hast-util-is-css-link","title":"HAST Utility: Is CSS Link","description":"hast-util-is-css-link is a utility function within the unified (specifically rehype) ecosystem designed to determine if a given HAST (HTML Abstract Syntax Tree) node represents a `<link>` element that references a CSS stylesheet. It checks for a `rel` attribute containing 'stylesheet' and a compatible `type` attribute (no type, empty string, or 'text/css'). The package is currently at version 3.0.1 and is part of the actively maintained unified collective, which typically releases updates aligned with Node.js LTS versions and major ecosystem changes. It differentiates itself by providing a focused, robust, and tree-agnostic check adhering to WHATWG HTML standards, making it reliable for transformations and analysis of HTML in JavaScript environments.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","css","hast","hast-util","html","link","unist","util","utility","typescript"],"install":[{"cmd":"npm install hast-util-is-css-link","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-is-css-link","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-is-css-link","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since its parent ecosystem (rehype/unified) moved to ESM primarily in major versions around Node.js 16. CommonJS `require` will not work.","wrong":"const { isCssLink } = require('hast-util-is-css-link')","symbol":"isCssLink","correct":"import { isCssLink } from 'hast-util-is-css-link'"},{"note":"The package ships with TypeScript types. The `isCssLink` function expects a HAST `Node` as input, typically imported from a `hast` type definition package or inferred by your tooling.","symbol":"isCssLink (Type)","correct":"import type { Node } from 'hast'\nimport { isCssLink } from 'hast-util-is-css-link'"}],"quickstart":{"code":"import { h } from 'hastscript';\nimport { isCssLink } from 'hast-util-is-css-link';\n\nconst cssLinkNode = h('link', { rel: ['stylesheet', 'author'], href: 'styles.css' });\nconst alternateCssLinkNode = h('link', { rel: ['stylesheet'], type: 'text/css', href: 'another.css' });\nconst nonCssLinkNode = h('link', { rel: ['preload'], href: 'image.png' });\nconst scriptNode = h('script', { src: 'app.js' });\n\nconsole.log('Is cssLinkNode a CSS link?', isCssLink(cssLinkNode));\nconsole.log('Is alternateCssLinkNode a CSS link?', isCssLink(alternateCssLinkNode));\nconsole.log('Is nonCssLinkNode a CSS link?', isCssLink(nonCssLinkNode));\nconsole.log('Is scriptNode a CSS link?', isCssLink(scriptNode));","lang":"typescript","description":"This quickstart demonstrates how to import and use `isCssLink` to check various HAST nodes, including valid CSS links and non-CSS elements."},"warnings":[{"fix":"Ensure your project runs on Node.js 16 or newer. Migrate your imports from CommonJS `require()` to ES Modules `import` statements.","message":"The unified ecosystem, which this package is part of, updated to require Node.js 16 and changed to ESM-only exports in its major version 7.0.0 (though this package is at 3.0.1, it's tied to that ecosystem versioning).","severity":"breaking","affected_versions":"<7.0.0 (of parent rehype/unified ecosystem)"},{"fix":"Only import directly from the package name, e.g., `import { isCssLink } from 'hast-util-is-css-link'`, and avoid internal paths like `hast-util-is-css-link/lib/foo`. If a specific utility is needed, check if it's exported directly or provided by another package.","message":"The unified ecosystem now strictly uses `exports` in `package.json`, which changes module resolution. Using direct deep imports ('private APIs') is no longer supported or stable.","severity":"breaking","affected_versions":">=7.0.0 (of parent rehype/unified ecosystem)"},{"fix":"Always use `rehype-sanitize` when processing untrusted or user-generated HTML to ensure the resulting HAST tree is safe and free from malicious content.","message":"Improper handling of HTML with rehype (the parent project for HAST utilities) can lead to Cross-Site Scripting (XSS) vulnerabilities if user-controlled HTML is processed without sanitization.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { isCssLink } = require('hast-util-is-css-link')` to `import { isCssLink } from 'hast-util-is-css-link'`. Ensure your project's `package.json` has `\"type\": \"module\"` or you are using a bundler configured for ESM.","cause":"Attempting to use `require()` to import `hast-util-is-css-link`, which is an ES Module.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/hast-util-is-css-link/index.js from ... not supported."},{"fix":"Ensure you are using named imports: `import { isCssLink } from 'hast-util-is-css-link'`. There is no default export for this package.","cause":"Incorrectly importing a named export as a default export, or attempting to import a non-existent export.","error":"TypeError: isCssLink is not a function (or similar undefined export error)"}],"ecosystem":"npm"}