base128-ascii 0.0.2 → 1.0.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/README.md +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +22 -14
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export declare function encode(input: Uint8Array):
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export declare function encode(input: Uint8Array): {
|
|
2
|
+
uint8Array: Uint8Array<ArrayBuffer>;
|
|
3
|
+
toString(): string;
|
|
4
|
+
toJSTemplateLiterals(): string;
|
|
5
|
+
};
|
|
4
6
|
export declare function decode(input: string): Uint8Array<ArrayBuffer>;
|
|
5
7
|
declare const base128: {
|
|
6
8
|
encode: typeof encode;
|
|
7
|
-
encodeToTemplateLiterals: typeof encodeToTemplateLiterals;
|
|
8
9
|
decode: typeof decode;
|
|
9
10
|
};
|
|
10
11
|
export default base128;
|
package/dist/index.js
CHANGED
|
@@ -21,19 +21,28 @@ export function encode(input) {
|
|
|
21
21
|
}
|
|
22
22
|
if (suffixSize)
|
|
23
23
|
out = out.slice(0, Math.ceil(suffixSize / 7 * 8) - 8);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
let str;
|
|
25
|
+
let jstl;
|
|
26
|
+
return {
|
|
27
|
+
uint8Array: out,
|
|
28
|
+
toString() {
|
|
29
|
+
return str ??= new TextDecoder().decode(out);
|
|
30
|
+
},
|
|
31
|
+
toJSTemplateLiterals() {
|
|
32
|
+
return jstl ??= '`' + this.toString().replace(/[\r\\`]|\${|\0\d?|<\/script/g, (match) => {
|
|
33
|
+
if (match == '\r')
|
|
34
|
+
return '\\r';
|
|
35
|
+
if (match == '</script')
|
|
36
|
+
return '<\\/script';
|
|
37
|
+
if (match[0] == '\0') {
|
|
38
|
+
if (match.length == 2)
|
|
39
|
+
return '\\x00' + match[1];
|
|
40
|
+
return '\\0';
|
|
41
|
+
}
|
|
42
|
+
return '\\' + match;
|
|
43
|
+
}) + '`';
|
|
44
|
+
}
|
|
45
|
+
};
|
|
37
46
|
}
|
|
38
47
|
export function decode(input) {
|
|
39
48
|
const u8a = new TextEncoder().encode(input);
|
|
@@ -62,7 +71,6 @@ export function decode(input) {
|
|
|
62
71
|
}
|
|
63
72
|
const base128 = {
|
|
64
73
|
encode,
|
|
65
|
-
encodeToTemplateLiterals,
|
|
66
74
|
decode
|
|
67
75
|
};
|
|
68
76
|
export default base128;
|