base128-ascii 4.0.1 → 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.
Files changed (3) hide show
  1. package/main.d.ts +4 -6
  2. package/main.js +4 -32
  3. 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,14 +11,12 @@ export declare class EncodeResult {
11
11
  */
12
12
  toJSTemplateLiterals(): string;
13
13
 
14
- get buffer(): ArrayBufferLike;
15
-
16
- readonly bytes: Uint8Array;
14
+ bytes: Uint8Array<ArrayBuffer>;
17
15
  }
18
16
 
19
- export declare function encode(input: Uint8Array | string | ArrayLike<number> | ArrayBuffer | Pick<ArrayBufferView, "buffer">): EncodeResult;
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
21
  declare const base128: {
24
22
  EncodeResult: typeof EncodeResult,
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
- if (!(bytes instanceof Uint8Array)) {
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 | string | ArrayLike<number> | ArrayBuffer | Pick<ArrayBufferView, "buffer">} input
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
- if (typeof il != 'number') {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "base128-ascii",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "author": "bddjr",
5
5
  "license": "Unlicense",
6
6
  "type": "module",