@guanghechen/byte 1.0.0-alpha.4 → 1.0.0-alpha.6
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/CHANGELOG.md +30 -16
- package/README.md +5 -5
- package/lib/cjs/index.cjs +21 -6
- package/lib/esm/index.mjs +21 -7
- package/lib/types/index.d.ts +12 -1
- package/package.json +4 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,44 +1,58 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
# [1.0.0-alpha.4](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.3...@guanghechen/byte@1.0.0-alpha.4) (2023-11-29)
|
|
3
|
+
All notable changes to this project will be documented in this file. See
|
|
4
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
5
|
|
|
6
|
+
# [1.0.0-alpha.6](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.5...@guanghechen/byte@1.0.0-alpha.6) (2024-02-03)
|
|
8
7
|
|
|
9
8
|
### Performance Improvements
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
- 💄 fix lint
|
|
11
|
+
([2d5bb6f](https://github.com/guanghechen/sora/commit/2d5bb6f03d0312a42c1117d95181df8b69de827a))
|
|
12
|
+
- 🔧 fix nx scripts
|
|
13
|
+
([47bc4e6](https://github.com/guanghechen/sora/commit/47bc4e66df825cb37127219bccf60dc81d6a9b48))
|
|
14
|
+
- 🔧 update tsconfig
|
|
15
|
+
([98855bc](https://github.com/guanghechen/sora/commit/98855bcc245d98c61217c5bafc6a1b2506b7824d))
|
|
12
16
|
|
|
17
|
+
# Change Log
|
|
13
18
|
|
|
19
|
+
All notable changes to this project will be documented in this file. See
|
|
20
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
14
21
|
|
|
22
|
+
# [1.0.0-alpha.5](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.4...@guanghechen/byte@1.0.0-alpha.5) (2024-01-02)
|
|
15
23
|
|
|
24
|
+
### Performance Improvements
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
- :art: prefer randomBytes from 'crypto' cause it returns true-random numbers
|
|
27
|
+
([7d0e7fd](https://github.com/guanghechen/sora/commit/7d0e7fd06b991b2121c01b639cf6d5d36eec4ea6))
|
|
28
|
+
- 🎨 add 'areSameBytes'
|
|
29
|
+
([fc0f163](https://github.com/guanghechen/sora/commit/fc0f163b9b78cf382e6e8b601ed53f95e2a14449))
|
|
18
30
|
|
|
31
|
+
# [1.0.0-alpha.4](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.3...@guanghechen/byte@1.0.0-alpha.4) (2023-11-29)
|
|
19
32
|
|
|
20
33
|
### Performance Improvements
|
|
21
34
|
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
- 🔧 no longer to require node engine version in packages
|
|
36
|
+
([6dc2014](https://github.com/guanghechen/sora/commit/6dc2014122dd44bcadc893e2ee98697265e7d61e))
|
|
24
37
|
|
|
38
|
+
# [1.0.0-alpha.3](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.2...@guanghechen/byte@1.0.0-alpha.3) (2023-11-18)
|
|
25
39
|
|
|
40
|
+
### Performance Improvements
|
|
26
41
|
|
|
42
|
+
- 🔧 upgrade engine version requirement from '>= 16.0.0' to '>= 18.0.0'
|
|
43
|
+
([ddb9521](https://github.com/guanghechen/sora/commit/ddb9521b529b2ca838554794339b9e27ac80b8aa))
|
|
27
44
|
|
|
28
45
|
# [1.0.0-alpha.2](https://github.com/guanghechen/sora/compare/@guanghechen/byte@1.0.0-alpha.1...@guanghechen/byte@1.0.0-alpha.2) (2023-10-25)
|
|
29
46
|
|
|
30
|
-
|
|
31
47
|
### Features
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
- ✨ support to encode/decode in base64 format (forked from
|
|
50
|
+
[@algorithm](https://github.com/algorithm).ts/base64)
|
|
51
|
+
([e30e234](https://github.com/guanghechen/sora/commit/e30e234494251f6ce79ce9b697c49179022b96a3))
|
|
38
52
|
|
|
39
53
|
# 1.0.0-alpha.1 (2023-10-22)
|
|
40
54
|
|
|
41
|
-
|
|
42
55
|
### Features
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
- ✨ add @guanghechen/byte
|
|
58
|
+
([23c4579](https://github.com/guanghechen/sora/commit/23c4579b3c82a710c026c3e1ffa5df27e240ef83))
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<header>
|
|
2
2
|
<h1 align="center">
|
|
3
|
-
<a href="https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.
|
|
3
|
+
<a href="https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.6/packages/byte#readme">@guanghechen/byte</a>
|
|
4
4
|
</h1>
|
|
5
5
|
<div align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/@guanghechen/byte">
|
|
@@ -51,16 +51,15 @@
|
|
|
51
51
|
|
|
52
52
|
Utility functions for bytes (Uint8Array).
|
|
53
53
|
|
|
54
|
-
|
|
55
54
|
## Install
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
- npm
|
|
58
57
|
|
|
59
58
|
```bash
|
|
60
59
|
npm install --save @guanghechen/byte
|
|
61
60
|
```
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
- yarn
|
|
64
63
|
|
|
65
64
|
```bash
|
|
66
65
|
yarn add @guanghechen/byte
|
|
@@ -68,4 +67,5 @@ Utility functions for bytes (Uint8Array).
|
|
|
68
67
|
|
|
69
68
|
## Usage
|
|
70
69
|
|
|
71
|
-
[homepage]:
|
|
70
|
+
[homepage]:
|
|
71
|
+
https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.6/packages/byte#readme
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
3
5
|
const CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
4
6
|
const CODE_PADDING = '=';
|
|
5
7
|
const CODE_LIST = CODES.split('');
|
|
@@ -194,6 +196,22 @@ function destroyBytesList(bytesList) {
|
|
|
194
196
|
destroyBytes(bytes);
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
function areSameBytes(bytes1, bytes2) {
|
|
200
|
+
if (bytes1 === bytes2)
|
|
201
|
+
return true;
|
|
202
|
+
if (bytes1 === undefined)
|
|
203
|
+
return false;
|
|
204
|
+
if (bytes2 === undefined)
|
|
205
|
+
return false;
|
|
206
|
+
if (bytes1.length !== bytes2.length)
|
|
207
|
+
return false;
|
|
208
|
+
for (let i = 0; i < bytes1.length; ++i) {
|
|
209
|
+
if (bytes1.at(i) !== bytes2.at(i))
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
|
|
197
215
|
function mergeBytes(bytesList) {
|
|
198
216
|
const bytesSize = bytesList.reduce((acc, cur) => acc + cur.length, 0);
|
|
199
217
|
const result = new Uint8Array(bytesSize);
|
|
@@ -207,14 +225,11 @@ function mergeBytes(bytesList) {
|
|
|
207
225
|
}
|
|
208
226
|
|
|
209
227
|
function randomBytes(size) {
|
|
210
|
-
const bytes =
|
|
211
|
-
|
|
212
|
-
const v = Math.random() * 256;
|
|
213
|
-
bytes[i] = v >>> 0;
|
|
214
|
-
}
|
|
215
|
-
return bytes;
|
|
228
|
+
const bytes = crypto.randomBytes(size);
|
|
229
|
+
return Uint8Array.from(bytes);
|
|
216
230
|
}
|
|
217
231
|
|
|
232
|
+
exports.areSameBytes = areSameBytes;
|
|
218
233
|
exports.base64Text2bytes = base64Text2bytes;
|
|
219
234
|
exports.bytes2base64Text = bytes2base64Text;
|
|
220
235
|
exports.bytes2hexText = bytes2hexText;
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { randomBytes as randomBytes$1 } from 'crypto';
|
|
2
|
+
|
|
1
3
|
const CODES = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
2
4
|
const CODE_PADDING = '=';
|
|
3
5
|
const CODE_LIST = CODES.split('');
|
|
@@ -192,6 +194,22 @@ function destroyBytesList(bytesList) {
|
|
|
192
194
|
destroyBytes(bytes);
|
|
193
195
|
}
|
|
194
196
|
|
|
197
|
+
function areSameBytes(bytes1, bytes2) {
|
|
198
|
+
if (bytes1 === bytes2)
|
|
199
|
+
return true;
|
|
200
|
+
if (bytes1 === undefined)
|
|
201
|
+
return false;
|
|
202
|
+
if (bytes2 === undefined)
|
|
203
|
+
return false;
|
|
204
|
+
if (bytes1.length !== bytes2.length)
|
|
205
|
+
return false;
|
|
206
|
+
for (let i = 0; i < bytes1.length; ++i) {
|
|
207
|
+
if (bytes1.at(i) !== bytes2.at(i))
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
195
213
|
function mergeBytes(bytesList) {
|
|
196
214
|
const bytesSize = bytesList.reduce((acc, cur) => acc + cur.length, 0);
|
|
197
215
|
const result = new Uint8Array(bytesSize);
|
|
@@ -205,12 +223,8 @@ function mergeBytes(bytesList) {
|
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
function randomBytes(size) {
|
|
208
|
-
const bytes =
|
|
209
|
-
|
|
210
|
-
const v = Math.random() * 256;
|
|
211
|
-
bytes[i] = v >>> 0;
|
|
212
|
-
}
|
|
213
|
-
return bytes;
|
|
226
|
+
const bytes = randomBytes$1(size);
|
|
227
|
+
return Uint8Array.from(bytes);
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
export { base64Text2bytes, bytes2base64Text, bytes2hexText, bytes2text, bytes2utf8Text, destroyBytes, destroyBytesList, hexText2bytes, mergeBytes, randomBytes, text2bytes, utf8Text2bytes, validateBase64Text };
|
|
230
|
+
export { areSameBytes, base64Text2bytes, bytes2base64Text, bytes2hexText, bytes2text, bytes2utf8Text, destroyBytes, destroyBytesList, hexText2bytes, mergeBytes, randomBytes, text2bytes, utf8Text2bytes, validateBase64Text };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -30,13 +30,24 @@ declare function destroyBytes(bytes: Uint8Array): void;
|
|
|
30
30
|
*/
|
|
31
31
|
declare function destroyBytesList(bytesList: Uint8Array[]): void;
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Check if two Uint8Array are same.
|
|
35
|
+
* @param bytes1
|
|
36
|
+
* @param bytes2
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
declare function areSameBytes(bytes1: Readonly<Uint8Array> | undefined, bytes2: Readonly<Uint8Array> | undefined): boolean;
|
|
40
|
+
|
|
33
41
|
declare function mergeBytes(bytesList: ReadonlyArray<Uint8Array>): Uint8Array;
|
|
34
42
|
|
|
35
43
|
/**
|
|
36
44
|
* Generate a random bytes with the given size.
|
|
45
|
+
*
|
|
46
|
+
* Use randomBytes from 'crypto' cause it returns true random numbers.
|
|
47
|
+
*
|
|
37
48
|
* @param size
|
|
38
49
|
* @returns
|
|
39
50
|
*/
|
|
40
51
|
declare function randomBytes(size: number): Uint8Array;
|
|
41
52
|
|
|
42
|
-
export { type IByteEncoding, base64Text2bytes, bytes2base64Text, bytes2hexText, bytes2text, bytes2utf8Text, destroyBytes, destroyBytesList, hexText2bytes, mergeBytes, randomBytes, text2bytes, utf8Text2bytes, validateBase64Text };
|
|
53
|
+
export { type IByteEncoding, areSameBytes, base64Text2bytes, bytes2base64Text, bytes2hexText, bytes2text, bytes2utf8Text, destroyBytes, destroyBytesList, hexText2bytes, mergeBytes, randomBytes, text2bytes, utf8Text2bytes, validateBase64Text };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guanghechen/byte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "Utility functions for bytes (Uint8Array).",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.
|
|
11
|
+
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.5",
|
|
12
12
|
"directory": "packages/byte"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.
|
|
14
|
+
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/byte@1.0.0-alpha.5/packages/byte#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"Uint8Array"
|
|
17
17
|
],
|
|
@@ -37,10 +37,5 @@
|
|
|
37
37
|
"LICENSE",
|
|
38
38
|
"README.md"
|
|
39
39
|
],
|
|
40
|
-
"
|
|
41
|
-
"build": "../../node_modules/.bin/rimraf lib/ && ../../node_modules/.bin/cross-env NODE_ENV=production ../../node_modules/.bin/rollup -c ../../rollup.config.mjs",
|
|
42
|
-
"prepublishOnly": "yarn build",
|
|
43
|
-
"test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
|
|
44
|
-
},
|
|
45
|
-
"gitHead": "eca17030162daa875cb8e1fd92087257932e6e41"
|
|
40
|
+
"gitHead": "9c051a66df3f4dbd8eddd709046af0a975fdc702"
|
|
46
41
|
}
|