{"id":15658922,"url":"https://github.com/ije/deno-lol-html","last_synced_at":"2025-05-05T17:04:07.199Z","repository":{"id":62422543,"uuid":"457923388","full_name":"ije/deno-lol-html","owner":"ije","description":"The Low Output Latency streaming HTML rewriter/parser with CSS-selector based API, in Webassembly.","archived":false,"fork":false,"pushed_at":"2023-12-18T03:17:54.000Z","size":2581,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T22:32:19.167Z","etag":null,"topics":[],"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/ije.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-02-10T19:43:22.000Z","updated_at":"2024-09-08T03:26:15.000Z","dependencies_parsed_at":"2024-10-23T05:49:07.839Z","dependency_job_id":"f612480e-51a3-4bfc-a655-1ca6c99ff500","html_url":"https://github.com/ije/deno-lol-html","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"5a8c23f69af79dd42ed67eaf76706c966ff1f2b6"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ije%2Fdeno-lol-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ije%2Fdeno-lol-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ije%2Fdeno-lol-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ije%2Fdeno-lol-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ije","download_url":"https://codeload.github.com/ije/deno-lol-html/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542059,"owners_count":21764907,"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-10-03T13:14:25.825Z","updated_at":"2025-05-05T17:04:07.150Z","avatar_url":"https://github.com/ije.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LOL(😂) HTML\n\nWasm bindings of [cloudflare/lol-html](https://github.com/cloudflare/lol-html) for Deno, the Low Output\nLatency streaming HTML rewriter/parser with CSS-selector based API, in\nWebassembly.\n\n\u003e The wasm bindings code is based on\n\u003e https://github.com/cloudflare/lol-html/pull/100 by @devsnek\n\n## Documentation\n\nSee https://developers.cloudflare.com/workers/runtime-apis/html-rewriter\n\n## Example\n\n```ts\nimport { concat } from \"https://deno.land/std@0.200.0/bytes/mod.ts\";\nimport init, { HTMLRewriter } from \"https://deno.land/x/lol_html@0.1.0/mod.ts\";\n\nawait init();\n\nconst enc = new TextEncoder();\nconst dec = new TextDecoder();\nconst chunks: Uint8Array[] = [];\nconst parts = [\n  \"\u003ch1\u003e\u003ca href=\",\n  '\"https://lol-html.fun\"\u003e',\n  \"LOL(:lol) HTML\u003c/\",\n  \"a\u003e\u003c/h1\u003e\",\n];\n\nconst rewriter = new HTMLRewriter(\"utf8\", (chunk: Uint8Array) =\u003e {\n  chunks.push(chunk);\n});\n\n// add handlers before calling `write` or `end`\nrewriter.on(\"a[href]\", {\n  element(el) {\n    el.setAttribute(\"class\", \"this-is-a-link\");\n  },\n  text(chunk) {\n    chunk.replace(chunk.text.replaceAll(\":lol\", \"😂\"));\n  },\n});\n\ntry {\n  for (const part of parts) {\n    rewriter.write(enc.encode(part));\n  }\n  rewriter.end();\n  console.log(dec.decode(concat(...chunks)));\n} finally {\n  // don't forget to free the memory\n  rewriter.free();\n}\n```\n\n## Using Stream\n\nThe wasm binding version doesn't implement the `transform` method in the [docs](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter), you can use\nthe `ReadableStream` instead.\n\n```ts\nimport { serve } from \"https://deno.land/std@0.170.0/http/server.ts\";\nimport init, { HTMLRewriter } from \"https://deno.land/x/lol_html@0.1.0/mod.ts\";\n\nawait init();\n\nserve(() =\u003e {\n  const readable = new ReadableStream({\n    async start(controller) {\n      const rewriter = new HTMLRewriter(\"utf8\", (chunk: Uint8Array) =\u003e {\n        controller.enqueue(chunk);\n      });\n      const res = await fetch(\"https://lol-html.fun\");\n      const pump = async () =\u003e {\n        const { done, value } = await res.body!.read();\n        if (done) {\n          controller.close();\n          try {\n            rewriter.end();\n          } finally {\n            rewriter.free();\n          }\n          return;\n        }\n        rewriter.write(value!);\n        pump();\n      };\n      pump();\n    },\n  });\n  return new Response(readable, {\n    headers: { \"content-type\": \"text/html\" },\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fije%2Fdeno-lol-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fije%2Fdeno-lol-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fije%2Fdeno-lol-html/lists"}