@thi.ng/random 3.8.5 → 4.0.1
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 +11 -1
- package/README.md +10 -5
- package/crypto.d.ts +2 -2
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +4 -10
- package/random-bytes.js +1 -2
- package/uuid.d.ts +0 -19
- package/uuid.js +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-07-
|
|
3
|
+
- **Last updated**: 2024-07-22T14:42:28Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
# [4.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@4.0.0) (2024-07-22)
|
|
13
|
+
|
|
14
|
+
#### 🛑 Breaking changes
|
|
15
|
+
|
|
16
|
+
- migrate/remove UUID functions ([#486](https://github.com/thi-ng/umbrella/issues/486)) ([2ec753e](https://github.com/thi-ng/umbrella/commit/2ec753e))
|
|
17
|
+
- BREAKING CHANGE: migrate UUID functions to [@thi.ng/uuid](https://github.com/thi-ng/umbrella/tree/main/packages/uuid) pkg
|
|
18
|
+
- remove obsolete files
|
|
19
|
+
- update deps/pkg
|
|
20
|
+
- update readme
|
|
21
|
+
|
|
12
22
|
## [3.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/random@3.8.0) (2024-05-08)
|
|
13
23
|
|
|
14
24
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 198 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -31,6 +31,12 @@
|
|
|
31
31
|
|
|
32
32
|
Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation.
|
|
33
33
|
|
|
34
|
+
> [!IMPORTANT]
|
|
35
|
+
> In July 2024 this package was restructured and split-up to extract some
|
|
36
|
+
> features into smaller more focused packages:
|
|
37
|
+
>
|
|
38
|
+
> - [@thi.ng/uuid](https://thi.ng/uuid)
|
|
39
|
+
|
|
34
40
|
This package provides the `IRandom` interface and various (mostly seedable)
|
|
35
41
|
pseudo-random number generator implementations, incl. `IRandom` wrappers for
|
|
36
42
|
`Math.random()` and `window.crypto`:
|
|
@@ -62,7 +68,6 @@ Partially ported from C implementations taken from [c.thi.ng](http://c.thi.ng).
|
|
|
62
68
|
- [`randomID()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/random-id.ts)
|
|
63
69
|
- [`weightedRandom()` / `weightedRandomKey()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/weighted-random.ts)
|
|
64
70
|
- [`uniqueIndices()` / `uniqueValuesFrom()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/unique-indices.ts)
|
|
65
|
-
- [`uuidv4Bytes()` / `uuid()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/uuid.ts)
|
|
66
71
|
|
|
67
72
|
## Status
|
|
68
73
|
|
|
@@ -104,14 +109,14 @@ For Node.js REPL:
|
|
|
104
109
|
const rnd = await import("@thi.ng/random");
|
|
105
110
|
```
|
|
106
111
|
|
|
107
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
112
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.92 KB
|
|
108
113
|
|
|
109
114
|
## Dependencies
|
|
110
115
|
|
|
111
116
|
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
112
|
-
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
113
117
|
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
114
|
-
|
|
118
|
+
|
|
119
|
+
Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
|
|
115
120
|
|
|
116
121
|
## Usage examples
|
|
117
122
|
|
package/crypto.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { IBuffered, ICopy } from "@thi.ng/api";
|
|
|
2
2
|
import { ARandom } from "./arandom.js";
|
|
3
3
|
/**
|
|
4
4
|
* Currently browser only, a `window.crypto` backed {@link IRandom}
|
|
5
|
-
* implementation. Random values are buffered to minimize overhead.
|
|
6
|
-
* is configurable via ctor.
|
|
5
|
+
* implementation. Random values are repeatedly buffered to minimize overhead.
|
|
6
|
+
* Buffer size is configurable via ctor.
|
|
7
7
|
*
|
|
8
8
|
* @remarks
|
|
9
9
|
* Internally uses {@link randomBytes} to source values, which falls back to
|
package/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export * from "./sfc32.js";
|
|
|
14
14
|
export * from "./smush32.js";
|
|
15
15
|
export * from "./system.js";
|
|
16
16
|
export * from "./unique-indices.js";
|
|
17
|
-
export * from "./uuid.js";
|
|
18
17
|
export * from "./weighted-probability.js";
|
|
19
18
|
export * from "./weighted-random.js";
|
|
20
19
|
export * from "./xorshift128.js";
|
package/index.js
CHANGED
|
@@ -14,7 +14,6 @@ export * from "./sfc32.js";
|
|
|
14
14
|
export * from "./smush32.js";
|
|
15
15
|
export * from "./system.js";
|
|
16
16
|
export * from "./unique-indices.js";
|
|
17
|
-
export * from "./uuid.js";
|
|
18
17
|
export * from "./weighted-probability.js";
|
|
19
18
|
export * from "./weighted-random.js";
|
|
20
19
|
export * from "./xorshift128.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/random",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,10 +36,8 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/
|
|
41
|
-
"@thi.ng/errors": "^2.5.12",
|
|
42
|
-
"@thi.ng/hex": "^2.3.50"
|
|
39
|
+
"@thi.ng/api": "^8.11.7",
|
|
40
|
+
"@thi.ng/errors": "^2.5.13"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
43
|
"@microsoft/api-extractor": "^7.47.0",
|
|
@@ -62,7 +60,6 @@
|
|
|
62
60
|
"typedarray",
|
|
63
61
|
"typescript",
|
|
64
62
|
"weighted",
|
|
65
|
-
"uuid",
|
|
66
63
|
"uniform"
|
|
67
64
|
],
|
|
68
65
|
"publishConfig": {
|
|
@@ -131,9 +128,6 @@
|
|
|
131
128
|
"./unique-indices": {
|
|
132
129
|
"default": "./unique-indices.js"
|
|
133
130
|
},
|
|
134
|
-
"./uuid": {
|
|
135
|
-
"default": "./uuid.js"
|
|
136
|
-
},
|
|
137
131
|
"./weighted-probability": {
|
|
138
132
|
"default": "./weighted-probability.js"
|
|
139
133
|
},
|
|
@@ -160,5 +154,5 @@
|
|
|
160
154
|
"ksuid"
|
|
161
155
|
]
|
|
162
156
|
},
|
|
163
|
-
"gitHead": "
|
|
157
|
+
"gitHead": "bd22b0826134b79064169371665b4d6caa9b6066\n"
|
|
164
158
|
}
|
package/random-bytes.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { hasCrypto } from "@thi.ng/checks/has-crypto";
|
|
2
1
|
import { SYSTEM } from "./system.js";
|
|
3
2
|
const randomBytesFrom = (rnd, buf, start = 0, end = buf.length) => {
|
|
4
3
|
for (let i = start; i < end; i++) {
|
|
@@ -6,7 +5,7 @@ const randomBytesFrom = (rnd, buf, start = 0, end = buf.length) => {
|
|
|
6
5
|
}
|
|
7
6
|
return buf;
|
|
8
7
|
};
|
|
9
|
-
const randomBytes =
|
|
8
|
+
const randomBytes = typeof window !== "undefined" && window["crypto"] !== void 0 ? (buf, start = 0, end = buf.length) => (window.crypto.getRandomValues(buf.subarray(start, end)), buf) : (buf, start, end) => randomBytesFrom(SYSTEM, buf, start, end);
|
|
10
9
|
export {
|
|
11
10
|
randomBytes,
|
|
12
11
|
randomBytesFrom
|
package/uuid.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { IRandom } from "./api.js";
|
|
2
|
-
/**
|
|
3
|
-
* Depending on if `rnd` is given, uses {@link randomBytesFrom} or
|
|
4
|
-
* {@link randomBytes} to fill given (optional) byte array with a new UUIDv4.
|
|
5
|
-
* Creates new Uint8Array if none given.
|
|
6
|
-
*
|
|
7
|
-
* @param buf -
|
|
8
|
-
* @param rnd -
|
|
9
|
-
*/
|
|
10
|
-
export declare const uuidv4Bytes: (buf?: Uint8Array, rnd?: IRandom) => Uint8Array;
|
|
11
|
-
/**
|
|
12
|
-
* Returns a UUID string, either from given byte array, or if omitted, using a
|
|
13
|
-
* new UUID v4 produced by {@link uuidv4Bytes}.
|
|
14
|
-
*
|
|
15
|
-
* @param id - byte array
|
|
16
|
-
* @param i - start index
|
|
17
|
-
*/
|
|
18
|
-
export declare const uuid: (id?: ArrayLike<number>, i?: number) => string;
|
|
19
|
-
//# sourceMappingURL=uuid.d.ts.map
|
package/uuid.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { uuid as $uuid } from "@thi.ng/hex";
|
|
2
|
-
import { randomBytes, randomBytesFrom } from "./random-bytes.js";
|
|
3
|
-
const uuidv4Bytes = (buf, rnd) => {
|
|
4
|
-
buf = buf || new Uint8Array(16);
|
|
5
|
-
buf = rnd ? randomBytesFrom(rnd, buf) : randomBytes(buf);
|
|
6
|
-
buf[6] = 64 | buf[6] & 15;
|
|
7
|
-
buf[8] = 128 | buf[8] & 63;
|
|
8
|
-
return buf;
|
|
9
|
-
};
|
|
10
|
-
const __buf = new Uint8Array(16);
|
|
11
|
-
const uuid = (id, i = 0) => $uuid(id || uuidv4Bytes(__buf), i);
|
|
12
|
-
export {
|
|
13
|
-
uuid,
|
|
14
|
-
uuidv4Bytes
|
|
15
|
-
};
|