{"id":23366718,"url":"https://github.com/d8corp/innet-switch","last_synced_at":"2025-08-14T18:33:27.321Z","repository":{"id":57118745,"uuid":"461523056","full_name":"d8corp/innet-switch","owner":"d8corp","description":"Innet jsx plugin to switch elements inside","archived":false,"fork":false,"pushed_at":"2022-02-22T09:48:58.000Z","size":94,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T12:36:36.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/d8corp.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}},"created_at":"2022-02-20T15:04:56.000Z","updated_at":"2022-02-22T09:48:44.000Z","dependencies_parsed_at":"2022-08-22T22:20:53.592Z","dependency_job_id":null,"html_url":"https://github.com/d8corp/innet-switch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Finnet-switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Finnet-switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Finnet-switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Finnet-switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d8corp","download_url":"https://codeload.github.com/d8corp/innet-switch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744329,"owners_count":20988783,"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":[],"created_at":"2024-12-21T14:17:25.063Z","updated_at":"2025-04-07T23:16:07.928Z","avatar_url":"https://github.com/d8corp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://www.npmjs.com/package/innet\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/d8corp/innet/main/logo.svg\" align=\"left\" width=\"90\" height=\"90\" alt=\"InnetJs logo by Mikhail Lysikov\"\u003e\n\u003c/a\u003e\n\n# \u0026nbsp; @innet/switch\n\n\u0026nbsp;\n\n[![NPM](https://img.shields.io/npm/v/@innet/switch.svg)](https://www.npmjs.com/package/@innet/switch)\n[![downloads](https://img.shields.io/npm/dm/@innet/switch.svg)](https://www.npmtrends.com/@innet/switch)\n[![changelog](https://img.shields.io/badge/Changelog-⋮-brightgreen)](https://changelogs.xyz/@innet/switch)\n[![license](https://img.shields.io/npm/l/@innet/switch)](https://github.com/d8corp/innet-switch/blob/main/LICENSE)\n\n## Abstract\n`switch` is a [jsx plugin](https://www.npmjs.com/package/@innet/jsx).  \nIt helps to select the first children that does not return `undefined`.\n\n[![stars](https://img.shields.io/github/stars/d8corp/innet-switch?style=social)](https://github.com/d8corp/innet-switch/stargazers)\n[![watchers](https://img.shields.io/github/watchers/d8corp/innet-switch?style=social)](https://github.com/d8corp/innet-switch/watchers)\n\n## Install\nnpm\n```bash\nnpm i @innet/switch\n```\nyarn\n```bash\nyarn add @innet/switch\n```\n\n## switchSync\nUse it if you do not want to handle promises.\n\n```typescript jsx\nimport innet, { createHandler } from 'innet'\nimport { switchSync } from '@innet/switch'\nimport { jsxPlugins } from '@innet/jsx'\nimport { object } from '@innet/utils'\n\nconst handler = createHandler([\n  object([\n    jsxPlugins({\n      switch: switchSync,\n    }),\n  ]),\n])\n\nconst app = (\n  \u003cswitch\u003e\n    {undefined}\n    test1\n    {'test2'}\n  \u003c/switch\u003e\n)\n\ninnet(app, handler)\n// 'test1'\n```\n\n## switchAsync\nUse it when you want to handle promises.  \nIt waits while a promise ends and the continues the checking.\n\n```typescript jsx\nimport innet, { createHandler } from 'innet'\nimport { switchAsync } from '@innet/switch'\nimport { jsxPlugins } from '@innet/jsx'\nimport { object } from '@innet/utils'\n\nconst handler = createHandler([\n  object([\n    jsxPlugins({\n      switch: switchAsync,\n    }),\n  ]),\n])\n\nconst app = (\n  \u003cswitch\u003e\n    {undefined}\n    {new Promise(resolve =\u003e resolve('test1'))}\n    {'test2'}\n  \u003c/switch\u003e\n)\n\nawait innet(app, handler)\n// 'test1'\n```\n\nChange `resolve('test1')` to `resolve(undefined)` and you get `test2`\n\n## Issues\nIf you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-switch/issues).\n\n[![issues](https://img.shields.io/github/issues-raw/d8corp/innet-switch)](https://github.com/d8corp/innet-switch/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd8corp%2Finnet-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd8corp%2Finnet-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd8corp%2Finnet-switch/lists"}