@lppedd/kotlinx-charset 0.1.4 → 0.1.5
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/LICENSE +21 -21
- package/README.md +111 -108
- package/kotlinx-charset-exported.mjs +280 -196
- package/kotlinx-charset-exported.mjs.map +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Edoardo Luppi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Edoardo Luppi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,108 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[](https://mvnrepository.com/artifact/com.lppedd.kotlinx-charset)
|
|
7
|
+
[](https://www.npmjs.com/package/@lppedd/kotlinx-charset)
|
|
8
|
+
[](https://kotlinlang.org)
|
|
9
|
+
[](https://github.com/lppedd/kotlinx-charset/actions/workflows/build.yml)
|
|
10
|
+
[](./LICENSE)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
### Changelog
|
|
15
|
+
|
|
16
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
17
|
+
|
|
18
|
+
### Supported Kotlin platforms
|
|
19
|
+
|
|
20
|
+
All Kotlin platforms are supported, except for Android Native.
|
|
21
|
+
|
|
22
|
+
### Design considerations
|
|
23
|
+
|
|
24
|
+
**kotlinx-charset** aims to be straightforward for existing JDK consumers.
|
|
25
|
+
It replicates parts of the JDK's `Charset` API, albeit with more restrictions.
|
|
26
|
+
|
|
27
|
+
The core types you will work with are:
|
|
28
|
+
|
|
29
|
+
- `XCharset` - describes a character set
|
|
30
|
+
- `XCharsetDecoder` - decodes a byte sequence into characters
|
|
31
|
+
- `XCharsetEncoder` - encodes characters into a byte sequence
|
|
32
|
+
- `XCharsetRegistrar` - a registry and lookup service for obtaining `XCharset` instances
|
|
33
|
+
|
|
34
|
+
## core
|
|
35
|
+
|
|
36
|
+
The `core` module provides the foundational components for implementing
|
|
37
|
+
and registering new charsets.
|
|
38
|
+
|
|
39
|
+
```kotlin
|
|
40
|
+
// Create an empty charset registry
|
|
41
|
+
private val registrar = XCharsetRegistrar()
|
|
42
|
+
|
|
43
|
+
// Register a new charset
|
|
44
|
+
registrar.registerCharset(YourCharset())
|
|
45
|
+
|
|
46
|
+
// Retrieve and use a charset
|
|
47
|
+
val charset = registrar.getCharset("YourCharsetName")
|
|
48
|
+
val decoder = charset.newDecoder()
|
|
49
|
+
val encoder = charset.newEncoder()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## ebcdic
|
|
53
|
+
|
|
54
|
+
The `ebcdic` module adds support for:
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
IBM037 IBM930 IBM1143
|
|
58
|
+
IBM273 IBM939 IBM1147
|
|
59
|
+
IBM278 IBM1047 IBM1390
|
|
60
|
+
IBM297 IBM1141 IBM1399
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
You can register supported EBCDIC charsets to your `XCharsetRegistrar`
|
|
64
|
+
via the `provideCharsets` function.
|
|
65
|
+
|
|
66
|
+
```kotlin
|
|
67
|
+
import com.lppedd.kotlinx.charset.ebcdic.provideCharsets as provideEbcdicCharsets
|
|
68
|
+
|
|
69
|
+
// Your shared charset registry
|
|
70
|
+
private val registrar = XCharsetRegistrar()
|
|
71
|
+
|
|
72
|
+
provideEbcdicCharsets(registrar)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## exported
|
|
76
|
+
|
|
77
|
+
The `exported` module allows JS (and soon WebAssembly) consumers to decode bytes
|
|
78
|
+
and encode strings, using top-level functions exported via ECMAScript modules.
|
|
79
|
+
|
|
80
|
+
> [!TIP]
|
|
81
|
+
> Avoid using this module when consuming `kotlinx-charset` from a Kotlin project
|
|
82
|
+
|
|
83
|
+
You can depend on the [@lppedd/kotlinx-charset][npm] npm package.
|
|
84
|
+
For example, consuming the library from TypeScript would look like:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { decode, encode, getCharset } from "@lppedd/kotlinx-charset";
|
|
88
|
+
|
|
89
|
+
function funsExample(bytes: Uint8Array): Uint8Array {
|
|
90
|
+
const str = decode("ibm037", bytes);
|
|
91
|
+
return encode("ibm037", str);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Alternatively, you can interact with a charset instance directly.
|
|
95
|
+
// This allows setting or removing (by passing null) the replacement character.
|
|
96
|
+
function instanceExample(bytes: Uint8Array): Uint8Array {
|
|
97
|
+
const charset = getCharset("ibm037");
|
|
98
|
+
|
|
99
|
+
const decoder = charset.newDecoder();
|
|
100
|
+
const str = decoder.decode(bytes);
|
|
101
|
+
|
|
102
|
+
const encoder = charset.newEncoder();
|
|
103
|
+
return encoder.encode(str);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Both the `decode` and `encode` functions will throw an `Error`
|
|
108
|
+
if the specified charset does not exist or if an error occurs
|
|
109
|
+
during data processing.
|
|
110
|
+
|
|
111
|
+
[npm]: https://www.npmjs.com/package/@lppedd/kotlinx-charset
|