{"id":11012,"library":"hast-util-phrasing","title":"HAST Phrasing Content Utility","description":"hast-util-phrasing is a niche utility within the unified (remark/rehype) ecosystem, specifically designed to determine if a given HAST (Hypertext Abstract Syntax Tree) node represents 'phrasing content' according to HTML specifications. This classification is crucial for advanced HTML manipulation and validation scenarios. The package is currently at version 3.0.1, indicating active maintenance and regular, albeit minor, updates since its major release. It adheres to the unified collective's release cadence, typically aligning major versions with Node.js LTS support lifecycles. Its key differentiator is its precise adherence to HTML phrasing content rules, making it invaluable for tools that need to strictly adhere to HTML parsing and serialization standards, particularly in content transformation pipelines.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/hast-util-phrasing","tags":["javascript","unist","hast","hast-util","util","utility","html","category","phrasing","typescript"],"install":[{"cmd":"npm install hast-util-phrasing","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-phrasing","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-phrasing","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v2.0.0. CommonJS 'require' is not supported.","wrong":"const phrasing = require('hast-util-phrasing')","symbol":"phrasing","correct":"import { phrasing } from 'hast-util-phrasing'"},{"note":"When using Deno or browser ESM CDNs, ensure named import as there is no default export. Specify the major version for stability.","wrong":"import phrasing from 'https://esm.sh/hast-util-phrasing@3'","symbol":"phrasing","correct":"import { phrasing } from 'https://esm.sh/hast-util-phrasing@3'"}],"quickstart":{"code":"import { phrasing } from 'hast-util-phrasing';\n\n// Example 1: A div element, which is typically flow content and not phrasing.\nconst divNode = {\n  type: 'element',\n  tagName: 'div',\n  children: [{ type: 'text', value: 'Hello' }]\n};\nconsole.log('Is <div> phrasing content?', phrasing(divNode));\n// Expected: false\n\n// Example 2: A meta element with 'itemProp', which can be phrasing content.\nconst metaItemPropNode = {\n  type: 'element',\n  tagName: 'meta',\n  properties: { itemProp: 'description' },\n  children: []\n};\nconsole.log('Is <meta itemprop> phrasing content?', phrasing(metaItemPropNode));\n// Expected: true\n\n// Example 3: A meta element with 'charset', which is not phrasing content.\nconst metaCharsetNode = {\n  type: 'element',\n  tagName: 'meta',\n  properties: { charSet: 'utf8' },\n  children: []\n};\nconsole.log('Is <meta charset> phrasing content?', phrasing(metaCharsetNode));\n// Expected: false\n\n// Example 4: A text node, which is always phrasing content.\nconst textNode = { type: 'text', value: 'Some text' };\nconsole.log('Is text node phrasing content?', phrasing(textNode));\n// Expected: true","lang":"typescript","description":"This quickstart demonstrates how to use the `phrasing` utility with various HAST node types to check if they qualify as phrasing content according to HTML specifications, illustrating different outcomes."},"warnings":[{"fix":"Ensure that the `value` argument passed to `phrasing` is always a valid HAST `Node`. Validate input before calling `phrasing` if external data is used.","message":"Version 3.0.0 removed support for non-nodes as input. The `phrasing` function now strictly expects a valid HAST `Node` object.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update your `@types/hast` package to the latest compatible version (e.g., `npm install @types/hast@latest`).","message":"Version 3.0.0 updated `@types/hast` and other internal utilities. If you are using TypeScript, you might need to update your `@types/hast` dependency to match.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade your Node.js environment to version 16 or newer. For projects that must support older Node.js, pin the package to `hast-util-phrasing@^2`.","message":"Version 3.0.0 changed the package to require Node.js 16 or higher. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always use the main entry point: `import { phrasing } from 'hast-util-phrasing'`. Do not rely on internal, non-exported paths.","message":"The package now uses `exports` in `package.json` since v3.0.0. This enforces strict import paths and removes access to private internal APIs. Direct imports to subpaths not explicitly exported will fail.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Refactor your imports to use ES module syntax: `import { phrasing } from 'hast-util-phrasing'`. Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json` or `.mjs` files).","message":"The package migrated to ESM (ES Module) only starting with version 2.0.0. CommonJS `require()` statements will no longer work.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use ESM import syntax: `import { phrasing } from 'hast-util-phrasing'`.","cause":"Attempting to use `require()` for this package, which is ESM-only since v2.0.0.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... hast-util-phrasing.js not supported."},{"fix":"Ensure the input to `phrasing` is always a valid HAST node object. Add checks like `if (value && typeof value === 'object' && 'type' in value) { phrasing(value); }` if inputs are untrusted.","cause":"Passing `null`, `undefined`, or a non-object to `phrasing` after v3.0.0, which expects a valid HAST `Node`.","error":"TypeError: Cannot read properties of undefined (reading 'type') at phrasing (hast-util-phrasing.js:...) or similar 'value is not a HAST Node' errors."}],"ecosystem":"npm"}