@lppedd/kotlinx-charset 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/kotlinx-charset-exported.d.ts +3 -0
- package/kotlinx-charset-exported.mjs +4370 -0
- package/kotlinx-charset-exported.mjs.map +1 -0
- package/package.json +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# kotlinx-charset
|
|
2
|
+
|
|
3
|
+
Charset support for Kotlin Multiplatform.
|
|
4
|
+
|
|
5
|
+
## core
|
|
6
|
+
|
|
7
|
+
The `core` module provides the building blocks to implement new charsets,
|
|
8
|
+
and to store them in a registry.
|
|
9
|
+
|
|
10
|
+
```kotlin
|
|
11
|
+
// Create an empty charset registry
|
|
12
|
+
private val registrar = XCharsetRegistrar()
|
|
13
|
+
|
|
14
|
+
// Register a new charset
|
|
15
|
+
registrar.registerCharset(YourCharset())
|
|
16
|
+
|
|
17
|
+
// Retrieve and use a charset
|
|
18
|
+
val charset = registrar.getCharset("yourCharsetName")
|
|
19
|
+
val decoder = charset.newDecoder()
|
|
20
|
+
val encoder = charset.newEncoder()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## ebcdic
|
|
24
|
+
|
|
25
|
+
The `ebcdic` module adds support for:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
IBM037
|
|
29
|
+
IBM930
|
|
30
|
+
IBM1047
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can register supported EBCDIC charsets to your `XCharsetRegistrar`
|
|
34
|
+
via the `provideCharsets` function.
|
|
35
|
+
|
|
36
|
+
```kotlin
|
|
37
|
+
import com.github.lppedd.kotlinx.charset.ebcdic.provideCharsets as provideEbcdicCharsets
|
|
38
|
+
|
|
39
|
+
// Your shared charset registry
|
|
40
|
+
private val registrar = XCharsetRegistrar()
|
|
41
|
+
|
|
42
|
+
provideEbcdicCharsets(registrar)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## exported
|
|
46
|
+
|
|
47
|
+
The `exported` module allows JS (and soon WebAssembly) consumers to decode bytes
|
|
48
|
+
and encode strings, using top-level functions exported via ECMAScript modules.
|
|
49
|
+
|
|
50
|
+
> [!TIP]
|
|
51
|
+
> If you are consuming kotlinx-charset from a Kotlin project, avoid using this module
|
|
52
|
+
|
|
53
|
+
For example, consuming the library from TypeScript would look like:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { decode, encode } from "@lppedd/kotlinx-charset";
|
|
57
|
+
|
|
58
|
+
function example(toDecode: Uint8Array): void {
|
|
59
|
+
const str = decode(toDecode);
|
|
60
|
+
const bytes = encode(str);
|
|
61
|
+
}
|
|
62
|
+
```
|