utilium 1.8.0 → 1.9.0
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/dist/string.d.ts +2 -0
- package/dist/string.js +14 -0
- package/package.json +1 -1
- package/src/string.ts +16 -0
package/dist/string.d.ts
CHANGED
@@ -15,3 +15,5 @@ export declare function encodeUTF8(input: string): Uint8Array;
|
|
15
15
|
* Decodes a UTF-8 string from a buffer
|
16
16
|
*/
|
17
17
|
export declare function decodeUTF8(input?: Uint8Array): string;
|
18
|
+
export declare function encodeASCII(input: string): Uint8Array;
|
19
|
+
export declare function decodeASCII(input: Uint8Array): string;
|
package/dist/string.js
CHANGED
@@ -18,3 +18,17 @@ const decoder = new TextDecoder();
|
|
18
18
|
export function decodeUTF8(input) {
|
19
19
|
return decoder.decode(input);
|
20
20
|
}
|
21
|
+
export function encodeASCII(input) {
|
22
|
+
const data = new Uint8Array(input.length);
|
23
|
+
for (let i = 0; i < input.length; i++) {
|
24
|
+
data[i] = input.charCodeAt(i);
|
25
|
+
}
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
export function decodeASCII(input) {
|
29
|
+
let output = '';
|
30
|
+
for (let i = 0; i < input.length; i++) {
|
31
|
+
output += String.fromCharCode(input[i]);
|
32
|
+
}
|
33
|
+
return output;
|
34
|
+
}
|
package/package.json
CHANGED
package/src/string.ts
CHANGED
@@ -38,3 +38,19 @@ const decoder = new TextDecoder();
|
|
38
38
|
export function decodeUTF8(input?: Uint8Array): string {
|
39
39
|
return decoder.decode(input);
|
40
40
|
}
|
41
|
+
|
42
|
+
export function encodeASCII(input: string): Uint8Array {
|
43
|
+
const data = new Uint8Array(input.length);
|
44
|
+
for (let i = 0; i < input.length; i++) {
|
45
|
+
data[i] = input.charCodeAt(i);
|
46
|
+
}
|
47
|
+
return data;
|
48
|
+
}
|
49
|
+
|
50
|
+
export function decodeASCII(input: Uint8Array): string {
|
51
|
+
let output = '';
|
52
|
+
for (let i = 0; i < input.length; i++) {
|
53
|
+
output += String.fromCharCode(input[i]);
|
54
|
+
}
|
55
|
+
return output;
|
56
|
+
}
|