@lppedd/kotlinx-charset 0.1.3 → 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 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
- # kotlinx-charset
2
-
3
- [![Build status](https://github.com/lppedd/kotlinx-charset/workflows/Build/badge.svg)](https://github.com/lppedd/kotlinx-charset/actions/workflows/build.yml)
4
- [![MIT license](https://img.shields.io/github/license/lppedd/kotlinx-charset)](./LICENSE)
5
- [![Kotlin 2.1.20](https://img.shields.io/badge/kotlin-2.1.20-blue.svg?logo=kotlin)](https://kotlinlang.org)
6
- [![Maven Central](https://img.shields.io/maven-central/v/com.lppedd.kotlinx-charset/core)](https://mvnrepository.com/artifact/com.lppedd.kotlinx-charset)
7
- [![NPM Version](https://img.shields.io/npm/v/%40lppedd%2Fkotlinx-charset)](https://www.npmjs.com/package/@lppedd/kotlinx-charset)
8
-
9
- Minimal charset support for Kotlin Multiplatform.
10
-
11
- ### Changelog
12
-
13
- See [CHANGELOG.md](./CHANGELOG.md).
14
-
15
- ### Supported Kotlin platforms
16
-
17
- All Kotlin platforms are supported, except for Android Native.
18
-
19
- ### Design considerations
20
-
21
- **kotlinx-charset** aims to be straightforward for existing JDK consumers.
22
- It replicates parts of the JDK's `Charset` API, albeit with more restrictions.
23
-
24
- The core types you will work with are:
25
-
26
- - `XCharset` - describes a character set
27
- - `XCharsetDecoder` - decodes a byte sequence into characters
28
- - `XCharsetEncoder` - encodes characters into a byte sequence
29
- - `XCharsetRegistrar` - a registry and lookup service for obtaining `XCharset` instances
30
-
31
- ## core
32
-
33
- The `core` module provides the foundational components for implementing
34
- and registering new charsets.
35
-
36
- ```kotlin
37
- // Create an empty charset registry
38
- private val registrar = XCharsetRegistrar()
39
-
40
- // Register a new charset
41
- registrar.registerCharset(YourCharset())
42
-
43
- // Retrieve and use a charset
44
- val charset = registrar.getCharset("YourCharsetName")
45
- val decoder = charset.newDecoder()
46
- val encoder = charset.newEncoder()
47
- ```
48
-
49
- ## ebcdic
50
-
51
- The `ebcdic` module adds support for:
52
-
53
- ```text
54
- IBM037 IBM939 IBM1390
55
- IBM273 IBM1047 IBM1399
56
- IBM297 IBM1141
57
- IBM930 IBM1147
58
- ```
59
-
60
- You can register supported EBCDIC charsets to your `XCharsetRegistrar`
61
- via the `provideCharsets` function.
62
-
63
- ```kotlin
64
- import com.lppedd.kotlinx.charset.ebcdic.provideCharsets as provideEbcdicCharsets
65
-
66
- // Your shared charset registry
67
- private val registrar = XCharsetRegistrar()
68
-
69
- provideEbcdicCharsets(registrar)
70
- ```
71
-
72
- ## exported
73
-
74
- The `exported` module allows JS (and soon WebAssembly) consumers to decode bytes
75
- and encode strings, using top-level functions exported via ECMAScript modules.
76
-
77
- > [!TIP]
78
- > Avoid using this module when consuming `kotlinx-charset` from a Kotlin project
79
-
80
- You can depend on the [@lppedd/kotlinx-charset][1] npm package.
81
- For example, consuming the library from TypeScript would look like:
82
-
83
- ```ts
84
- import { decode, encode, getCharset } from "@lppedd/kotlinx-charset";
85
-
86
- function funsExample(bytes: Uint8Array): Uint8Array {
87
- const str = decode("ibm037", bytes);
88
- return encode("ibm037", str);
89
- }
90
-
91
- // Alternatively, you can interact with a charset instance directly.
92
- // This allows setting or removing (by passing null) the replacement character.
93
- function instanceExample(bytes: Uint8Array): Uint8Array {
94
- const charset = getCharset("ibm037");
95
-
96
- const decoder = charset.newDecoder();
97
- const str = decoder.decode(bytes);
98
-
99
- const encoder = charset.newEncoder();
100
- return encoder.encode(str);
101
- }
102
- ```
103
-
104
- Both the `decode` and `encode` functions will throw an `Error`
105
- if the specified charset does not exist or if an error occurs
106
- during data processing.
107
-
108
- [1]: https://www.npmjs.com/package/@lppedd/kotlinx-charset
1
+ <!--suppress HtmlDeprecatedAttribute -->
2
+ <h1 align="center">kotlinx-charset</h1>
3
+ <p align="center">Minimal charset support for Kotlin Multiplatform</p>
4
+ <div align="center">
5
+
6
+ [![maven central](https://img.shields.io/maven-central/v/com.lppedd.kotlinx-charset/core)](https://mvnrepository.com/artifact/com.lppedd.kotlinx-charset)
7
+ [![npm](https://img.shields.io/npm/v/%40lppedd%2Fkotlinx-charset?color=%23de1f1f&logo=npm)](https://www.npmjs.com/package/@lppedd/kotlinx-charset)
8
+ [![kotlin](https://img.shields.io/badge/kotlin-2.2.20-blue.svg?logo=kotlin)](https://kotlinlang.org)
9
+ [![build](https://img.shields.io/github/actions/workflow/status/lppedd/kotlinx-charset/build.yml.svg?branch=master)](https://github.com/lppedd/kotlinx-charset/actions/workflows/build.yml)
10
+ [![license](https://img.shields.io/github/license/lppedd/kotlinx-charset?color=blue)](./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
@@ -1,4 +1,5 @@
1
1
  type Nullable<T> = T | null | undefined
2
+ declare function KtSingleton<T>(): T & (abstract new() => any);
2
3
  export declare interface XCharset {
3
4
  readonly name: string;
4
5
  readonly aliases: Array<string>;