{"name":"hastscript","version":"3.0.0","description":"Hyperscript compatible DSL for creating virtual HAST trees","license":"MIT","keywords":["hast","rehype","vdom","virtual","dom","hyperscript","dsl","html"],"files":["index.js"],"repository":{"type":"git","url":"git+https://github.com/wooorm/hastscript.git"},"bugs":{"url":"https://github.com/wooorm/hastscript/issues"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"}],"dependencies":{"camelcase":"^3.0.0","comma-separated-tokens":"^1.0.0","hast-util-parse-selector":"^2.0.0","property-information":"^3.0.0","space-separated-tokens":"^1.0.0"},"devDependencies":{"browserify":"^13.0.0","eslint":"^2.0.0","esmangle":"^1.0.0","hast":"0.0.2","istanbul":"^0.4.0","jscs":"^3.0.0","jscs-jsdoc":"^2.0.0","remark-cli":"^1.0.0","remark-comment-config":"^4.0.0","remark-github":"^5.0.0","remark-lint":"^4.0.0","remark-usage":"^4.0.0","remark-validate-links":"^4.0.0","tape":"^4.0.0"},"scripts":{"build-md":"remark . --quiet --frail","build-bundle":"browserify index.js --bare -s hastscript > hastscript.js","build-mangle":"esmangle hastscript.js > hastscript.min.js","build":"npm run build-md && npm run build-bundle && npm run build-mangle","lint-api":"eslint .","lint-style":"jscs --reporter inline .","lint":"npm run lint-api && npm run lint-style","test-api":"node test.js","test-coverage":"istanbul cover test.js","test":"npm run build && npm run lint && npm run test-coverage"},"gitHead":"d558e6c726974064051a1c75c688ed349da8e217","homepage":"https://github.com/wooorm/hastscript#readme","_id":"hastscript@3.0.0","_shasum":"6fa65452bf67f1bc9e4f11e5481e8eb0f65e2ae8","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.0.0","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"dist":{"shasum":"6fa65452bf67f1bc9e4f11e5481e8eb0f65e2ae8","tarball":"http://registry-npm.ywwl.com/hastscript/download/hastscript-3.0.0.tgz","integrity":"sha512-ihuCFsPPy5cuIvQfobcmlOCbwE8rduKOjUUqjmZD4vD8Ku1a26z1ycoszsPQuUSeyv/fq/L6l4vkQuRvQo12WA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDbEgJq8MD4PUHHLbkG5rXMg6jh3cRiPnkBS63bgS7IIAiBCZzq3kfy9ggB+OQVugxiLUMqRaVG44MHu7SzqGlNqYg=="}],"size":3729,"noattachment":false,"key":"/hastscript/-/hastscript-3.0.0.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/hastscript-3.0.0.tgz_1465937725747_0.23100639740005136"},"directories":{},"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":1465937728643,"_cnpm_publish_time":1465937728643,"dist-tags":{"latest":"9.0.3"}}