{"name":"hastscript","version":"7.2.0","description":"hast utility to create trees","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","rehype","vdom","virtual","dom","hyperscript","dsl"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hastscript.git"},"bugs":{"url":"https://github.com/syntax-tree/hastscript/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","exports":{".":"./index.js","./index.js":"./index.js","./html.js":"./html.js","./svg.js":"./svg.js","./jsx-runtime":"./jsx-runtime.js","./jsx-dev-runtime":"./jsx-runtime.js","./html/jsx-runtime":"./html/jsx-runtime.js","./html/jsx-dev-runtime":"./html/jsx-runtime.js","./svg/jsx-runtime":"./svg/jsx-runtime.js","./svg/jsx-dev-runtime":"./svg/jsx-runtime.js"},"dependencies":{"@types/hast":"^2.0.0","comma-separated-tokens":"^2.0.0","hast-util-parse-selector":"^3.0.0","property-information":"^6.0.0","space-separated-tokens":"^2.0.0"},"devDependencies":{"@types/node":"^18.0.0","acorn-jsx":"^5.0.0","c8":"^7.0.0","esast-util-from-js":"^1.0.0","estree-util-build-jsx":"^2.0.0","estree-util-to-js":"^1.0.0","prettier":"^2.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","svg-tag-names":"^3.0.0","tsd":"^0.25.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","xo":"^0.53.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && tsd && type-coverage","generate":"node script/generate-jsx.js && node script/build.js","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --check-coverage --100 --reporter lcov npm run test-api","test":"npm run build && npm run generate && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true},"gitHead":"8e1381fca8327a151386c1cf9836938fc7a8794e","homepage":"https://github.com/syntax-tree/hastscript#readme","_id":"hastscript@7.2.0","_nodeVersion":"19.3.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-TtYPq24IldU8iKoJQqvZOuhi5CyCQRAbvDOX0x1eW6rsHSxa/1i2CCiptNTotGHJ3VoHRGmqiv6/D3q113ikkw==","shasum":"0eafb7afb153d047077fa2a833dc9b7ec604d10b","tarball":"http://registry-npm.ywwl.com/hastscript/download/hastscript-7.2.0.tgz","fileCount":35,"unpackedSize":41979,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCzKME/fRsHEftYESnsXwp1zpXOZISA7U2vuyT5WPYvjgIgRTZStVHpgqyu3hPA6fbemUouhN6sj/H0CMaUY0rFlOE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjtcOeACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpiXBAAjEe51AASfGjvqnTlYbW1aX8vN42cZgNxvZH1ZBjiKjGcyPNe\r\nXfxUcPDvP1BXBLOz346v26hbmIoH9Lhw4Qn/X8qLh76Ol+Xw6ESHD9g6BiWx\r\nClVMyrTecQMr8fMBoyBeOY+OMD61rIPHfkP/2KLooSDBnsyhtaZBLw9gXG27\r\nimJvlS7Z2AKHI2KQvSljyrCUbQcq/4aslxXN2okm9DwQk0QaFw+dZNh+M4r1\r\nJoQM9HxY4u6w+EB6s3dcS5gszUBVwKvqFrXSvFwzhEsh7tyGzYjyrfUWkBdc\r\njVrXTxUsEmKt3XgwJmaLO/s3JoMTzWD7I6DWri81J0BBMxhXBwmHVigJ/721\r\n0WsSP38omIDGIb1tGwXhVBVFR9Webwlz9kTk/EK3Zt6sDIWkjDgmDF8PdJqP\r\njIfs9CrSNdv0P+NwX+K4E/ph8PYaQepYRcbKhxWC63k0w2z3iEjaqgI/lduz\r\n0a2C2luUGQ+GZUHfOd6KcHdJqBc+h20O6JNf63K/KdGE719w+jH7NANRdpFT\r\nl/qCpjtnPMjNHAKkv960ZC3ezgVVj2JAqGG/thmwNJouj/W2HiJn3EDe5M28\r\n2hnpdgDfWItt5FzApEPRHubfAoIL9g7VGx/my3IkWYDTdo+I8MXH8Bb0RlTX\r\nn3+UozVtciGiXgyPLHlh8XtU2RQkKmiEBwI=\r\n=1BLj\r\n-----END PGP SIGNATURE-----\r\n","size":11503,"noattachment":false,"key":"/hastscript/-/hastscript-7.2.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hastscript_7.2.0_1672856477814_0.6416490749656081"},"_hasShrinkwrap":false,"readme":"# hastscript\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[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*   [Types](#types)\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`][u] when creating any unist nodes and\n[`xastscript`][x] when creating xast (XML) nodes.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hastscript\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {h} from 'https://esm.sh/hastscript@9'\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', {xmlns: 'http://www.w3.org/2000/svg', viewbox: '0 0 500 500'}, [\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: {xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 500 500'},\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.\n\nThe export map supports the automatic JSX runtime.\nYou can pass `hastscript` or `hastscript/svg` to your build tool (TypeScript,\nBabel, SWC) with an `importSource` option or similar.\n\n### `h(selector?[, properties][, …children])`\n\nCreate virtual **[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 (`string`, optional).\nCan contain a tag name (`foo`), IDs (`#bar`), and classes (`.baz`).\nIf the selector is a string but there is no tag name in it, `h` defaults to\nbuild a `div` element, and `s` to a `g` element.\n`selector` is parsed by [`hast-util-parse-selector`][parse-selector].\nWhen string, builds an [`Element`][element].\nWhen nullish, builds a [`Root`][root] instead.\n\n###### `properties`\n\nProperties of the element ([`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`][element] when a `selector` is passed, otherwise [`Root`][root].\n\n### `s(selector?[, properties][, …children])`\n\nCreate virtual **[hast][]** trees for SVG.\n\nSignatures, parameters, and return value are the same as `h` above.\nImportantly, the `selector` and `properties` parameters are interpreted as\nSVG.\n\n### `Child`\n\n(Lists of) children (TypeScript type).\n\nWhen strings or numbers are encountered, they are turned into [`Text`][text]\nnodes.\n[`Root`][root] nodes are treated as “fragments”, meaning that their children\nare 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, but\nare 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][].\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**: while `h` supports dots (`.`) for classes or number signs (`#`)\n> for IDs in `selector`, those are not supported in JSX.\n\n> 🪦 **Legacy**: you can also use the classic JSX runtime, but this is not\n> recommended.\n> To do so, import `h` (or `s`) yourself and define it as the pragma (plus\n> set the fragment to `null`).\n\nThe Use example above can then be written like so, using inline pragmas, so\nthat SVG can be used too:\n\n`example-html.jsx`:\n\n```jsx\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```jsx\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## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Child`][api-child],\n[`Properties`][api-properties], and\n[`Result`][api-result].\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, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `hastscript@^9`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `hastscript` can open you up to a [cross-site scripting (XSS)][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 = {src: 'x', onError: 'alert(1)'}\n\ntree.children.push(h('img', {src: 'default.png', ...otherProps}))\n```\n\nYields:\n\n```html\n<img src=\"x\" onerror=\"alert(1)\">\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`][hast-util-sanitize].\n\n## Related\n\n*   [`unist-builder`](https://github.com/syntax-tree/unist-builder)\n    — create unist trees\n*   [`xastscript`](https://github.com/syntax-tree/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 [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/hastscript/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hastscript/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hastscript.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hastscript\n\n[downloads-badge]: https://img.shields.io/npm/dm/hastscript.svg\n\n[downloads]: https://www.npmjs.com/package/hastscript\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hastscript\n\n[size]: https://bundlejs.com/?q=hastscript\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[hast]: https://github.com/syntax-tree/hast\n\n[element]: https://github.com/syntax-tree/hast#element\n\n[root]: https://github.com/syntax-tree/xast#root\n\n[text]: https://github.com/syntax-tree/hast#text\n\n[u]: https://github.com/syntax-tree/unist-builder\n\n[x]: https://github.com/syntax-tree/xastscript\n\n[parse-selector]: https://github.com/syntax-tree/hast-util-parse-selector\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[api-h]: #hselector-properties-children\n\n[api-s]: #sselector-properties-children\n\n[api-child]: #child\n\n[api-properties]: #properties-1\n\n[api-result]: #result\n","publish_time":1672856478028,"_cnpm_publish_time":1672856478028,"dist-tags":{"latest":"9.0.3"}}