{"name":"hastscript","version":"9.0.2","keywords":["dom","dsl","hast-util","hast","html","hyperscript","rehype","unist","utility","util","vdom","virtual"],"author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"license":"MIT","_id":"hastscript@9.0.2","maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"}],"homepage":"https://github.com/syntax-tree/hastscript#readme","bugs":{"url":"https://github.com/syntax-tree/hastscript/issues"},"dist":{"shasum":"3dc6595c54f433e782634b7beea874d63dc6f991","tarball":"http://registry-npm.ywwl.com/hastscript/download/hastscript-9.0.2.tgz","fileCount":26,"integrity":"sha512-ghcIWJlrROwOddvAvbt0AAnLTyt/Xt02Ucc6VfXejSPESai+q24iROd0MjOYUEhJiI/b4vokkm9ZHb4MNOOizA==","signatures":[{"sig":"MEUCIDcdTpz0YDVupcwYxJHhGxgV1OOX/HLFKYdwv2kxyDRYAiEA6y/FEN/MWA3y/mIRpaT7KUavm/YMYmq2MlEzvm6W30g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIELg+NFjebzA6YQ4aqFXyD3rf/7IEe/n4vuGZn0smMUjAiEAklhh8GQChcfPAm7H15IUSQRopx9+l8sPkBB9JKsG6J4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47271,"size":12578,"noattachment":false,"key":"/hastscript/-/hastscript-9.0.2.tgz"},"type":"module","types":"./index.d.ts","exports":{".":"./index.js","./jsx-runtime":"./lib/automatic-runtime-html.js","./jsx-dev-runtime":"./lib/automatic-runtime-html.js","./svg/jsx-runtime":"./lib/automatic-runtime-svg.js","./svg/jsx-dev-runtime":"./lib/automatic-runtime-svg.js"},"funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"718268d452cfd0f1c8e5afea21bbb093c224b72e","scripts":{"test":"npm run generate && npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && tsd && type-coverage","format":"remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix","generate":"node --conditions development script/generate-jsx.js && node --conditions development script/build.js","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/hastscript.git","type":"git"},"_npmVersion":"12.2.1","description":"hast utility to create trees","directories":{},"sideEffects":false,"_nodeVersion":"26.12.1","dependencies":{"@types/hast":"^3.0.0","property-information":"^7.0.0","comma-separated-tokens":"^2.0.0","space-separated-tokens":"^2.0.0","hast-util-parse-selector":"^4.0.0"},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"strict":true,"atLeast":100,"ignoreFiles":["test/jsx-build-jsx-automatic-development.js"],"ignoreFiles#":"needed `any`s :'("},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","xo":"^5.0.0","tsd":"^0.33.0","prettier":"^3.0.0","acorn-jsx":"^5.0.0","remark-cli":"^12.0.0","typescript":"^6.0.0","@types/node":"^26.0.0","svg-tag-names":"^3.0.0","type-coverage":"^2.0.0","estree-util-to-js":"^2.0.0","esast-util-from-js":"^2.0.0","remark-preset-wooorm":"^11.0.0","estree-util-build-jsx":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/hastscript_9.0.2_1793304604250_0.924196952183212","host":"s3://npm-registry-packages-npm-production"},"readme":"# hastscript\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n[![Size][badge-size-image]][badge-size-url]\n\n[hast][github-hast] utility to create trees with ease.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`h(selector?[, properties][, …children])`](#hselector-properties-children)\n  * [`s(selector?[, properties][, …children])`](#sselector-properties-children)\n  * [`Child`](#child)\n  * [`Properties`](#properties-1)\n  * [`Result`](#result)\n* [Syntax tree](#syntax-tree)\n* [JSX](#jsx)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a hyperscript interface (like `createElement` from React and\n`h` from Vue and such) to help with creating hast trees.\n\n## When should I use this?\n\nYou can use this utility in your project when you generate hast syntax trees\nwith code.\nIt helps because it replaces most of the repetition otherwise needed in a syntax\ntree with function calls.\nIt also helps as it improves the attributes you pass by turning them into the\nform that is required by hast.\n\nYou can instead use [`unist-builder`][github-unist-builder]\nwhen creating any unist nodes and\n[`xastscript`][github-xastscript] when creating xast (XML) nodes.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+),\ninstall with [npm][npmjs-install]:\n\n```sh\nnpm install hastscript\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {h} from 'https://esm.sh/hastscript@9?bundle'\n</script>\n```\n\n## Use\n\n```js\nimport {h, s} from 'hastscript'\n\nconsole.log(\n  h('.foo#some-id', [\n    h('span', 'some text'),\n    h('input', {type: 'text', value: 'foo'}),\n    h('a.alpha', {class: 'bravo charlie', download: 'download'}, [\n      'delta',\n      'echo'\n    ])\n  ])\n)\n\nconsole.log(\n  s('svg', {viewbox: '0 0 500 500', xmlns: 'http://www.w3.org/2000/svg'}, [\n    s('title', 'SVG `<circle>` element'),\n    s('circle', {cx: 120, cy: 120, r: 100})\n  ])\n)\n```\n\nYields:\n\n```js\n{\n  type: 'element',\n  tagName: 'div',\n  properties: {className: ['foo'], id: 'some-id'},\n  children: [\n    {\n      type: 'element',\n      tagName: 'span',\n      properties: {},\n      children: [{type: 'text', value: 'some text'}]\n    },\n    {\n      type: 'element',\n      tagName: 'input',\n      properties: {type: 'text', value: 'foo'},\n      children: []\n    },\n    {\n      type: 'element',\n      tagName: 'a',\n      properties: {className: ['alpha', 'bravo', 'charlie'], download: true},\n      children: [{type: 'text', value: 'delta'}, {type: 'text', value: 'echo'}]\n    }\n  ]\n}\n{\n  type: 'element',\n  tagName: 'svg',\n  properties: {viewBox: '0 0 500 500', xmlns: 'http://www.w3.org/2000/svg'},\n  children: [\n    {\n      type: 'element',\n      tagName: 'title',\n      properties: {},\n      children: [{type: 'text', value: 'SVG `<circle>` element'}]\n    },\n    {\n      type: 'element',\n      tagName: 'circle',\n      properties: {cx: 120, cy: 120, r: 100},\n      children: []\n    }\n  ]\n}\n```\n\n## API\n\nThis package exports the identifiers [`h`][api-h] and [`s`][api-s].\nThere is no default export.\nIt exports the additional [TypeScript][] types\n[`Child`][api-child],\n[`Properties`][api-properties],\nand\n[`Result`][api-result].\n\nThe export map supports the automatic JSX runtime.\nYou can pass `hastscript` or `hastscript/svg` to your build tool\n(TypeScript, Babel, SWC)\nwith an `importSource` option or similar.\n\n### `h(selector?[, properties][, …children])`\n\nCreate virtual **[hast][github-hast]** trees for HTML.\n\n##### Signatures\n\n* `h(): root`\n* `h(null[, …children]): root`\n* `h(selector[, properties][, …children]): element`\n\n##### Parameters\n\n###### `selector`\n\nSimple CSS selector\n(`string`, optional).\nWhen string, builds an [`Element`][github-hast-element].\nWhen nullish, builds a [`Root`][github-hast-root] instead.\nThe selector can contain a tag name (`foo`),\nIDs (`#bar`),\nand classes (`.baz`).\nIf the selector is a string but there is no tag name in it then `h` defaults to\nbuild a `div` element and `s` to a `g` element.\n`selector` is parsed by\n[`hast-util-parse-selector`][github-hast-util-parse-selector].\n\n###### `properties`\n\nProperties of the element\n([`Properties`][api-properties], optional).\n\n###### `children`\n\nChildren of the node ([`Child`][api-child] or `Array<Child>`, optional).\n\n##### Returns\n\nCreated tree ([`Result`][api-result]).\n\n[`Element`][github-hast-element] when a `selector` is passed,\notherwise [`Root`][github-hast-root].\n\n### `s(selector?[, properties][, …children])`\n\nCreate virtual **[hast][github-hast]** trees for SVG.\n\nSignatures, parameters, and return value are the same as `h` above.\nImportantly,\nthe `selector` and `properties` parameters are interpreted as SVG.\n\n### `Child`\n\n(Lists of) children (TypeScript type).\n\nWhen strings or numbers are encountered,\nthey are turned into [`Text`][github-hast-text]\nnodes.\n[`Root`][github-hast-root] nodes are treated as “fragments”,\nmeaning that their children are used instead.\n\n###### Type\n\n```ts\ntype Child =\n  | Array<Node | number | string | null | undefined>\n  | Node\n  | number\n  | string\n  | null\n  | undefined\n```\n\n### `Properties`\n\nMap of properties (TypeScript type).\nKeys should match either the HTML attribute name or the DOM property name,\nbut are case-insensitive.\n\n###### Type\n\n```ts\ntype Properties = Record<\n  string,\n  | boolean\n  | number\n  | string\n  | null\n  | undefined\n  // For comma- and space-separated values such as `className`:\n  | Array<number | string>\n  // Accepts value for `style` prop as object.\n  | Record<string, number | string>\n>\n```\n\n### `Result`\n\nResult from a `h` (or `s`) call (TypeScript type).\n\n###### Type\n\n```ts\ntype Result = Element | Root\n```\n\n## Syntax tree\n\nThe syntax tree is [hast][github-hast].\n\n## JSX\n\nThis package can be used with JSX.\nYou should use the automatic JSX runtime set to `hastscript` or\n`hastscript/svg`.\n\n> 👉 **Note**\n> while `h` supports dots (`.`) for classes or number signs (`#`)\n> for IDs in `selector`,\n> those are not supported in JSX.\n\n> 🪦 **Legacy**:\n> you can also use the classic JSX runtime,\n> but this is not recommended.\n> To do so,\n> import `h` (or `s`) yourself and define it as the pragma\n> (plus set the fragment to `null`).\n\nThe Use example above can then be written like so,\nusing inline pragmas,\nso that SVG can be used too:\n\n`example-html.jsx`:\n\n```js\n/** @jsxImportSource hastscript */\nconsole.log(\n  <div class=\"foo\" id=\"some-id\">\n    <span>some text</span>\n    <input type=\"text\" value=\"foo\" />\n    <a class=\"alpha bravo charlie\" download>\n      deltaecho\n    </a>\n  </div>\n)\n```\n\n`example-svg.jsx`:\n\n```js\n/** @jsxImportSource hastscript/svg */\nconsole.log(\n  <svg xmlns=\"http://www.w3.org/2000/svg\" viewbox=\"0 0 500 500\">\n    <title>SVG `&lt;circle&gt;` element</title>\n    <circle cx={120} cy={120} r={100} />\n  </svg>\n)\n```\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release,\nwe drop support for unmaintained versions of Node.\nThis means we try to keep the current release line,\n`hastscript@9`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hastscript` can open you up to a\n[cross-site scripting (XSS)][wikipedia-xss]\nwhen you pass user-provided input to it because values are injected into the\nsyntax tree.\n\nThe following example shows how an image is injected that fails loading and\ntherefore runs code in a browser.\n\n```js\nconst tree = h()\n\n// Somehow someone injected these properties instead of an expected `src` and\n// `alt`:\nconst otherProps = {onError: 'alert(1)', src: 'x'}\n\ntree.children.push(h('img', {src: 'default.png', ...otherProps}))\n```\n\nYields:\n\n```html\n<img onerror=\"alert(1)\" src=\"x\">\n```\n\nThe following example shows how code can run in a browser because someone stored\nan object in a database instead of the expected string.\n\n```js\nconst tree = h()\n\n// Somehow this isn’t the expected `'wooorm'`.\nconst username = {\n  type: 'element',\n  tagName: 'script',\n  children: [{type: 'text', value: 'alert(2)'}]\n}\n\ntree.children.push(h('span.handle', username))\n```\n\nYields:\n\n```html\n<span class=\"handle\"><script>alert(2)</script></span>\n```\n\nEither do not use user-provided input in `hastscript` or use\n[`hast-util-santize`][github-hast-util-sanitize].\n\n## Related\n\n* [`unist-builder`][github-unist-builder]\n  — create unist trees\n* [`xastscript`][github-xastscript]\n  — create xast trees\n* [`hast-to-hyperscript`](https://github.com/syntax-tree/hast-to-hyperscript)\n  — turn hast into React, Preact, Vue, etc\n* [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)\n  — turn hast into HTML\n* [`hast-util-to-dom`](https://github.com/syntax-tree/hast-util-to-dom)\n  — turn hast into DOM trees\n* [`estree-util-build-jsx`](https://github.com/syntax-tree/estree-util-build-jsx)\n  — compile JSX away\n\n## Contribute\n\nSee\n[`contributing.md`][health-contributing]\nin\n[`syntax-tree/.github`][health]\nfor ways to get started.\nSee [`support.md`][health-support] for ways to get help.\n\nThis project has a [code of conduct][health-coc].\nBy interacting with this repository,\norganization,\nor community you agree to abide by its terms.\n\n## License\n\n[MIT][file-license] © [Titus Wormer][wooorm]\n\n<!-- Definitions -->\n\n[api-child]: #child\n\n[api-h]: #hselector-properties-children\n\n[api-properties]: #properties-1\n\n[api-result]: #result\n\n[api-s]: #sselector-properties-children\n\n[badge-build-image]: https://github.com/syntax-tree/hastscript/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/syntax-tree/hastscript/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/hastscript.svg\n\n[badge-coverage-url]: https://codecov.io/github/syntax-tree/hastscript\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/hastscript.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/hastscript\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/hastscript\n\n[badge-size-url]: https://bundlejs.com/?q=hastscript\n\n[esmsh]: https://esm.sh\n\n[file-license]: license\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-hast]: https://github.com/syntax-tree/hast\n\n[github-hast-element]: https://github.com/syntax-tree/hast#element\n\n[github-hast-root]: https://github.com/syntax-tree/hast#root\n\n[github-hast-text]: https://github.com/syntax-tree/hast#text\n\n[github-hast-util-parse-selector]: https://github.com/syntax-tree/hast-util-parse-selector\n\n[github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[github-unist-builder]: https://github.com/syntax-tree/unist-builder\n\n[github-xastscript]: https://github.com/syntax-tree/xastscript\n\n[health]: https://github.com/syntax-tree/.github\n\n[health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[health-support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[npmjs-install]: https://docs.npmjs.com/cli/install\n\n[typescript]: https://www.typescriptlang.org\n\n[wikipedia-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[wooorm]: https://wooorm.com\n","publish_time":1793304604341,"_cnpm_publish_time":1793304604341,"dist-tags":{"latest":"9.0.3"}}