Skip to content

Commit 9f285e1

Browse files
committed
docs: add doc for js encoding api
- docs(js): add doc for `TextEncoder` - docs(js): add doc for `TextDecoder` Relates-To: elide-dev/elide#1044 Signed-off-by: Sam Gammon <[email protected]>
1 parent 79465f8 commit 9f285e1

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

Writerside/e.tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
<toc-element toc-title="Worker threads" />
6262
<toc-element toc-title="Zlib" />
6363
</toc-element>
64-
<toc-element toc-title="Web APIs">
64+
<toc-element toc-title="Web &amp; JavaScript APIs">
65+
<toc-element topic="JavaScript-Encoding-API.md"/>
6566
<toc-element toc-title="Fetch API" />
6667
<toc-element toc-title="URL API" />
6768
<toc-element toc-title="Web Crypto API" />
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Encoding API
2+
3+
Elide supports the standard JavaScript types [`TextEncoder`](#textencoder) and [`TextDecoder`](#textdecoder). These
4+
classes can be used to obtain byte-arrays of strings in different encodings, or to obtain strings from byte arrays with
5+
different encodings.
6+
7+
## Supported Encodings
8+
9+
Elide supports several encodings via the `TextEncoder` and `TextDecoder` constructors:
10+
11+
| Support | Charset | Encoding (Label) | Notes |
12+
|-----------------------|------------------|------------------|------------------|
13+
| 🟢 Supported. | `ISO_8859_1` | `iso-8859-1` | |
14+
| 🟢 Supported. | `ASCII` | `ascii` | |
15+
| 🟢 Supported. | `UTF_8` | `utf-8` | Default encoding |
16+
| 🔴 Not supported yet. | `UTF_16` | `utf-16` | |
17+
| 🔴 Not supported yet. | `UTF_32` | `utf-32` | |
18+
| 🔴 Not supported yet. | (Other charsets) | | |
19+
20+
## Encoding API | Classes
21+
22+
[`TextEncoder`](#textencoder) Encode strings into byte array representations
23+
: 🟢 Supported.
24+
25+
[`TextDecoder`](#textdecoder) Decode byte arrays into string representations
26+
: 🟢 Supported.
27+
28+
## `TextEncoder`
29+
30+
```Javascript
31+
// create an encoder; by default, it uses utf-8
32+
const encoder = new TextEncoder();
33+
encoder.encoding // returns 'utf-8'
34+
encoder.encode("hello") // returns `Uint8Array([...])`
35+
```
36+
37+
The `TextEncoder` class behaves very similarly to how it behaves in a browser, or under Node.js; the only difference is
38+
that Elide supports additional encodings, on top of the default, which is `utf-8`.
39+
40+
> Read more about [`TextEncoder` on MDN](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder)
41+
42+
### `TextEncoder` Properties
43+
44+
[`TextEncoder.encoding`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encoding)
45+
: 🟢 Supported.
46+
47+
### `TextEncoder` Methods
48+
49+
[`TextEncoder.encode`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encode)
50+
: 🟢 Supported.
51+
52+
[`TextEncoder.encodeInto`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto)
53+
: 🟢 Supported.
54+
55+
## `TextDecoder`
56+
57+
```Javascript
58+
// create a decoder; by default, it uses utf-8
59+
const decoder = new TextDecoder();
60+
decoder.encoding // returns 'utf-8'
61+
const input = new Uint8Array([104, 101, 108, 108, 111]);
62+
decoder.decode(input) // returns 'hello'
63+
```
64+
65+
The `TextDecoder` class behaves identically to how it behaves in a browser, or under Node.js.
66+
67+
> Read more about [`TextDecoder` on MDN](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder)
68+
69+
### `TextDecoder` Properties
70+
71+
[`TextDecoder.encoding`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding)
72+
: 🟢 Supported.
73+
74+
### `TextDecoder` Methods
75+
76+
[`TextDecoder.decode`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)
77+
: 🟢 Supported.

Writerside/topics/javascript-sqlite.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ switcher-label: Imports
66

77
<tldr>
88
<p>Module: <code>elide:sqlite</code></p>
9-
<p>Support: <img style="inline" src="https://img.shields.io/badge/-beta-purple" /></p>
9+
<p>Support: <img style="inline" src="https://img.shields.io/badge/-beta-purple" alt="beta" /></p>
1010
<p>Docs: <a href="https://bun.sh/docs/api/sqlite">Bun SQLite Docs</a></p>
1111
</tldr>
1212

@@ -28,6 +28,10 @@ db.query("SELECT * FROM test;").get()["name"]
2828
> Bindings are on the way for Python and Ruby.
2929
> {style="note"}
3030
31+
## SQLite Examples
32+
33+
Coming soon.
34+
3135
## `sqlite` | Classes
3236

3337
[`Database`](https://bun.sh/docs/api/sqlite#database)

0 commit comments

Comments
 (0)