@exodus/bytes 1.0.0-rc.9 → 1.1.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/LICENSE +1 -1
- package/README.md +151 -0
- package/array.d.ts +24 -0
- package/base58.js +16 -8
- package/base64.d.ts +76 -0
- package/bigint.js +14 -0
- package/encoding-lite.js +7 -0
- package/encoding.js +12 -234
- package/fallback/_utils.js +18 -6
- package/fallback/encoding.js +290 -0
- package/fallback/encoding.labels.js +10 -10
- package/fallback/multi-byte.js +2 -3
- package/fallback/multi-byte.table.js +2 -2
- package/fallback/single-byte.encodings.js +56 -40
- package/fallback/single-byte.js +17 -14
- package/hex.d.ts +22 -0
- package/package.json +24 -6
- package/single-byte.js +0 -1
- package/single-byte.node.js +5 -5
- package/utf8.d.ts +42 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bytes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Various operations on Uint8Array data",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint .",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/ExodusOSS/bytes#readme",
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": "^20.19.0 ||
|
|
42
|
+
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
43
43
|
},
|
|
44
44
|
"type": "module",
|
|
45
45
|
"files": [
|
|
46
46
|
"/fallback/_utils.js",
|
|
47
47
|
"/fallback/base32.js",
|
|
48
48
|
"/fallback/base64.js",
|
|
49
|
+
"/fallback/encoding.js",
|
|
49
50
|
"/fallback/encoding.labels.js",
|
|
50
51
|
"/fallback/encoding.util.js",
|
|
51
52
|
"/fallback/hex.js",
|
|
@@ -59,14 +60,19 @@
|
|
|
59
60
|
"/fallback/utf16.js",
|
|
60
61
|
"/fallback/utf8.js",
|
|
61
62
|
"/array.js",
|
|
63
|
+
"/array.d.ts",
|
|
62
64
|
"/assert.js",
|
|
63
65
|
"/base32.js",
|
|
64
66
|
"/base58.js",
|
|
65
67
|
"/base58check.js",
|
|
66
68
|
"/base64.js",
|
|
69
|
+
"/base64.d.ts",
|
|
67
70
|
"/bech32.js",
|
|
71
|
+
"/bigint.js",
|
|
68
72
|
"/encoding.js",
|
|
73
|
+
"/encoding-lite.js",
|
|
69
74
|
"/hex.js",
|
|
75
|
+
"/hex.d.ts",
|
|
70
76
|
"/hex.node.js",
|
|
71
77
|
"/multi-byte.js",
|
|
72
78
|
"/multi-byte.node.js",
|
|
@@ -75,17 +81,26 @@
|
|
|
75
81
|
"/utf16.js",
|
|
76
82
|
"/utf16.node.js",
|
|
77
83
|
"/utf8.js",
|
|
84
|
+
"/utf8.d.ts",
|
|
78
85
|
"/utf8.node.js",
|
|
79
86
|
"/wif.js"
|
|
80
87
|
],
|
|
81
88
|
"exports": {
|
|
82
|
-
"./array.js":
|
|
89
|
+
"./array.js": {
|
|
90
|
+
"types": "./array.d.ts",
|
|
91
|
+
"default": "./array.js"
|
|
92
|
+
},
|
|
83
93
|
"./base32.js": "./base32.js",
|
|
84
94
|
"./base58.js": "./base58.js",
|
|
85
95
|
"./base58check.js": "./base58check.js",
|
|
86
|
-
"./base64.js":
|
|
96
|
+
"./base64.js": {
|
|
97
|
+
"types": "./base64.d.ts",
|
|
98
|
+
"default": "./base64.js"
|
|
99
|
+
},
|
|
87
100
|
"./bech32.js": "./bech32.js",
|
|
101
|
+
"./bigint.js": "./bigint.js",
|
|
88
102
|
"./hex.js": {
|
|
103
|
+
"types": "./hex.d.ts",
|
|
89
104
|
"node": "./hex.node.js",
|
|
90
105
|
"default": "./hex.js"
|
|
91
106
|
},
|
|
@@ -98,11 +113,13 @@
|
|
|
98
113
|
"default": "./single-byte.js"
|
|
99
114
|
},
|
|
100
115
|
"./encoding.js": "./encoding.js",
|
|
116
|
+
"./encoding-lite.js": "./encoding-lite.js",
|
|
101
117
|
"./utf16.js": {
|
|
102
118
|
"node": "./utf16.node.js",
|
|
103
119
|
"default": "./utf16.js"
|
|
104
120
|
},
|
|
105
121
|
"./utf8.js": {
|
|
122
|
+
"types": "./utf8.d.ts",
|
|
106
123
|
"node": "./utf8.node.js",
|
|
107
124
|
"default": "./utf8.js"
|
|
108
125
|
},
|
|
@@ -126,9 +143,10 @@
|
|
|
126
143
|
"@scure/base": "^1.2.6",
|
|
127
144
|
"@stablelib/base64": "^2.0.1",
|
|
128
145
|
"@stablelib/hex": "^2.0.1",
|
|
129
|
-
"@types/node": "^22.
|
|
146
|
+
"@types/node": "^22.12.0",
|
|
130
147
|
"base-x": "^5.0.1",
|
|
131
148
|
"base32.js": "^0.1.0",
|
|
149
|
+
"base58-js": "^3.0.3",
|
|
132
150
|
"base64-js": "^1.5.1",
|
|
133
151
|
"bech32": "^2.0.0",
|
|
134
152
|
"bs58": "^6.0.0",
|
|
@@ -144,7 +162,7 @@
|
|
|
144
162
|
"hextreme": "^1.0.7",
|
|
145
163
|
"hi-base32": "^0.5.1",
|
|
146
164
|
"iconv-lite": "^0.7.0",
|
|
147
|
-
"jsvu": "^3.0.
|
|
165
|
+
"jsvu": "^3.0.3",
|
|
148
166
|
"text-encoding": "^0.7.0",
|
|
149
167
|
"typescript": "^5.9.3",
|
|
150
168
|
"uint8array-tools": "^0.0.9",
|
package/single-byte.js
CHANGED
package/single-byte.node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertUint8 } from './assert.js'
|
|
2
2
|
import { isAscii } from 'node:buffer'
|
|
3
3
|
import { isDeno, isLE } from './fallback/_utils.js'
|
|
4
|
-
import { asciiPrefix
|
|
4
|
+
import { asciiPrefix } from './fallback/latin1.js'
|
|
5
5
|
import { encodingMapper, encodingDecoder, E_STRICT } from './fallback/single-byte.js'
|
|
6
6
|
|
|
7
7
|
const toBuf = (x) => Buffer.from(x.buffer, x.byteOffset, x.byteLength)
|
|
@@ -24,8 +24,7 @@ function latin1Prefix(arr, start) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function createSinglebyteDecoder(encoding, loose = false) {
|
|
27
|
-
|
|
28
|
-
const latin1path = encoding === 'windows-1252' // TODO: are there more?
|
|
27
|
+
const latin1path = encoding === 'windows-1252'
|
|
29
28
|
if (isDeno) {
|
|
30
29
|
const jsDecoder = encodingDecoder(encoding) // asserts
|
|
31
30
|
return (arr) => {
|
|
@@ -52,8 +51,9 @@ export function createSinglebyteDecoder(encoding, loose = false) {
|
|
|
52
51
|
if (prefixBytes === arr.length) return prefix
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
const b = mapper(arr, prefix.length) // prefix.length can mismatch prefixBytes
|
|
56
|
-
|
|
54
|
+
const b = toBuf(mapper(arr, prefix.length)) // prefix.length can mismatch prefixBytes
|
|
55
|
+
if (!isLE) b.swap16()
|
|
56
|
+
const suffix = b.ucs2Slice(0, b.byteLength)
|
|
57
57
|
if (!loose && incomplete && suffix.includes('\uFFFD')) throw new TypeError(E_STRICT)
|
|
58
58
|
return prefix + suffix
|
|
59
59
|
}
|
package/utf8.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
import type { OutputFormat, Uint8ArrayBuffer } from './array.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Encodes a string to UTF-8 bytes (strict mode)
|
|
7
|
+
* Throws on invalid Unicode (unpaired surrogates)
|
|
8
|
+
* @param str - The string to encode
|
|
9
|
+
* @param format - Output format (default: 'uint8')
|
|
10
|
+
* @returns The encoded bytes
|
|
11
|
+
*/
|
|
12
|
+
export function utf8fromString(str: string, format?: 'uint8'): Uint8ArrayBuffer;
|
|
13
|
+
export function utf8fromString(str: string, format: 'buffer'): Buffer;
|
|
14
|
+
export function utf8fromString(str: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Encodes a string to UTF-8 bytes (loose mode)
|
|
18
|
+
* Replaces invalid Unicode with replacement character
|
|
19
|
+
* @param str - The string to encode
|
|
20
|
+
* @param format - Output format (default: 'uint8')
|
|
21
|
+
* @returns The encoded bytes
|
|
22
|
+
*/
|
|
23
|
+
export function utf8fromStringLoose(str: string, format?: 'uint8'): Uint8ArrayBuffer;
|
|
24
|
+
export function utf8fromStringLoose(str: string, format: 'buffer'): Buffer;
|
|
25
|
+
export function utf8fromStringLoose(str: string, format?: OutputFormat): Uint8ArrayBuffer | Buffer;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Decodes UTF-8 bytes to a string (strict mode)
|
|
29
|
+
* Throws on invalid UTF-8 sequences
|
|
30
|
+
* @param arr - The bytes to decode
|
|
31
|
+
* @returns The decoded string
|
|
32
|
+
*/
|
|
33
|
+
export function utf8toString(arr: Uint8ArrayBuffer): string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Decodes UTF-8 bytes to a string (loose mode)
|
|
37
|
+
* Replaces invalid sequences with replacement character
|
|
38
|
+
* @param arr - The bytes to decode
|
|
39
|
+
* @returns The decoded string
|
|
40
|
+
*/
|
|
41
|
+
export function utf8toStringLoose(arr: Uint8ArrayBuffer): string;
|
|
42
|
+
|