{"id":19382949,"url":"https://github.com/kenoxa/svelte-hyperscript","last_synced_at":"2025-04-23T20:32:35.606Z","repository":{"id":36972931,"uuid":"273775401","full_name":"kenoxa/svelte-hyperscript","owner":"kenoxa","description":"use hyperscript to create svelte components","archived":false,"fork":false,"pushed_at":"2023-06-01T03:23:18.000Z","size":523,"stargazers_count":8,"open_issues_count":17,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T13:19:01.101Z","etag":null,"topics":["hyperscript","javascript","svelte"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenoxa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-20T19:55:46.000Z","updated_at":"2024-08-29T12:39:43.000Z","dependencies_parsed_at":"2024-06-18T21:17:48.051Z","dependency_job_id":"39310602-8d97-4e0e-8cad-1e7b9ce36491","html_url":"https://github.com/kenoxa/svelte-hyperscript","commit_stats":{"total_commits":58,"total_committers":4,"mean_commits":14.5,"dds":0.3793103448275862,"last_synced_commit":"a3f14deaa04813c079cff8476ec67015943eba3d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-hyperscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-hyperscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-hyperscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-hyperscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenoxa","download_url":"https://codeload.github.com/kenoxa/svelte-hyperscript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250509891,"owners_count":21442517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hyperscript","javascript","svelte"],"created_at":"2024-11-10T09:23:58.870Z","updated_at":"2025-04-23T20:32:34.449Z","avatar_url":"https://github.com/kenoxa.png","language":"JavaScript","readme":"# svelte-hyperscript\n\n\u003e use [hyperscript](https://github.com/hyperhype/hyperscript) to create [svelte](https://svelte.dev/) components\n\n[![License](https://badgen.net/npm/license/svelte-hyperscript)](https://github.com/kenoxa/svelte-hyperscript/blob/main/LICENSE)\n[![Latest Release](https://badgen.net/npm/v/svelte-hyperscript)](https://www.npmjs.com/package/svelte-hyperscript)\n[![View changelog](https://badgen.net/badge/%E2%80%8B/Explore%20Changelog/green?icon=awesome)](https://changelogs.xyz/svelte-hyperscript)\n\n[![CI](https://github.com/kenoxa/svelte-hyperscript/workflows/CI/badge.svg)](https://github.comkenoxan/svelte-hyperscript/actions?query=branch%3Amain+workflow%3ACI)\n[![Coverage Status](https://badgen.net/coveralls/c/github/kenoxa/svelte-hyperscript/main)](https://coveralls.io/github/kenoxa/svelte-hyperscript?branch=main)\n[![PRs Welcome](https://badgen.net/badge/PRs/welcome/purple)](http://makeapullrequest.com)\n[![Conventional Commits](https://badgen.net/badge/Conventional%20Commits/1.0.0/cyan)](https://conventionalcommits.org)\n\n## What?\n\nThis package exposes an [hyperscript](https://github.com/hyperhype/hyperscript) compatible function: `h(tag, properties, ...children)` which returns a svelte component.\n\n## Why?\n\nThis is the core for [svelte-jsx] and [svelte-htm]. These packages allow to simplify svelte testing code especially slot handling.\n\n## Installation\n\n```sh\nnpm install svelte-hyperscript\n```\n\nAnd then import it:\n\n```js\n// using es modules\nimport h from 'svelte-hyperscript'\n\n// common.js\nconst h = require('svelte-hyperscript')\n```\n\nAlternatively use [UNPKG](https://unpkg.com/svelte-htm/) or [jsDelivr](https://cdn.jsdelivr.net/npm/svelte-htm/) packages:\n\nWith script tags and globals:\n\n```html\n\u003c!-- UNPKG --\u003e\n\u003cscript src=\"https://unpkg.com/svelte-hyperscript\"\u003e\u003c/script\u003e\n\n\u003c!-- jsDelivr --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/svelte-hyperscript\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  \u003c!-- And then grab it off the global like so: --\u003e\n  const h = svelteHyperscript\n\u003c/script\u003e\n```\n\nHotlinking from unpkg: _(no build tool needed!)_\n\n```js\nimport h from 'https://unpkg.com/svelte-hyperscript?module'\n```\n\n## Usage\n\n```js\nimport h from 'svelte-hyperscript'\n\nimport Button from '../src/Button.svelte'\n\nlet clicked = 0\nconst LabeledButton = h(Button, { 'on:click': () =\u003e (clicked += 1) }, h('span', null, 'Click Me!'))\n\nconst button = new LabeledButton({\n  target: document.body,\n})\n```\n\nThe above example written in [jsx] using [svelte-jsx]:\n\n```jsx\nimport Button from '../src/Button.svelte'\n\nlet clicked = 0\nconst LabeledButton = (\n  \u003cButton onClick={() =\u003e (clicked += 1)}\u003e\n    \u003cspan\u003eClick Me!\u003c/span\u003e\n  \u003c/Button\u003e\n)\n\nconst button = new LabeledButton({\n  target: document.body,\n})\n```\n\nor using [svelte-htm]:\n\n```js\nimport html from 'svelte-htm'\nimport Button from '../src/Button.svelte'\n\nlet clicked = 0\nconst LabeledButton = html`\u003c${Button} on:click=${() =\u003e (clicked += 1)}\u003e\u003cspan\u003eClick Me!\u003c/span\u003e\u003c//\u003e`\n\nconst button = new LabeledButton({\n  target: document.body,\n})\n```\n\n## API\n\nWe [aim to support](#feature-set) all svelte features. In some cases this is not possible due to the static nature of hyperscript. For those cases we provided feasible workarounds:\n\n### Using stores to allow reactivity\n\nTo allow reactivity the following properties accept a [writable store](https://svelte.dev/docs#svelte_store):\n\n- [bind:property](https://svelte.dev/docs#bind_element_property)\n- [bind:group](https://svelte.dev/docs#bind_group)\n- [bind:this](https://svelte.dev/docs#bind_this)\n- [\\\u003cslot let:name={value}\u003e](https://svelte.dev/docs#slot_let)\n\n[\\\u003cslot let:name={value}\u003e](https://svelte.dev/docs#slot_let) additionally accepts a function which is called with the current value.\n\nThis allows to for example to access the value if an input:\n\n```js\nimport { test } from '@jest/globals'\nimport { render } from '@testing-library/svelte'\nimport userEvent from '@testing-library/user-event'\n\nimport { writable, get } from 'svelte/store'\n\nimport h from 'svelte-hyperscript'\n\ntest('write into an input', () =\u003e {\n  const text = writable()\n  const { getByRole } = render(h('input', { 'bind:value': text }))\n\n  const input = getByRole('textbox')\n\n  await userEvent.type(input, 'some text')\n\n  expect(get(text)).toBe('some text')\n})\n```\n\nThe [tests](https://github.com/kenoxa/svelte-hyperscript/tree/main/src/__tests__) are a good source of how to use this feature.\n\n### Action factories\n\nThe [action feature](https://svelte.dev/docs#use_action) of svelte is supported but lacks the possibility to pass parameters to the action. This can still be achieved using a factory function as action:\n\n```js\nimport h from 'svelte-hyperscript'\n\nimport action from 'some-action-module'\n\nh('div', { 'use:action': (node) =\u003e action(node, parameters) })\n```\n\n## Related Projects\n\n- [svelte-jsx] - write svelte components using [jsx]\n- [svelte-htm] - [**H**yperscript **T**agged **M**arkup](https://www.npmjs.com/package/htm) for svelte\n- [svelte-fragment-component] - a utility component\n\n## Feature Set\n\n- [x] plain html children\n- [x] readable store children\n- [x] on:eventname\n- [x] on:eventname modifiers\n- [x] bind:property **but** using writable store\n  - [x] bind:property on components\n  - [x] bind:property on html elements\n  - [x] bind:group\n  - [x] bind:this\n- [x] use:action\n- [x] class:name\n- [ ] transition:fn\n- [ ] in:fn/out:fn\n- [x] `\u003cslot\u003e`\n  - [x] `\u003cslot name=\"name\"\u003e`\n  - [x] `\u003cslot let:name={setter}\u003e` **but** using setter or writable store\n  - [x] `\u003cslot let:name={property}\u003e{property}\u003c/slot\u003e` when using a writable store\n- [x] context propagation\n- [ ] svelte:self\n- [ ] svelte:component\n- [ ] svelte:window\n- [ ] svelte:body\n- [ ] svelte:head\n\n## Support\n\nThis project is free and open-source, so if you think this project can help you or anyone else, you may [star it on GitHub](https://github.com/kenoxa/svelte-hyperscript). Feel free to [open an issue](https://github.comkenoxan/svelte-hyperscript/issues) if you have any idea, question, or you've found a bug.\n\n## Contribute\n\nThanks for being willing to contribute!\n\n**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)\n\nWe are following the [Conventional Commits](https://www.conventionalcommits.org) convention.\n\n### Develop\n\n- `npm test`: Run test suite\n- `npm run build`: Generate bundles\n- `npm run lint`: Lints code\n\n## NPM Statistics\n\n[![NPM](https://nodei.co/npm/svelte-hyperscript.png)](https://nodei.co/npm/svelte-hyperscript/)\n\n## License\n\n`svelte-hyperscript` is open source software [licensed as MIT](https://github.com/kenoxa/svelte-hyperscript/blob/main/LICENSE).\n\n[jsx]: https://reactjs.org/docs/introducing-jsx.html\n[svelte-jsx]: https://www.npmjs.com/package/svelte-jsx\n[svelte-hyperscript]: https://www.npmjs.com/package/svelte-hyperscript\n[svelte-fragment-component]: https://www.npmjs.com/package/svelte-fragment-component\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-hyperscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenoxa%2Fsvelte-hyperscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-hyperscript/lists"}