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 CHANGED
@@ -15,7 +15,7 @@ The first byte indicates the length of the last incomplete block, 0 means no inc
15
15
  `0LF3!Tl7`
16
16
  ```
17
17
 
18
- Test effect, Base128 is 10KB smaller than Base64:
18
+ Test effect, Base128 is 102KiB smaller than Base64:
19
19
 
20
20
  ```
21
21
  screenshot-45.519.jpg
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export declare function encode(input: Uint8Array): string;
2
- export declare function stringToTemplateLiterals(input: string): string;
3
- export declare function encodeToTemplateLiterals(input: Uint8Array): string;
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
- return new TextDecoder().decode(out);
25
- }
26
- export function stringToTemplateLiterals(input) {
27
- return '`' + input.replace(/[\r\\`]|\${|\0\d?/g, (match) => match[0] == '\0'
28
- ? match.length == 2
29
- ? '\\x00' + match[1]
30
- : '\\0'
31
- : match == '\r'
32
- ? '\\r'
33
- : '\\' + match) + '`';
34
- }
35
- export function encodeToTemplateLiterals(input) {
36
- return stringToTemplateLiterals(encode(input));
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "base128-ascii",
3
- "version": "0.0.2",
3
+ "version": "1.0.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {