llonebot-dist 6.6.4
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.
- dist/default_config.json +68 -0
- dist/llonebot.js +48348 -0
- dist/llonebot.js.map +1 -0
- dist/node_modules/@borewit/text-codec/LICENSE.txt +9 -0
- dist/node_modules/@borewit/text-codec/README.md +76 -0
- dist/node_modules/@borewit/text-codec/lib/index.d.ts +8 -0
- dist/node_modules/@borewit/text-codec/lib/index.js +161 -0
- dist/node_modules/@borewit/text-codec/package.json +68 -0
- dist/node_modules/@minatojs/sql.js/LICENSE +44 -0
- dist/node_modules/@minatojs/sql.js/README.md +357 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.d.ts +316 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.js +225 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.wasm +0 -0
- dist/node_modules/@minatojs/sql.js/package.json +58 -0
- dist/node_modules/@tokenizer/inflate/LICENSE +15 -0
- dist/node_modules/@tokenizer/inflate/README.md +114 -0
- dist/node_modules/@tokenizer/inflate/lib/GzipHandler.d.ts +6 -0
- dist/node_modules/@tokenizer/inflate/lib/GzipHandler.js +19 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipHandler.d.ts +26 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipHandler.js +233 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipToken.d.ts +94 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipToken.js +117 -0
- dist/node_modules/@tokenizer/inflate/lib/index.d.ts +3 -0
- dist/node_modules/@tokenizer/inflate/lib/index.js +2 -0
- dist/node_modules/@tokenizer/inflate/package.json +76 -0
- dist/node_modules/@tokenizer/token/README.md +19 -0
- dist/node_modules/@tokenizer/token/index.d.ts +30 -0
- dist/node_modules/@tokenizer/token/package.json +33 -0
- dist/node_modules/debug/LICENSE +20 -0
- dist/node_modules/debug/README.md +481 -0
- dist/node_modules/debug/package.json +64 -0
- dist/node_modules/debug/src/browser.js +272 -0
- dist/node_modules/debug/src/common.js +292 -0
- dist/node_modules/debug/src/index.js +10 -0
- dist/node_modules/debug/src/node.js +263 -0
- dist/node_modules/file-type/core.d.ts +253 -0
- dist/node_modules/file-type/core.js +1899 -0
- dist/node_modules/file-type/index.d.ts +98 -0
- dist/node_modules/file-type/index.js +86 -0
- dist/node_modules/file-type/license +9 -0
- dist/node_modules/file-type/package.json +288 -0
- dist/node_modules/file-type/readme.md +674 -0
- dist/node_modules/file-type/supported.js +356 -0
- dist/node_modules/file-type/util.js +60 -0
- dist/node_modules/ieee754/LICENSE +11 -0
- dist/node_modules/ieee754/README.md +51 -0
- dist/node_modules/ieee754/index.d.ts +10 -0
- dist/node_modules/ieee754/index.js +85 -0
- dist/node_modules/ieee754/package.json +52 -0
- dist/node_modules/ms/index.js +162 -0
- dist/node_modules/ms/license.md +21 -0
- dist/node_modules/ms/package.json +38 -0
- dist/node_modules/ms/readme.md +59 -0
- dist/node_modules/silk-wasm/LICENSE +21 -0
- dist/node_modules/silk-wasm/README.md +85 -0
- dist/node_modules/silk-wasm/lib/index.cjs +16 -0
- dist/node_modules/silk-wasm/lib/index.d.ts +70 -0
- dist/node_modules/silk-wasm/lib/index.mjs +16 -0
- dist/node_modules/silk-wasm/lib/silk.wasm +0 -0
- dist/node_modules/silk-wasm/lib/utils.d.ts +4 -0
- dist/node_modules/silk-wasm/package.json +39 -0
- dist/node_modules/strtok3/LICENSE.txt +21 -0
- dist/node_modules/strtok3/README.md +399 -0
- dist/node_modules/strtok3/lib/AbstractTokenizer.d.ts +76 -0
- dist/node_modules/strtok3/lib/AbstractTokenizer.js +108 -0
- dist/node_modules/strtok3/lib/BlobTokenizer.d.ts +29 -0
- dist/node_modules/strtok3/lib/BlobTokenizer.js +53 -0
- dist/node_modules/strtok3/lib/BufferTokenizer.d.ts +29 -0
- dist/node_modules/strtok3/lib/BufferTokenizer.js +52 -0
- dist/node_modules/strtok3/lib/FileTokenizer.d.ts +37 -0
- dist/node_modules/strtok3/lib/FileTokenizer.js +61 -0
- dist/node_modules/strtok3/lib/ReadStreamTokenizer.d.ts +31 -0
- dist/node_modules/strtok3/lib/ReadStreamTokenizer.js +102 -0
- dist/node_modules/strtok3/lib/core.d.ts +40 -0
- dist/node_modules/strtok3/lib/core.js +62 -0
- dist/node_modules/strtok3/lib/index.d.ts +16 -0
- dist/node_modules/strtok3/lib/index.js +22 -0
- dist/node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts +54 -0
- dist/node_modules/strtok3/lib/stream/AbstractStreamReader.js +71 -0
- dist/node_modules/strtok3/lib/stream/Deferred.d.ts +6 -0
- dist/node_modules/strtok3/lib/stream/Deferred.js +10 -0
- dist/node_modules/strtok3/lib/stream/Errors.d.ts +10 -0
- dist/node_modules/strtok3/lib/stream/Errors.js +16 -0
- dist/node_modules/strtok3/lib/stream/StreamReader.d.ts +29 -0
- dist/node_modules/strtok3/lib/stream/StreamReader.js +83 -0
- dist/node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts +14 -0
- dist/node_modules/strtok3/lib/stream/WebStreamByobReader.js +27 -0
- dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts +19 -0
- dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.js +62 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReader.d.ts +14 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReader.js +13 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.d.ts +5 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.js +19 -0
- dist/node_modules/strtok3/lib/stream/index.d.ts +6 -0
- dist/node_modules/strtok3/lib/stream/index.js +5 -0
- dist/node_modules/strtok3/lib/types.d.ts +139 -0
- dist/node_modules/strtok3/lib/types.js +1 -0
- dist/node_modules/strtok3/package.json +94 -0
- dist/node_modules/token-types/LICENSE.txt +9 -0
- dist/node_modules/token-types/README.md +120 -0
- dist/node_modules/token-types/lib/index.d.ts +135 -0
- dist/node_modules/token-types/lib/index.js +401 -0
- dist/node_modules/token-types/package.json +81 -0
- dist/node_modules/uint8array-extras/index.d.ts +312 -0
- dist/node_modules/uint8array-extras/index.js +321 -0
- dist/node_modules/uint8array-extras/license +9 -0
- dist/node_modules/uint8array-extras/package.json +54 -0
- dist/node_modules/uint8array-extras/readme.md +301 -0
- dist/node_modules/ws/LICENSE +20 -0
- dist/node_modules/ws/README.md +548 -0
- dist/node_modules/ws/browser.js +8 -0
- dist/node_modules/ws/index.js +13 -0
- dist/node_modules/ws/lib/buffer-util.js +131 -0
- dist/node_modules/ws/lib/constants.js +18 -0
- dist/node_modules/ws/lib/event-target.js +292 -0
- dist/node_modules/ws/lib/extension.js +203 -0
- dist/node_modules/ws/lib/limiter.js +55 -0
- dist/node_modules/ws/lib/permessage-deflate.js +528 -0
- dist/node_modules/ws/lib/receiver.js +706 -0
- dist/node_modules/ws/lib/sender.js +602 -0
- dist/node_modules/ws/lib/stream.js +161 -0
- dist/node_modules/ws/lib/subprotocol.js +62 -0
- dist/node_modules/ws/lib/validation.js +152 -0
- dist/node_modules/ws/lib/websocket-server.js +550 -0
- dist/node_modules/ws/lib/websocket.js +1388 -0
- dist/node_modules/ws/package.json +69 -0
- dist/node_modules/ws/wrapper.mjs +8 -0
- dist/package.json +1 -0
- dist/webui/assets/index-B9vGhdCO.js +256 -0
- dist/webui/assets/index-DaqFU7JR.css +1 -0
- dist/webui/index.html +13 -0
- dist/webui/logo.jpg +0 -0
- dist//344/275/277/347/224/250/350/257/264/346/230/216.txt +11 -0
- dist//346/233/264/346/226/260/346/227/245/345/277/227.txt +399 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "token-types",
|
|
3
|
+
"version": "6.1.1",
|
|
4
|
+
"description": "Common token types for decoding and encoding numeric and string values",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Borewit",
|
|
7
|
+
"url": "https://github.com/Borewit"
|
|
8
|
+
},
|
|
9
|
+
"funding": {
|
|
10
|
+
"type": "github",
|
|
11
|
+
"url": "https://github.com/sponsors/Borewit"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"clean": "del-cli 'lib/**/*.js' 'lib/***.js.map' 'test/**/*.d.ts' 'test/**/*.js' 'test/**/*.js.map'",
|
|
15
|
+
"build": "npm run compile",
|
|
16
|
+
"compile-src": "tsc --p lib --sourceMap false",
|
|
17
|
+
"compile-test": "tsc --p test",
|
|
18
|
+
"compile": "npm run compile-src && npm run compile-test",
|
|
19
|
+
"lint:ts": "biome check",
|
|
20
|
+
"lint:md": "remark -u preset-lint-recommended .",
|
|
21
|
+
"lint": "npm run lint:md && npm run lint:ts",
|
|
22
|
+
"test": "mocha",
|
|
23
|
+
"test-coverage": "c8 npm run test",
|
|
24
|
+
"send-codacy": "c8 report --reports-dir=./.coverage --reporter=text-lcov | codacy-coverage",
|
|
25
|
+
"update-biome": "yarn add -D --exact @biomejs/biome && npx @biomejs/biome migrate --write"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=14.16"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/Borewit/token-types"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"lib/index.js",
|
|
36
|
+
"lib/index.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"type": "module",
|
|
40
|
+
"exports": "./lib/index.js",
|
|
41
|
+
"types": "lib/index.d.ts",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Borewit/token-types/issues"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@biomejs/biome": "2.1.4",
|
|
47
|
+
"@types/chai": "^5.2.2",
|
|
48
|
+
"@types/mocha": "^10.0.10",
|
|
49
|
+
"@types/node": "^24.2.1",
|
|
50
|
+
"c8": "^10.1.3",
|
|
51
|
+
"chai": "^5.2.1",
|
|
52
|
+
"del-cli": "^6.0.0",
|
|
53
|
+
"mocha": "^11.7.1",
|
|
54
|
+
"remark-cli": "^12.0.1",
|
|
55
|
+
"remark-preset-lint-recommended": "^7.0.0",
|
|
56
|
+
"source-map-support": "^0.5.21",
|
|
57
|
+
"ts-node": "^10.9.1",
|
|
58
|
+
"typescript": "^5.9.2"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@borewit/text-codec": "^0.1.0",
|
|
62
|
+
"@tokenizer/token": "^0.3.0",
|
|
63
|
+
"ieee754": "^1.2.1"
|
|
64
|
+
},
|
|
65
|
+
"remarkConfig": {
|
|
66
|
+
"plugins": [
|
|
67
|
+
"preset-lint-recommended"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"keywords": [
|
|
71
|
+
"token",
|
|
72
|
+
"integer",
|
|
73
|
+
"unsigned",
|
|
74
|
+
"numeric",
|
|
75
|
+
"float",
|
|
76
|
+
"IEEE",
|
|
77
|
+
"754",
|
|
78
|
+
"strtok3"
|
|
79
|
+
],
|
|
80
|
+
"packageManager": "yarn@4.9.2"
|
|
81
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
export type TypedArray =
|
|
2
|
+
| Int8Array
|
|
3
|
+
| Uint8Array
|
|
4
|
+
| Uint8ClampedArray
|
|
5
|
+
| Int16Array
|
|
6
|
+
| Uint16Array
|
|
7
|
+
| Int32Array
|
|
8
|
+
| Uint32Array
|
|
9
|
+
| Float32Array
|
|
10
|
+
| Float64Array
|
|
11
|
+
| BigInt64Array
|
|
12
|
+
| BigUint64Array;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
Check if the given value is an instance of `Uint8Array`.
|
|
16
|
+
|
|
17
|
+
Replacement for [`Buffer.isBuffer()`](https://nodejs.org/api/buffer.html#static-method-bufferisbufferobj).
|
|
18
|
+
|
|
19
|
+
@example
|
|
20
|
+
```
|
|
21
|
+
import {isUint8Array} from 'uint8array-extras';
|
|
22
|
+
|
|
23
|
+
console.log(isUint8Array(new Uint8Array()));
|
|
24
|
+
//=> true
|
|
25
|
+
|
|
26
|
+
console.log(isUint8Array(Buffer.from('x')));
|
|
27
|
+
//=> true
|
|
28
|
+
|
|
29
|
+
console.log(isUint8Array(new ArrayBuffer(10)));
|
|
30
|
+
//=> false
|
|
31
|
+
```
|
|
32
|
+
*/
|
|
33
|
+
export function isUint8Array(value: unknown): value is Uint8Array;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
Throw a `TypeError` if the given value is not an instance of `Uint8Array`.
|
|
37
|
+
|
|
38
|
+
@example
|
|
39
|
+
```
|
|
40
|
+
import {assertUint8Array} from 'uint8array-extras';
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
assertUint8Array(new ArrayBuffer(10)); // Throws a TypeError
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(error.message);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
*/
|
|
49
|
+
export function assertUint8Array(value: unknown): asserts value is Uint8Array;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
Convert a value to a `Uint8Array` without copying its data.
|
|
53
|
+
|
|
54
|
+
This can be useful for converting a `Buffer` to a pure `Uint8Array`. `Buffer` is already an `Uint8Array` subclass, but [`Buffer` alters some behavior](https://sindresorhus.com/blog/goodbye-nodejs-buffer), so it can be useful to cast it to a pure `Uint8Array` before returning it.
|
|
55
|
+
|
|
56
|
+
Tip: If you want a copy, just call `.slice()` on the return value.
|
|
57
|
+
*/
|
|
58
|
+
export function toUint8Array(value: TypedArray | ArrayBuffer | DataView): Uint8Array;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
Concatenate the given arrays into a new array.
|
|
62
|
+
|
|
63
|
+
If `arrays` is empty, it will return a zero-sized `Uint8Array`.
|
|
64
|
+
|
|
65
|
+
If `totalLength` is not specified, it is calculated from summing the lengths of the given arrays.
|
|
66
|
+
|
|
67
|
+
Replacement for [`Buffer.concat()`](https://nodejs.org/api/buffer.html#static-method-bufferconcatlist-totallength).
|
|
68
|
+
|
|
69
|
+
@example
|
|
70
|
+
```
|
|
71
|
+
import {concatUint8Arrays} from 'uint8array-extras';
|
|
72
|
+
|
|
73
|
+
const a = new Uint8Array([1, 2, 3]);
|
|
74
|
+
const b = new Uint8Array([4, 5, 6]);
|
|
75
|
+
|
|
76
|
+
console.log(concatUint8Arrays([a, b]));
|
|
77
|
+
//=> Uint8Array [1, 2, 3, 4, 5, 6]
|
|
78
|
+
```
|
|
79
|
+
*/
|
|
80
|
+
export function concatUint8Arrays(arrays: Uint8Array[], totalLength?: number): Uint8Array;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
Check if two arrays are identical by verifying that they contain the same bytes in the same sequence.
|
|
84
|
+
|
|
85
|
+
Replacement for [`Buffer#equals()`](https://nodejs.org/api/buffer.html#bufequalsotherbuffer).
|
|
86
|
+
|
|
87
|
+
@example
|
|
88
|
+
```
|
|
89
|
+
import {areUint8ArraysEqual} from 'uint8array-extras';
|
|
90
|
+
|
|
91
|
+
const a = new Uint8Array([1, 2, 3]);
|
|
92
|
+
const b = new Uint8Array([1, 2, 3]);
|
|
93
|
+
const c = new Uint8Array([4, 5, 6]);
|
|
94
|
+
|
|
95
|
+
console.log(areUint8ArraysEqual(a, b));
|
|
96
|
+
//=> true
|
|
97
|
+
|
|
98
|
+
console.log(areUint8ArraysEqual(a, c));
|
|
99
|
+
//=> false
|
|
100
|
+
```
|
|
101
|
+
*/
|
|
102
|
+
export function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
Compare two arrays and indicate their relative order or equality. Useful for sorting.
|
|
106
|
+
|
|
107
|
+
Replacement for [`Buffer.compare()`](https://nodejs.org/api/buffer.html#static-method-buffercomparebuf1-buf2).
|
|
108
|
+
|
|
109
|
+
@example
|
|
110
|
+
```
|
|
111
|
+
import {compareUint8Arrays} from 'uint8array-extras';
|
|
112
|
+
|
|
113
|
+
const array1 = new Uint8Array([1, 2, 3]);
|
|
114
|
+
const array2 = new Uint8Array([4, 5, 6]);
|
|
115
|
+
const array3 = new Uint8Array([7, 8, 9]);
|
|
116
|
+
|
|
117
|
+
[array3, array1, array2].sort(compareUint8Arrays);
|
|
118
|
+
//=> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
119
|
+
```
|
|
120
|
+
*/
|
|
121
|
+
export function compareUint8Arrays(a: Uint8Array, b: Uint8Array): 0 | 1 | -1;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
Convert a `Uint8Array` to a string.
|
|
125
|
+
|
|
126
|
+
@param encoding - The [encoding](https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings) to convert from. Default: `'utf8'`
|
|
127
|
+
|
|
128
|
+
Replacement for [`Buffer#toString()`](https://nodejs.org/api/buffer.html#buftostringencoding-start-end). For the `encoding` parameter, `latin1` should be used instead of `binary` and `utf-16le` instead of `utf16le`.
|
|
129
|
+
|
|
130
|
+
@example
|
|
131
|
+
```
|
|
132
|
+
import {uint8ArrayToString} from 'uint8array-extras';
|
|
133
|
+
|
|
134
|
+
const byteArray = new Uint8Array([72, 101, 108, 108, 111]);
|
|
135
|
+
console.log(uint8ArrayToString(byteArray));
|
|
136
|
+
//=> 'Hello'
|
|
137
|
+
|
|
138
|
+
const zh = new Uint8Array([167, 65, 166, 110]);
|
|
139
|
+
console.log(uint8ArrayToString(zh, 'big5'));
|
|
140
|
+
//=> '你好'
|
|
141
|
+
|
|
142
|
+
const ja = new Uint8Array([130, 177, 130, 241, 130, 201, 130, 191, 130, 205]);
|
|
143
|
+
console.log(uint8ArrayToString(ja, 'shift-jis'));
|
|
144
|
+
//=> 'こんにちは'
|
|
145
|
+
```
|
|
146
|
+
*/
|
|
147
|
+
export function uint8ArrayToString(array: Uint8Array | ArrayBuffer, encoding?: string): string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
Convert a string to a `Uint8Array` (using UTF-8 encoding).
|
|
151
|
+
|
|
152
|
+
Replacement for [`Buffer.from('Hello')`](https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding).
|
|
153
|
+
|
|
154
|
+
@example
|
|
155
|
+
```
|
|
156
|
+
import {stringToUint8Array} from 'uint8array-extras';
|
|
157
|
+
|
|
158
|
+
console.log(stringToUint8Array('Hello'));
|
|
159
|
+
//=> Uint8Array [72, 101, 108, 108, 111]
|
|
160
|
+
```
|
|
161
|
+
*/
|
|
162
|
+
export function stringToUint8Array(string: string): Uint8Array;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
Convert a `Uint8Array` to a Base64-encoded string.
|
|
166
|
+
|
|
167
|
+
Specify `{urlSafe: true}` to get a [Base64URL](https://base64.guru/standards/base64url)-encoded string.
|
|
168
|
+
|
|
169
|
+
Replacement for [`Buffer#toString('base64')`](https://nodejs.org/api/buffer.html#buftostringencoding-start-end).
|
|
170
|
+
|
|
171
|
+
@example
|
|
172
|
+
```
|
|
173
|
+
import {uint8ArrayToBase64} from 'uint8array-extras';
|
|
174
|
+
|
|
175
|
+
const byteArray = new Uint8Array([72, 101, 108, 108, 111]);
|
|
176
|
+
|
|
177
|
+
console.log(uint8ArrayToBase64(byteArray));
|
|
178
|
+
//=> 'SGVsbG8='
|
|
179
|
+
```
|
|
180
|
+
*/
|
|
181
|
+
export function uint8ArrayToBase64(array: Uint8Array, options?: {urlSafe: boolean}): string;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
Convert a Base64-encoded or [Base64URL](https://base64.guru/standards/base64url)-encoded string to a `Uint8Array`.
|
|
185
|
+
|
|
186
|
+
Replacement for [`Buffer.from('SGVsbG8=', 'base64')`](https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding).
|
|
187
|
+
|
|
188
|
+
@example
|
|
189
|
+
```
|
|
190
|
+
import {base64ToUint8Array} from 'uint8array-extras';
|
|
191
|
+
|
|
192
|
+
console.log(base64ToUint8Array('SGVsbG8='));
|
|
193
|
+
//=> Uint8Array [72, 101, 108, 108, 111]
|
|
194
|
+
```
|
|
195
|
+
*/
|
|
196
|
+
export function base64ToUint8Array(string: string): Uint8Array;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
Encode a string to Base64-encoded string.
|
|
200
|
+
|
|
201
|
+
Specify `{urlSafe: true}` to get a [Base64URL](https://base64.guru/standards/base64url)-encoded string.
|
|
202
|
+
|
|
203
|
+
Replacement for `Buffer.from('Hello').toString('base64')` and [`btoa()`](https://developer.mozilla.org/en-US/docs/Web/API/btoa).
|
|
204
|
+
|
|
205
|
+
@example
|
|
206
|
+
```
|
|
207
|
+
import {stringToBase64} from 'uint8array-extras';
|
|
208
|
+
|
|
209
|
+
console.log(stringToBase64('Hello'));
|
|
210
|
+
//=> 'SGVsbG8='
|
|
211
|
+
```
|
|
212
|
+
*/
|
|
213
|
+
export function stringToBase64(string: string, options?: {urlSafe: boolean}): string;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
Decode a Base64-encoded or [Base64URL](https://base64.guru/standards/base64url)-encoded string to a string.
|
|
217
|
+
|
|
218
|
+
Replacement for `Buffer.from('SGVsbG8=', 'base64').toString()` and [`atob()`](https://developer.mozilla.org/en-US/docs/Web/API/atob).
|
|
219
|
+
|
|
220
|
+
@example
|
|
221
|
+
```
|
|
222
|
+
import {base64ToString} from 'uint8array-extras';
|
|
223
|
+
|
|
224
|
+
console.log(base64ToString('SGVsbG8='));
|
|
225
|
+
//=> 'Hello'
|
|
226
|
+
```
|
|
227
|
+
*/
|
|
228
|
+
export function base64ToString(base64String: string): string;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
Convert a `Uint8Array` to a Hex string.
|
|
232
|
+
|
|
233
|
+
Replacement for [`Buffer#toString('hex')`](https://nodejs.org/api/buffer.html#buftostringencoding-start-end).
|
|
234
|
+
|
|
235
|
+
@example
|
|
236
|
+
```
|
|
237
|
+
import {uint8ArrayToHex} from 'uint8array-extras';
|
|
238
|
+
|
|
239
|
+
const byteArray = new Uint8Array([72, 101, 108, 108, 111]);
|
|
240
|
+
|
|
241
|
+
console.log(uint8ArrayToHex(byteArray));
|
|
242
|
+
//=> '48656c6c6f'
|
|
243
|
+
```
|
|
244
|
+
*/
|
|
245
|
+
export function uint8ArrayToHex(array: Uint8Array): string;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
Convert a Hex string to a `Uint8Array`.
|
|
249
|
+
|
|
250
|
+
Replacement for [`Buffer.from('48656c6c6f', 'hex')`](https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding).
|
|
251
|
+
|
|
252
|
+
@example
|
|
253
|
+
```
|
|
254
|
+
import {hexToUint8Array} from 'uint8array-extras';
|
|
255
|
+
|
|
256
|
+
console.log(hexToUint8Array('48656c6c6f'));
|
|
257
|
+
//=> Uint8Array [72, 101, 108, 108, 111]
|
|
258
|
+
```
|
|
259
|
+
*/
|
|
260
|
+
export function hexToUint8Array(hexString: string): Uint8Array;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
Read `DataView#byteLength` number of bytes from the given view, up to 48-bit.
|
|
264
|
+
|
|
265
|
+
Replacement for [`Buffer#readUintBE`](https://nodejs.org/api/buffer.html#bufreadintbeoffset-bytelength)
|
|
266
|
+
|
|
267
|
+
@example
|
|
268
|
+
```
|
|
269
|
+
import {getUintBE} from 'uint8array-extras';
|
|
270
|
+
|
|
271
|
+
const byteArray = new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
|
272
|
+
|
|
273
|
+
console.log(getUintBE(new DataView(byteArray.buffer)));
|
|
274
|
+
//=> 20015998341291
|
|
275
|
+
```
|
|
276
|
+
*/
|
|
277
|
+
export function getUintBE(view: DataView): number; // eslint-disable-line @typescript-eslint/naming-convention
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
Find the index of the first occurrence of the given sequence of bytes (`value`) within the given `Uint8Array` (`array`).
|
|
281
|
+
|
|
282
|
+
Replacement for [`Buffer#indexOf`](https://nodejs.org/api/buffer.html#bufindexofvalue-byteoffset-encoding). `Uint8Array#indexOf` only takes a number which is different from Buffer's `indexOf` implementation.
|
|
283
|
+
|
|
284
|
+
@example
|
|
285
|
+
```
|
|
286
|
+
import {indexOf} from 'uint8array-extras';
|
|
287
|
+
|
|
288
|
+
const byteArray = new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef]);
|
|
289
|
+
|
|
290
|
+
console.log(indexOf(byteArray, new Uint8Array([0x78, 0x90])));
|
|
291
|
+
//=> 3
|
|
292
|
+
```
|
|
293
|
+
*/
|
|
294
|
+
export function indexOf(array: Uint8Array, value: Uint8Array): number;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
Checks if the given sequence of bytes (`value`) is within the given `Uint8Array` (`array`).
|
|
298
|
+
|
|
299
|
+
Returns true if the value is included, otherwise false.
|
|
300
|
+
|
|
301
|
+
Replacement for [`Buffer#includes`](https://nodejs.org/api/buffer.html#bufincludesvalue-byteoffset-encoding). `Uint8Array#includes` only takes a number which is different from Buffer's `includes` implementation.
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
import {includes} from 'uint8array-extras';
|
|
305
|
+
|
|
306
|
+
const byteArray = new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef]);
|
|
307
|
+
|
|
308
|
+
console.log(includes(byteArray, new Uint8Array([0x78, 0x90])));
|
|
309
|
+
//=> true
|
|
310
|
+
```
|
|
311
|
+
*/
|
|
312
|
+
export function includes(array: Uint8Array, value: Uint8Array): boolean;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
const objectToString = Object.prototype.toString;
|
|
2
|
+
const uint8ArrayStringified = '[object Uint8Array]';
|
|
3
|
+
const arrayBufferStringified = '[object ArrayBuffer]';
|
|
4
|
+
|
|
5
|
+
function isType(value, typeConstructor, typeStringified) {
|
|
6
|
+
if (!value) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (value.constructor === typeConstructor) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return objectToString.call(value) === typeStringified;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isUint8Array(value) {
|
|
18
|
+
return isType(value, Uint8Array, uint8ArrayStringified);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isArrayBuffer(value) {
|
|
22
|
+
return isType(value, ArrayBuffer, arrayBufferStringified);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isUint8ArrayOrArrayBuffer(value) {
|
|
26
|
+
return isUint8Array(value) || isArrayBuffer(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function assertUint8Array(value) {
|
|
30
|
+
if (!isUint8Array(value)) {
|
|
31
|
+
throw new TypeError(`Expected \`Uint8Array\`, got \`${typeof value}\``);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function assertUint8ArrayOrArrayBuffer(value) {
|
|
36
|
+
if (!isUint8ArrayOrArrayBuffer(value)) {
|
|
37
|
+
throw new TypeError(`Expected \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof value}\``);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function toUint8Array(value) {
|
|
42
|
+
if (value instanceof ArrayBuffer) {
|
|
43
|
+
return new Uint8Array(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ArrayBuffer.isView(value)) {
|
|
47
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new TypeError(`Unsupported value, got \`${typeof value}\`.`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function concatUint8Arrays(arrays, totalLength) {
|
|
54
|
+
if (arrays.length === 0) {
|
|
55
|
+
return new Uint8Array(0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
totalLength ??= arrays.reduce((accumulator, currentValue) => accumulator + currentValue.length, 0);
|
|
59
|
+
|
|
60
|
+
const returnValue = new Uint8Array(totalLength);
|
|
61
|
+
|
|
62
|
+
let offset = 0;
|
|
63
|
+
for (const array of arrays) {
|
|
64
|
+
assertUint8Array(array);
|
|
65
|
+
returnValue.set(array, offset);
|
|
66
|
+
offset += array.length;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return returnValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function areUint8ArraysEqual(a, b) {
|
|
73
|
+
assertUint8Array(a);
|
|
74
|
+
assertUint8Array(b);
|
|
75
|
+
|
|
76
|
+
if (a === b) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (a.length !== b.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line unicorn/no-for-loop
|
|
85
|
+
for (let index = 0; index < a.length; index++) {
|
|
86
|
+
if (a[index] !== b[index]) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function compareUint8Arrays(a, b) {
|
|
95
|
+
assertUint8Array(a);
|
|
96
|
+
assertUint8Array(b);
|
|
97
|
+
|
|
98
|
+
const length = Math.min(a.length, b.length);
|
|
99
|
+
|
|
100
|
+
for (let index = 0; index < length; index++) {
|
|
101
|
+
const diff = a[index] - b[index];
|
|
102
|
+
if (diff !== 0) {
|
|
103
|
+
return Math.sign(diff);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// At this point, all the compared elements are equal.
|
|
108
|
+
// The shorter array should come first if the arrays are of different lengths.
|
|
109
|
+
return Math.sign(a.length - b.length);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const cachedDecoders = {
|
|
113
|
+
utf8: new globalThis.TextDecoder('utf8'),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export function uint8ArrayToString(array, encoding = 'utf8') {
|
|
117
|
+
assertUint8ArrayOrArrayBuffer(array);
|
|
118
|
+
cachedDecoders[encoding] ??= new globalThis.TextDecoder(encoding);
|
|
119
|
+
return cachedDecoders[encoding].decode(array);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function assertString(value) {
|
|
123
|
+
if (typeof value !== 'string') {
|
|
124
|
+
throw new TypeError(`Expected \`string\`, got \`${typeof value}\``);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const cachedEncoder = new globalThis.TextEncoder();
|
|
129
|
+
|
|
130
|
+
export function stringToUint8Array(string) {
|
|
131
|
+
assertString(string);
|
|
132
|
+
return cachedEncoder.encode(string);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function base64ToBase64Url(base64) {
|
|
136
|
+
return base64.replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function base64UrlToBase64(base64url) {
|
|
140
|
+
return base64url.replaceAll('-', '+').replaceAll('_', '/');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Reference: https://phuoc.ng/collection/this-vs-that/concat-vs-push/
|
|
144
|
+
const MAX_BLOCK_SIZE = 65_535;
|
|
145
|
+
|
|
146
|
+
export function uint8ArrayToBase64(array, {urlSafe = false} = {}) {
|
|
147
|
+
assertUint8Array(array);
|
|
148
|
+
|
|
149
|
+
let base64;
|
|
150
|
+
|
|
151
|
+
if (array.length < MAX_BLOCK_SIZE) {
|
|
152
|
+
// Required as `btoa` and `atob` don't properly support Unicode: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
|
153
|
+
base64 = globalThis.btoa(String.fromCodePoint.apply(this, array));
|
|
154
|
+
} else {
|
|
155
|
+
base64 = '';
|
|
156
|
+
for (const value of array) {
|
|
157
|
+
base64 += String.fromCodePoint(value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
base64 = globalThis.btoa(base64);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return urlSafe ? base64ToBase64Url(base64) : base64;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function base64ToUint8Array(base64String) {
|
|
167
|
+
assertString(base64String);
|
|
168
|
+
return Uint8Array.from(globalThis.atob(base64UrlToBase64(base64String)), x => x.codePointAt(0));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function stringToBase64(string, {urlSafe = false} = {}) {
|
|
172
|
+
assertString(string);
|
|
173
|
+
return uint8ArrayToBase64(stringToUint8Array(string), {urlSafe});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function base64ToString(base64String) {
|
|
177
|
+
assertString(base64String);
|
|
178
|
+
return uint8ArrayToString(base64ToUint8Array(base64String));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const byteToHexLookupTable = Array.from({length: 256}, (_, index) => index.toString(16).padStart(2, '0'));
|
|
182
|
+
|
|
183
|
+
export function uint8ArrayToHex(array) {
|
|
184
|
+
assertUint8Array(array);
|
|
185
|
+
|
|
186
|
+
// Concatenating a string is faster than using an array.
|
|
187
|
+
let hexString = '';
|
|
188
|
+
|
|
189
|
+
// eslint-disable-next-line unicorn/no-for-loop -- Max performance is critical.
|
|
190
|
+
for (let index = 0; index < array.length; index++) {
|
|
191
|
+
hexString += byteToHexLookupTable[array[index]];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return hexString;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const hexToDecimalLookupTable = {
|
|
198
|
+
0: 0,
|
|
199
|
+
1: 1,
|
|
200
|
+
2: 2,
|
|
201
|
+
3: 3,
|
|
202
|
+
4: 4,
|
|
203
|
+
5: 5,
|
|
204
|
+
6: 6,
|
|
205
|
+
7: 7,
|
|
206
|
+
8: 8,
|
|
207
|
+
9: 9,
|
|
208
|
+
a: 10,
|
|
209
|
+
b: 11,
|
|
210
|
+
c: 12,
|
|
211
|
+
d: 13,
|
|
212
|
+
e: 14,
|
|
213
|
+
f: 15,
|
|
214
|
+
A: 10,
|
|
215
|
+
B: 11,
|
|
216
|
+
C: 12,
|
|
217
|
+
D: 13,
|
|
218
|
+
E: 14,
|
|
219
|
+
F: 15,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export function hexToUint8Array(hexString) {
|
|
223
|
+
assertString(hexString);
|
|
224
|
+
|
|
225
|
+
if (hexString.length % 2 !== 0) {
|
|
226
|
+
throw new Error('Invalid Hex string length.');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const resultLength = hexString.length / 2;
|
|
230
|
+
const bytes = new Uint8Array(resultLength);
|
|
231
|
+
|
|
232
|
+
for (let index = 0; index < resultLength; index++) {
|
|
233
|
+
const highNibble = hexToDecimalLookupTable[hexString[index * 2]];
|
|
234
|
+
const lowNibble = hexToDecimalLookupTable[hexString[(index * 2) + 1]];
|
|
235
|
+
|
|
236
|
+
if (highNibble === undefined || lowNibble === undefined) {
|
|
237
|
+
throw new Error(`Invalid Hex character encountered at position ${index * 2}`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
bytes[index] = (highNibble << 4) | lowNibble; // eslint-disable-line no-bitwise
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return bytes;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
@param {DataView} view
|
|
248
|
+
@returns {number}
|
|
249
|
+
*/
|
|
250
|
+
export function getUintBE(view) {
|
|
251
|
+
const {byteLength} = view;
|
|
252
|
+
|
|
253
|
+
if (byteLength === 6) {
|
|
254
|
+
return (view.getUint16(0) * (2 ** 32)) + view.getUint32(2);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (byteLength === 5) {
|
|
258
|
+
return (view.getUint8(0) * (2 ** 32)) + view.getUint32(1);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (byteLength === 4) {
|
|
262
|
+
return view.getUint32(0);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (byteLength === 3) {
|
|
266
|
+
return (view.getUint8(0) * (2 ** 16)) + view.getUint16(1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (byteLength === 2) {
|
|
270
|
+
return view.getUint16(0);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (byteLength === 1) {
|
|
274
|
+
return view.getUint8(0);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
@param {Uint8Array} array
|
|
280
|
+
@param {Uint8Array} value
|
|
281
|
+
@returns {number}
|
|
282
|
+
*/
|
|
283
|
+
export function indexOf(array, value) {
|
|
284
|
+
const arrayLength = array.length;
|
|
285
|
+
const valueLength = value.length;
|
|
286
|
+
|
|
287
|
+
if (valueLength === 0) {
|
|
288
|
+
return -1;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (valueLength > arrayLength) {
|
|
292
|
+
return -1;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const validOffsetLength = arrayLength - valueLength;
|
|
296
|
+
|
|
297
|
+
for (let index = 0; index <= validOffsetLength; index++) {
|
|
298
|
+
let isMatch = true;
|
|
299
|
+
for (let index2 = 0; index2 < valueLength; index2++) {
|
|
300
|
+
if (array[index + index2] !== value[index2]) {
|
|
301
|
+
isMatch = false;
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (isMatch) {
|
|
307
|
+
return index;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return -1;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
@param {Uint8Array} array
|
|
316
|
+
@param {Uint8Array} value
|
|
317
|
+
@returns {boolean}
|
|
318
|
+
*/
|
|
319
|
+
export function includes(array, value) {
|
|
320
|
+
return indexOf(array, value) !== -1;
|
|
321
|
+
}
|