{"id":19018908,"url":"https://github.com/virtualstate/kdl","last_synced_at":"2025-09-06T18:32:23.060Z","repository":{"id":43758415,"uuid":"460691788","full_name":"virtualstate/kdl","owner":"virtualstate","description":"KDL Implementation for JSX nodes","archived":false,"fork":false,"pushed_at":"2022-10-17T10:13:29.000Z","size":959,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-17T00:50:10.357Z","etag":null,"topics":["deno","javascript","jsx","kdl","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/kdl-org/kdl","language":"TypeScript","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/virtualstate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-18T03:11:23.000Z","updated_at":"2024-11-01T19:43:26.000Z","dependencies_parsed_at":"2023-01-20T05:03:43.149Z","dependency_job_id":null,"html_url":"https://github.com/virtualstate/kdl","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstate%2Fkdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstate%2Fkdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstate%2Fkdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstate%2Fkdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virtualstate","download_url":"https://codeload.github.com/virtualstate/kdl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232137215,"owners_count":18477791,"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":["deno","javascript","jsx","kdl","typescript"],"created_at":"2024-11-08T20:10:10.623Z","updated_at":"2025-01-02T00:10:18.440Z","avatar_url":"https://github.com/virtualstate.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `@virtualstate/kdl`\n\n[KDL](https://github.com/kdl-org/kdl) Tooling for [JSX](https://github.com/virtualstate/focus)\n\n[//]: # (badges)\n\n### Support\n\n ![Node.js supported](https://img.shields.io/badge/node-%3E%3D16.0.0-blue) ![Deno supported](https://img.shields.io/badge/deno-%3E%3D1.17.0-blue) \n\n### Test Coverage\n\n ![96.54%25 lines covered](https://img.shields.io/badge/lines-96.54%25-brightgreen) ![96.54%25 statements covered](https://img.shields.io/badge/statements-96.54%25-brightgreen) ![93.24%25 functions covered](https://img.shields.io/badge/functions-93.24%25-brightgreen) ![90.54%25 branches covered](https://img.shields.io/badge/branches-90.54%25-brightgreen)\n\n[//]: # (badges)\n\n# Preparing queries\n\nQueries are not preformed as soon as they are created, but they are partially prepared. \nWhile the query runs, additional parts to the query will be included in as needed. \n\nTo prepare a query for a JSX node, import and use `prepare`\n\n```typescript jsx\nimport {prepare} from \"@virtualstate/kdl\";\n\nconst node = (\n    \u003cmain\u003e\n        \u003ch1\u003e@virtualstate/focus\u003c/h1\u003e\n        \u003cblockquote\u003eVersion: \u003cspan\u003e1.0.0\u003c/span\u003e\u003c/blockquote\u003e\n    \u003c/main\u003e\n);\n```\n\nThe first parameter, is the JSX node you want to query\nThe second parameter, is a string containing [KDL Query Language](https://github.com/kdl-org/kdl/blob/main/QUERY-SPEC.md)\n\n```typescript jsx\nconst result = prepare(\n    node,\n    `main blockquote \u003e span`\n);\n```\n\nThe result is an async object that can be resolved in many ways\n\nFirst, if used as a promise, will result in an array of matching JSX nodes\n\n```typescript jsx\nconst [span] = await result\nconsole.log(span); // Is the node for \u003cspan\u003e1.0.0\u003c/span\u003e\n```\n\nIf used as an async iterable, then snapshots of results can be accessed, allowing for earlier processing\nof earlier found JSX nodes\n\n```typescript jsx\nfor await (const [span] of result) {\n    if (!span) continue;\n    // We have at least one span!\n    console.log(span) // Is the node for \u003cspan\u003e1.0.0\u003c/span\u003e\n}\n```\n\nIf used as an iterable, and destructuring is used, the individual destructured values will\nbe async objects too, which can be used as a promise or async iterable\n\n```typescript jsx\nconst [firstSpan] = result;\nconst span = await firstSpan;\nconsole.log(span) // Is the node for \u003cspan\u003e1.0.0\u003c/span\u003e\n```\n```typescript jsx\nconst [firstSpan] = result;\nfor await (const span of firstSpan) {\n    console.log(span) // Is the node for \u003cspan\u003e1.0.0\u003c/span\u003e\n}\n```\n\nThe async object returned from prepare supports many array like operations, \nlike `.at`, `.filter`, `.map`, `.group`, `.flatMap`, and [more](https://github.com/virtualstate/promise/blob/143b070e298b3417ac13b891b818d567c7346522/src/split/type.ts#L104-L138)\n\nThese operations are performed on the individual snapshots yielded across the lifecycle of the query\n\nThe map operator is also available, which can be used to directly return information about the node found\n\n```typescript jsx\nconst [value] = await prepare(\n    node,\n    `main blockquote \u003e span =\u003e val()`\n);\n\nconsole.log(value); // Logs the content of the span \"1.0.0\"\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualstate%2Fkdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirtualstate%2Fkdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualstate%2Fkdl/lists"}