@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 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
+ ```
@@ -0,0 +1,3 @@
1
+ type Nullable<T> = T | null | undefined
2
+ export declare function decode(charsetName: string, bytes: Uint8Array): string;
3
+ export declare function encode(charsetName: string, value: string): Uint8Array;