Registry / web-framework / hast-util-is-css-link

hast-util-is-css-link

JSON →
library3.0.1jsnpmunverified

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.

npm install hast-util-is-css-link
INSTALL
IMPORT
SIG · HAST-UTIL-IS-CSS-L
H
hast-util-is-css-link
web-frameworkjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isCssLink
import { isCssLink } from 'hast-util-is-css-link'
const { isCssLink } = require('hast-util-is-css-link')
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.
isCssLink (Type)
import type { Node } from 'hast' import { isCssLink } from 'hast-util-is-css-link'
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.

This quickstart demonstrates how to import and use `isCssLink` to check various HAST nodes, including valid CSS links and non-CSS elements.

import { h } from 'hastscript'; import { isCssLink } from 'hast-util-is-css-link'; const cssLinkNode = h('link', { rel: ['stylesheet', 'author'], href: 'styles.css' }); const alternateCssLinkNode = h('link', { rel: ['stylesheet'], type: 'text/css', href: 'another.css' }); const nonCssLinkNode = h('link', { rel: ['preload'], href: 'image.png' }); const scriptNode = h('script', { src: 'app.js' }); console.log('Is cssLinkNode a CSS link?', isCssLink(cssLinkNode)); console.log('Is alternateCssLinkNode a CSS link?', isCssLink(alternateCssLinkNode)); console.log('Is nonCssLinkNode a CSS link?', isCssLink(nonCssLinkNode)); console.log('Is scriptNode a CSS link?', isCssLink(scriptNode));
Debug
Known issues
breakingThe 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).
fix
Ensure your project runs on Node.js 16 or newer. Migrate your imports from CommonJS `require()` to ES Modules `import` statements.
affects: <7.0.0 (of parent rehype/unified ecosystem)
breakingThe 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.
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.
affects: >=7.0.0 (of parent rehype/unified ecosystem)
gotchaImproper 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.
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.
affects: All versions
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/hast-util-is-css-link/index.js from ... not supported.
Attempting to use `require()` to import `hast-util-is-css-link`, which is an ES Module.
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.
TypeError: isCssLink is not a function (or similar undefined export error)
Incorrectly importing a named export as a default export, or attempting to import a non-existent export.
fix
Ensure you are using named imports: `import { isCssLink } from 'hast-util-is-css-link'`. There is no default export for this package.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
hast-util-is-css-link — npm install hast-util-is-css-link · libregistry