Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takker99/data-url-js
Convert Blob to Data URL in Deno/Web browsers
https://github.com/takker99/data-url-js
Last synced: about 11 hours ago
JSON representation
Convert Blob to Data URL in Deno/Web browsers
- Host: GitHub
- URL: https://github.com/takker99/data-url-js
- Owner: takker99
- License: mit
- Created: 2024-11-08T08:09:29.000Z (9 days ago)
- Default Branch: main
- Last Pushed: 2024-11-08T08:25:13.000Z (9 days ago)
- Last Synced: 2024-11-08T09:28:05.465Z (9 days ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @takker/data-url
[![JSR](https://jsr.io/badges/@takker/data-url)](https://jsr.io/@takker/data-url)
[![test](https://github.com/takker99/data-url-js/workflows/ci/badge.svg)](https://github.com/takker99/data-url-js/actions?query=workflow%3Aci)Convert [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob) to
[Data URL](https://developer.mozilla.org/docs/Web/URI/Schemes/data) in Deno/Web
browsers## Usage
```ts
import { assertEquals } from "@std/assert/equals";
import { toDataURL } from "@takker/data-url";const blob = new Blob(["Test data"], { type: "text/plain" });
const result = await toDataURL(blob);
assertEquals(result, "data:text/plain;base64,VGVzdCBkYXRh");
```Abort a covertion before it completes:
```ts
import { assertRejects } from "@std/assert/rejects";
import { toDataURL } from "@takker/data-url";const controller = new AbortController();
const blob = new Blob(["Test data"], { type: "text/plain" });
const promise = toDataURL(blob, controller.signal);
controller.abort();
await assertRejects(() => promise, controller.signal.reason);
```