base128-ascii 5.0.2 → 5.0.3
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.js +19 -15
- package/package.json +3 -1
package/main.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
let _bytesToStr = (
|
|
2
|
+
(
|
|
3
|
+
typeof Buffer == 'function' &&
|
|
4
|
+
Buffer.prototype &&
|
|
5
|
+
typeof Buffer.prototype.latin1Slice == 'function' &&
|
|
6
|
+
// Exclude Deno. See https://github.com/bddjr/base128/pull/4
|
|
7
|
+
typeof Deno == 'undefined'
|
|
8
|
+
)
|
|
9
|
+
? (bytes) => Buffer.prototype.latin1Slice.call(bytes)
|
|
10
|
+
: (bytes) => {
|
|
11
|
+
// TextDecoder keeps the default UTF-8, which is already the fastest.
|
|
12
|
+
const td = new TextDecoder
|
|
13
|
+
return (_bytesToStr = (bytes) => td.decode(bytes))(bytes)
|
|
14
|
+
}
|
|
15
|
+
)
|
|
16
|
+
|
|
1
17
|
export class EncodeResult {
|
|
2
18
|
/**
|
|
3
19
|
* @param {Uint8Array<ArrayBuffer>} bytes
|
|
@@ -5,6 +21,9 @@ export class EncodeResult {
|
|
|
5
21
|
constructor(bytes) {
|
|
6
22
|
this.bytes = bytes
|
|
7
23
|
}
|
|
24
|
+
toString() {
|
|
25
|
+
return _bytesToStr(this.bytes)
|
|
26
|
+
}
|
|
8
27
|
toJSTemplateLiterals() {
|
|
9
28
|
return `\`${this.toString().replace(
|
|
10
29
|
/[\r\\`]|\$\{|<\/script/g,
|
|
@@ -19,21 +38,6 @@ export class EncodeResult {
|
|
|
19
38
|
}
|
|
20
39
|
}
|
|
21
40
|
|
|
22
|
-
if (
|
|
23
|
-
typeof Buffer == 'function' &&
|
|
24
|
-
Buffer.prototype &&
|
|
25
|
-
typeof Buffer.prototype.latin1Slice == 'function'
|
|
26
|
-
) {
|
|
27
|
-
EncodeResult.prototype.toString = function () {
|
|
28
|
-
return Buffer.prototype.latin1Slice.call(this.bytes)
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
let _textDecoder
|
|
32
|
-
EncodeResult.prototype.toString = function () {
|
|
33
|
-
return (_textDecoder || (_textDecoder = new TextDecoder)).decode(this.bytes)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
41
|
/**
|
|
38
42
|
* @param {Uint8Array} input
|
|
39
43
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "base128-ascii",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"author": "bddjr",
|
|
5
5
|
"license": "Unlicense",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "es-check es6 --checkFeatures --module main.js && tsc && node scripts/test.mjs",
|
|
14
|
+
"test:deno": "deno run --allow-read=. --allow-write=. scripts/test.mjs",
|
|
15
|
+
"test:bun": "bun scripts/test.mjs",
|
|
14
16
|
"prepublishOnly": "node --run test"
|
|
15
17
|
},
|
|
16
18
|
"repository": {
|