hastscript is a utility library that provides a hyperscript interface for programmatically creating HTML Abstract Syntax Trees (hast trees). Analogous to React's `createElement` or Vue's `h` function, it simplifies the process of generating complex HTML structures in code by replacing repetitive object literal syntax with concise function calls. It also handles the normalization of attributes into the format required by the hast specification. The current stable version is 9.0.1, with frequent patch and minor releases and major versions typically introducing breaking changes like ESM-only support or Node.js version bumps. It is a core part of the unified ecosystem for processing content and specifically targets HTML, differentiating it from `unist-builder` (for generic unist nodes) or `xastscript` (for XML nodes).
npm install hastscriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create both HTML and SVG hast trees using the `h` and `s` functions with selectors, properties, and nested children.
Migrate your codebase to use ECMAScript Modules (ESM) syntax: `import { h } from 'hastscript'` instead of `require()`. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions.Upgrade your Node.js environment to version 16 or newer to ensure compatibility.
Update your imports to directly reference `hastscript`: `import { h, s } from 'hastscript'` instead of `import { h } from 'hastscript/html'`.Review usage of `h` with custom elements. If issues arise, ensure your custom element declarations and property usage strictly adhere to the updated typing and runtime expectations.
Update your TypeScript configuration and codebase to align with the provided types. Address any type errors that emerge after upgrading.
Configure your `tsconfig.json` (`jsxImportSource`), Babel (`@babel/plugin-transform-react-jsx`), or other build tooling to specify `hastscript` for HTML JSX or `hastscript/svg` for SVG JSX.
Change your import statements to use ESM syntax: `import { h } from 'hastscript';` and ensure your environment supports ESM (e.g., `"type": "module"` in `package.json`).Ensure you are using `import { h } from 'hastscript';` for ESM, or if in a strict CommonJS context (not recommended for `hastscript`), use `import('hastscript').then(({ h }) => { /* ... */ });`.Update your imports to `import { h, s } from 'hastscript';` as both functions are now directly exported from the main package entry point.Upgrade Node.js to a version that supports ESM (>=16 for hastscript) and ensure your files are treated as ESM, or use dynamic `import()` if necessary.
No dependency data recorded yet.