{"name":"hastscript","version":"7.0.2","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","./html/jsx-runtime":"./html/jsx-runtime.js","./svg/jsx-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":{"@babel/core":"^7.0.0","@babel/plugin-syntax-jsx":"^7.0.0","@babel/plugin-transform-react-jsx":"^7.0.0","@types/babel__core":"^7.0.0","@types/tape":"^4.0.0","acorn":"^8.0.0","acorn-jsx":"^5.0.0","astring":"^1.0.0","c8":"^7.0.0","estree-util-build-jsx":"^2.0.0","prettier":"^2.0.0","remark-cli":"^9.0.0","remark-preset-wooorm":"^8.0.0","rimraf":"^3.0.0","svg-tag-names":"^3.0.0","tape":"^5.0.0","tsd":"^0.17.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","xo":"^0.42.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"{script/**,test/**,}*.d.ts\" \"lib/{core,html,index,runtime-html,runtime-svg,runtime,svg-case-sensitive-tag-names,svg}.d.ts\" && tsc && tsd && type-coverage","generate":"node script/generate-jsx && node script/build","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test/index.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js","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":"a0d3a070a4f01ab7df6c744ee85839a281060d0e","homepage":"https://github.com/syntax-tree/hastscript#readme","_id":"hastscript@7.0.2","_nodeVersion":"16.6.1","_npmVersion":"7.20.3","dist":{"integrity":"sha512-uA8ooUY4ipaBvKcMuPehTAB/YfFLSSzCwFSwT6ltJbocFUKH/GDHLN+tflq7lSRf9H86uOuxOFkh1KgIy3Gg2g==","shasum":"d811fc040817d91923448a28156463b2e40d590a","tarball":"http://registry-npm.ywwl.com/hastscript/download/hastscript-7.0.2.tgz","fileCount":35,"unpackedSize":37196,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhC++BCRA9TVsSAnZWagAALSQP/jcTtCPHimc7V+db58o+\n3tyWHeR4fFnzFlpUXRNkB09yeqrOpU9uAzdkcww8s2EF2vOPUdvlpA8lvA1v\nrFRwZk6m7J6p9GB7xDpAPe1II1frCji0Ac5tHuD52QFkyjtTatdoCxvmjkuw\nr4mE1Zvc2JRmDoaPQXkd8r9DgaLhC6M9GEehxWCXjusS9k0cHIHSAwusyGIf\nfEYRE6KXQDBRJuTo/8Ljy/pQYBsTL2TxwiJqQi5JdmeCYpRdhmlJD6S5eRv8\n5WNTF1q9cxWNptbiR3hbmOkCKXq90fBozUeBoT2lSthcM8wGpw6CX2yXh473\nksRzM8yW0nsAN5UfTroDU3/0UHU+/y+5oE2smRKenQfVJOUBwO/wjB1ZUZb1\n7iIO0ozmXgpK1Yj3TThxMgQuhamA5rO4kg+cj4OiYycTV/ldXOmQE+OZsK2p\nCLc10VdOA84ltF8zOScdRFRXVYtLPJL4ZfFGsMByLjuK3IECqbY1pCDC+w9U\nP7YYTndUWeDDT/4UCnHQNmahiaK2Ibcno8K8t5zI5jigbw87rml7SZH+BrVm\nyVXhD6dk9xCHXtThg1IhkpoNykzR9lnCXnmGWd15GksRK39+4sMg9MZAjlsC\nrqb+16b1pyFi5fKP59eZ3kkg4OBEcm6vCgujBFa6CAazlBb4ZUSqF6QtpqqR\nXyhK\r\n=Dk8B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB7iFycy8MIQwQge5yXMtwCs7riHYjm0oTtST4oCtUN+AiB3o24vDKchb2LXn70OpAcn3pIsgCqU+ULMethx/qjp1Q=="}],"size":10784,"noattachment":false,"key":"/hastscript/-/hastscript-7.0.2.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.0.2_1628172160820_0.306014928354319"},"_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":1628172161005,"_cnpm_publish_time":1628172161005,"dist-tags":{"latest":"9.0.3"}}