hast-util-classnames is a utility package within the unified collective, designed to simplify the management and merging of CSS class names on HAST (HTML Abstract Syntax Tree) elements. It provides a programmatic API to concatenate, conditionally include, or remove classes, analogous to popular string-based classname utilities but operating directly on HAST nodes. The package is currently at version 3.0.0, which requires Node.js 16 or higher and is distributed exclusively as an ES module (ESM). New major versions typically coincide with dropping support for unmaintained Node.js versions or significant API changes, ensuring compatibility with current Node.js releases. Its key differentiator is its deep integration with the HAST ecosystem, allowing direct manipulation of `properties.className` arrays on HAST element nodes, which is more robust than string manipulation when working with syntax trees.
npm install hast-util-classnamesVerified import paths — ran on the pinned version, not inferred.
Demonstrates both ways to use `classnames`: merging an array of strings and modifying a HAST node's `className` property in place.
Upgrade your Node.js environment to version 16 or newer to ensure compatibility.
Update your import statements from `require('hast-util-classnames')` to `import { classnames } from 'hast-util-classnames';` and ensure your project is configured for ESM.Only use the documented `classnames` export. Refactor any code that previously relied on internal paths to use the public API.
Be mindful of the function's signature and return type. If you intend to get a list of classes without modifying a node, do not pass a `Node` as the first argument. If you intend to modify a node, ensure you pass an `Element` node first.
Switch to ES module import syntax: `import { classnames } from 'hast-util-classnames';`Ensure you are using a named import `import { classnames } from 'hast-util-classnames';` and that your Node.js version is 16 or higher for v3.0.0+.No dependency data recorded yet.