Skip to content

Commit

Permalink
refactor(random): migrate/remove UUID functions (#486)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: migrate UUID functions to thi.ng/uuid pkg

- remove obsolete files
- update deps/pkg
- update readme
  • Loading branch information
postspectacular committed Jul 20, 2024
1 parent 4ca1750 commit 2ec753e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 74 deletions.
7 changes: 2 additions & 5 deletions packages/random/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)

> [!NOTE]
> This is one of 194 standalone projects, maintained as part
> This is one of 197 standalone projects, maintained as part
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
> and anti-framework.
>
Expand Down Expand Up @@ -62,7 +62,6 @@ Partially ported from C implementations taken from [c.thi.ng](http://c.thi.ng).
- [`randomID()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/random-id.ts)
- [`weightedRandom()` / `weightedRandomKey()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/weighted-random.ts)
- [`uniqueIndices()` / `uniqueValuesFrom()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/unique-indices.ts)
- [`uuidv4Bytes()` / `uuid()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/uuid.ts)

## Status

Expand Down Expand Up @@ -104,14 +103,12 @@ For Node.js REPL:
const rnd = await import("@thi.ng/random");
```

Package sizes (brotli'd, pre-treeshake): ESM: 2.02 KB
Package sizes (brotli'd, pre-treeshake): ESM: 1.92 KB

## Dependencies

- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
- [@thi.ng/hex](https://github.com/thi-ng/umbrella/tree/develop/packages/hex)

## Usage examples

Expand Down
5 changes: 1 addition & 4 deletions packages/random/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
},
"dependencies": {
"@thi.ng/api": "^8.11.6",
"@thi.ng/checks": "^3.6.8",
"@thi.ng/errors": "^2.5.12",
"@thi.ng/hex": "^2.3.50"
"@thi.ng/errors": "^2.5.12"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.47.0",
Expand All @@ -62,7 +60,6 @@
"typedarray",
"typescript",
"weighted",
"uuid",
"uniform"
],
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/random/src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { randomBytes } from "./random-bytes.js";

/**
* Currently browser only, a `window.crypto` backed {@link IRandom}
* implementation. Random values are buffered to minimize overhead. Buffer size
* is configurable via ctor.
* implementation. Random values are repeatedly buffered to minimize overhead.
* Buffer size is configurable via ctor.
*
* @remarks
* Internally uses {@link randomBytes} to source values, which falls back to
Expand Down
1 change: 0 additions & 1 deletion packages/random/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export * from "./sfc32.js";
export * from "./smush32.js";
export * from "./system.js";
export * from "./unique-indices.js";
export * from "./uuid.js";
export * from "./weighted-probability.js";
export * from "./weighted-random.js";
export * from "./xorshift128.js";
Expand Down
14 changes: 7 additions & 7 deletions packages/random/src/random-bytes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { hasCrypto } from "@thi.ng/checks/has-crypto";
import type { IRandom } from "./api.js";
import { SYSTEM } from "./system.js";

Expand Down Expand Up @@ -32,9 +31,10 @@ export const randomBytesFrom = (
* @param start -
* @param end -
*/
export const randomBytes = hasCrypto()
? (buf: Uint8Array, start = 0, end = buf.length) => (
window.crypto.getRandomValues(buf.subarray(start, end)), buf
)
: (buf: Uint8Array, start?: number, end?: number) =>
randomBytesFrom(SYSTEM, buf, start, end);
export const randomBytes =
typeof window !== "undefined" && window["crypto"] !== undefined
? (buf: Uint8Array, start = 0, end = buf.length) => (
window.crypto.getRandomValues(buf.subarray(start, end)), buf
)
: (buf: Uint8Array, start?: number, end?: number) =>
randomBytesFrom(SYSTEM, buf, start, end);
32 changes: 0 additions & 32 deletions packages/random/src/uuid.ts

This file was deleted.

22 changes: 0 additions & 22 deletions packages/random/test/uuid.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/random/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Partially ported from C implementations taken from [c.thi.ng](http://c.thi.ng).
- [`randomID()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/random-id.ts)
- [`weightedRandom()` / `weightedRandomKey()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/weighted-random.ts)
- [`uniqueIndices()` / `uniqueValuesFrom()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/unique-indices.ts)
- [`uuidv4Bytes()` / `uuid()`](https://github.com/thi-ng/umbrella/tree/develop/packages/random/src/uuid.ts)

{{meta.status}}

Expand Down

0 comments on commit 2ec753e

Please sign in to comment.