base128-ascii 4.0.0 → 5.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/main.d.ts +8 -10
- package/main.js +4 -32
- package/package.json +1 -1
package/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class EncodeResult {
|
|
2
|
-
constructor(bytes: Uint8Array);
|
|
2
|
+
constructor(bytes: Uint8Array<ArrayBuffer>);
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns a base128 string.
|
|
@@ -11,19 +11,17 @@ export declare class EncodeResult {
|
|
|
11
11
|
*/
|
|
12
12
|
toJSTemplateLiterals(): string;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
readonly bytes: Uint8Array;
|
|
14
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
export declare function encode(input: Uint8Array
|
|
17
|
+
export declare function encode(input: Uint8Array): EncodeResult;
|
|
20
18
|
|
|
21
|
-
export declare function decode(input: string): Uint8Array
|
|
19
|
+
export declare function decode(input: string): Uint8Array<ArrayBuffer>;
|
|
22
20
|
|
|
23
|
-
declare const base128
|
|
24
|
-
EncodeResult,
|
|
25
|
-
encode,
|
|
26
|
-
decode,
|
|
21
|
+
declare const base128: {
|
|
22
|
+
EncodeResult: typeof EncodeResult,
|
|
23
|
+
encode: typeof encode,
|
|
24
|
+
decode: typeof decode,
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
export default base128;
|
package/main.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
export class EncodeResult {
|
|
4
4
|
/**
|
|
5
|
-
* @param {Uint8Array} bytes
|
|
5
|
+
* @param {Uint8Array<ArrayBuffer>} bytes
|
|
6
6
|
*/
|
|
7
7
|
constructor(bytes) {
|
|
8
|
-
|
|
9
|
-
throw TypeError(`EncodeResult: Must input Uint8Array`)
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(this, "bytes", { value: bytes, enumerable: true })
|
|
8
|
+
this.bytes = bytes
|
|
12
9
|
}
|
|
13
10
|
toString() {
|
|
14
11
|
return new TextDecoder().decode(this.bytes)
|
|
@@ -25,36 +22,14 @@ export class EncodeResult {
|
|
|
25
22
|
)
|
|
26
23
|
)}\``
|
|
27
24
|
}
|
|
28
|
-
get buffer() {
|
|
29
|
-
return this.bytes.buffer
|
|
30
|
-
}
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
/**
|
|
34
|
-
* @param {Uint8Array
|
|
28
|
+
* @param {Uint8Array} input
|
|
35
29
|
*/
|
|
36
30
|
export function encode(input) {
|
|
37
|
-
if (input == null) {
|
|
38
|
-
throw TypeError(`encode: Cannot input null or undefined`)
|
|
39
|
-
}
|
|
40
|
-
if (input instanceof Uint8Array) {
|
|
41
|
-
// Uint8Array | Buffer
|
|
42
|
-
} else if (typeof input == 'string') {
|
|
43
|
-
// string
|
|
44
|
-
input = new TextEncoder().encode(input)
|
|
45
|
-
} else if (input instanceof ArrayBuffer) {
|
|
46
|
-
// ArrayBuffer
|
|
47
|
-
input = new Uint8Array(input)
|
|
48
|
-
} else if (input.buffer instanceof ArrayBuffer) {
|
|
49
|
-
// TypedArray | DataView | Pick<ArrayBufferView, "buffer">
|
|
50
|
-
input = new Uint8Array(input.buffer)
|
|
51
|
-
}
|
|
52
|
-
// else ArrayLike<number>
|
|
53
31
|
var il = input.length
|
|
54
|
-
|
|
55
|
-
throw TypeError(`encode: typeof input.length must be number`)
|
|
56
|
-
}
|
|
57
|
-
var out = new Uint8Array(Math.ceil(il / 7 * 8))
|
|
32
|
+
, out = new Uint8Array(Math.ceil(il / 7 * 8))
|
|
58
33
|
, ii = 0
|
|
59
34
|
, oi = 0
|
|
60
35
|
while (ii < il) {
|
|
@@ -78,9 +53,6 @@ export function encode(input) {
|
|
|
78
53
|
* @param {string} input
|
|
79
54
|
*/
|
|
80
55
|
export function decode(input) {
|
|
81
|
-
if (typeof input != 'string') {
|
|
82
|
-
throw TypeError(`decode: Must input string`)
|
|
83
|
-
}
|
|
84
56
|
var il = input.length
|
|
85
57
|
, out = new Uint8Array(il / 8 * 7)
|
|
86
58
|
, ii = 0
|