@lppedd/kotlinx-charset 0.0.2 → 0.0.4
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 -0
- package/README.md +32 -7
- package/kotlinx-charset-exported.d.ts +27 -1
- package/kotlinx-charset-exported.mjs +652 -337
- package/kotlinx-charset-exported.mjs.map +1 -1
- package/package.json +19 -1
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
# kotlinx-charset
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
3
7
|
Minimal charset support for Kotlin Multiplatform.
|
|
4
8
|
|
|
9
|
+
### Changelog
|
|
10
|
+
|
|
11
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
12
|
+
|
|
13
|
+
### Supported Kotlin platforms
|
|
14
|
+
|
|
15
|
+
All Kotlin platforms are supported, except for Android.
|
|
16
|
+
|
|
5
17
|
## core
|
|
6
18
|
|
|
7
19
|
The `core` module provides the foundational components for implementing
|
|
@@ -25,9 +37,10 @@ val encoder = charset.newEncoder()
|
|
|
25
37
|
The `ebcdic` module adds support for:
|
|
26
38
|
|
|
27
39
|
```text
|
|
28
|
-
IBM037
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
IBM037 IBM939
|
|
41
|
+
IBM273 IBM1047
|
|
42
|
+
IBM297 IBM1141
|
|
43
|
+
IBM930 IBM1147
|
|
31
44
|
```
|
|
32
45
|
|
|
33
46
|
You can register supported EBCDIC charsets to your `XCharsetRegistrar`
|
|
@@ -54,11 +67,23 @@ You can depend on the [@lppedd/kotlinx-charset][1] npm package.
|
|
|
54
67
|
For example, consuming the library from TypeScript would look like:
|
|
55
68
|
|
|
56
69
|
```ts
|
|
57
|
-
import { decode, encode } from "@lppedd/kotlinx-charset";
|
|
70
|
+
import { decode, encode, getCharset } from "@lppedd/kotlinx-charset";
|
|
71
|
+
|
|
72
|
+
function funsExample(bytes: Uint8Array): Uint8Array {
|
|
73
|
+
const str = decode("ibm037", bytes);
|
|
74
|
+
return encode("ibm037", str);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Alternatively, you can interact with a charset instance directly.
|
|
78
|
+
// This allows setting or removing (by passing null) the replacement character.
|
|
79
|
+
function instanceExample(bytes: Uint8Array): Uint8Array {
|
|
80
|
+
const charset = getCharset("ibm037");
|
|
81
|
+
|
|
82
|
+
const decoder = charset.newDecoder();
|
|
83
|
+
const str = decoder.decode(bytes);
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return encode("cp037", str);
|
|
85
|
+
const encoder = charset.newEncoder();
|
|
86
|
+
return encoder.encode(str);
|
|
62
87
|
}
|
|
63
88
|
```
|
|
64
89
|
|
|
@@ -1,3 +1,29 @@
|
|
|
1
1
|
type Nullable<T> = T | null | undefined
|
|
2
|
+
export declare function getCharset(charsetName: string): XCharset;
|
|
2
3
|
export declare function decode(charsetName: string, bytes: Uint8Array): string;
|
|
3
|
-
export declare function encode(charsetName: string, value: string): Uint8Array;
|
|
4
|
+
export declare function encode(charsetName: string, value: string): Uint8Array;
|
|
5
|
+
export declare interface XCharset {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly aliases: Array<string>;
|
|
8
|
+
newDecoder(): XCharsetDecoder;
|
|
9
|
+
newEncoder(): XCharsetEncoder;
|
|
10
|
+
readonly __doNotUseOrImplementIt: {
|
|
11
|
+
readonly "com.github.lppedd.kotlinx.charset.exported.XCharset": unique symbol;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare interface XCharsetDecoder {
|
|
15
|
+
decode(bytes: Uint8Array): string;
|
|
16
|
+
setReplacement(newReplacement: Nullable<string>): void;
|
|
17
|
+
reset(): void;
|
|
18
|
+
readonly __doNotUseOrImplementIt: {
|
|
19
|
+
readonly "com.github.lppedd.kotlinx.charset.exported.XCharsetDecoder": unique symbol;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare interface XCharsetEncoder {
|
|
23
|
+
encode(value: string): Uint8Array;
|
|
24
|
+
setReplacement(newReplacement: Nullable<Uint8Array>): void;
|
|
25
|
+
reset(): void;
|
|
26
|
+
readonly __doNotUseOrImplementIt: {
|
|
27
|
+
readonly "com.github.lppedd.kotlinx.charset.exported.XCharsetEncoder": unique symbol;
|
|
28
|
+
};
|
|
29
|
+
}
|