@williamthorsen/toolbelt.numbers 5.0.0 → 6.0.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/CHANGELOG.md +18 -0
- package/README.md +3 -7
- package/dist/esm/1-proposed/makeRng.js +2 -2
- package/dist/esm/3-candidate/generateRandom.js +2 -2
- package/dist/esm/3-candidate/seeded-rng.js +4 -4
- package/dist/esm/internal/IntegerSeed.js +2 -2
- package/dist/esm/internal/computeFakeMathRandom.d.ts +1 -0
- package/dist/esm/internal/{getFakeMathRandom.js → computeFakeMathRandom.js} +1 -1
- package/package.json +1 -1
- package/dist/esm/internal/evaluate.d.ts +0 -2
- package/dist/esm/internal/evaluate.js +0 -6
- package/dist/esm/internal/getFakeMathRandom.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 6.0.0 — 2026-08-12
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
10
|
+
|
|
11
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
12
|
+
|
|
13
|
+
### Refactoring
|
|
14
|
+
|
|
15
|
+
- Stop shipping test-only and dead support modules (#117)
|
|
16
|
+
|
|
17
|
+
Fixes an issue where `@williamthorsen/toolbelt.numbers`, `@williamthorsen/toolbelt.objects`, and `@williamthorsen/toolbelt.strings` each shipped a module that was never importable.
|
|
18
|
+
|
|
19
|
+
- Align stray modules with layout and TypeScript conventions (#118)
|
|
20
|
+
|
|
21
|
+
Aligns all packages with code-layout and annotation conventions, ending a handful of long-standing exceptions. Documentation has been updated to make the conventions clear.
|
|
22
|
+
|
|
5
23
|
## 5.0.0 — 2026-08-08
|
|
6
24
|
|
|
7
25
|
### Features
|
package/README.md
CHANGED
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
Utility functions for working with numbers.
|
|
4
4
|
|
|
5
5
|
<!-- section:release-notes -->
|
|
6
|
-
## Release notes —
|
|
6
|
+
## Release notes — v6.0.0 (2026-08-12)
|
|
7
7
|
|
|
8
8
|
### Features
|
|
9
9
|
|
|
10
|
-
- 🚨 **Breaking:**
|
|
10
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- Use underscore separator at 4 digits or more
|
|
15
|
-
|
|
16
|
-
Changes the `unicorn/numeric-separators-style` rule config so that separators are consistently used in base 10 numbers, instead of exempting numbers of 5 digits or less.
|
|
12
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
17
13
|
<!-- /section:release-notes -->
|
|
18
14
|
|
|
19
15
|
## Installation
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { computeFakeMathRandom } from "../internal/computeFakeMathRandom.js";
|
|
1
2
|
import { evaluateSeed } from "../internal/evaluateSeed.js";
|
|
2
|
-
import { getFakeMathRandom } from "../internal/getFakeMathRandom.js";
|
|
3
3
|
export function makeRng(seed) {
|
|
4
4
|
const inputSeed = evaluateSeed(seed);
|
|
5
5
|
if (inputSeed === undefined) {
|
|
@@ -8,6 +8,6 @@ export function makeRng(seed) {
|
|
|
8
8
|
let base = inputSeed;
|
|
9
9
|
return function random() {
|
|
10
10
|
base = (base + 1) % Number.MAX_SAFE_INTEGER;
|
|
11
|
-
return
|
|
11
|
+
return computeFakeMathRandom(base);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { computeFakeMathRandom } from "../internal/computeFakeMathRandom.js";
|
|
1
2
|
import { evaluateSeed } from "../internal/evaluateSeed.js";
|
|
2
|
-
import { getFakeMathRandom } from "../internal/getFakeMathRandom.js";
|
|
3
3
|
import { scale } from "./scale.js";
|
|
4
4
|
export function generateRandom(options = {}) {
|
|
5
5
|
const { min = 0, max = 1 } = options;
|
|
6
6
|
const seed = evaluateSeed(options.seed);
|
|
7
|
-
const randomNumber = seed === undefined ? Math.random() :
|
|
7
|
+
const randomNumber = seed === undefined ? Math.random() : computeFakeMathRandom(seed);
|
|
8
8
|
return scale(randomNumber, { min, max });
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { computeFakeMathRandom } from "../internal/computeFakeMathRandom.js";
|
|
1
2
|
import { checkIsRngLike, evaluateSeed } from "../internal/evaluateSeed.js";
|
|
2
|
-
import { getFakeMathRandom } from "../internal/getFakeMathRandom.js";
|
|
3
3
|
import { IntegerSeed } from "../internal/IntegerSeed.js";
|
|
4
4
|
import { wrapSum } from "../internal/wrapSum.js";
|
|
5
5
|
import { pickInteger } from "./pickInteger.js";
|
|
@@ -69,7 +69,7 @@ export class SeededRng {
|
|
|
69
69
|
return scaleInt(value, { min: 1, max: IntegerSeed.max }, { min: 1, max: this.maxBase });
|
|
70
70
|
}
|
|
71
71
|
generateValue() {
|
|
72
|
-
return
|
|
72
|
+
return computeFakeMathRandom(this._seed);
|
|
73
73
|
}
|
|
74
74
|
initializeSeeds(baseSeed) {
|
|
75
75
|
this.baseSeed = wrapSum(this.maxBase, IntegerSeed.toInt(baseSeed));
|
|
@@ -78,11 +78,11 @@ export class SeededRng {
|
|
|
78
78
|
}
|
|
79
79
|
export class IntSeededRng extends SeededRng {
|
|
80
80
|
generateValue() {
|
|
81
|
-
return pickInteger({ min: 1, max: Number.MAX_SAFE_INTEGER, seed:
|
|
81
|
+
return pickInteger({ min: 1, max: Number.MAX_SAFE_INTEGER, seed: computeFakeMathRandom(this.seed) });
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
export class Int32SeededRng extends SeededRng {
|
|
85
85
|
generateValue() {
|
|
86
|
-
return pickInteger({ min: 1, max: 2 ** 32 - 1, seed:
|
|
86
|
+
return pickInteger({ min: 1, max: 2 ** 32 - 1, seed: computeFakeMathRandom(this.seed) });
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computeFakeMathRandom } from "./computeFakeMathRandom.js";
|
|
2
2
|
const MAX_INTEGER = 2 ** 31 - 1;
|
|
3
3
|
export const IntegerSeed = {
|
|
4
4
|
max: MAX_INTEGER,
|
|
@@ -14,7 +14,7 @@ function toIntegerSeed(value) {
|
|
|
14
14
|
let integer = (() => {
|
|
15
15
|
if (Number.isSafeInteger(value))
|
|
16
16
|
return value;
|
|
17
|
-
return Math.floor(
|
|
17
|
+
return Math.floor(computeFakeMathRandom(value) * MAX_INTEGER);
|
|
18
18
|
})();
|
|
19
19
|
integer %= MAX_INTEGER;
|
|
20
20
|
if (integer <= 0) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function computeFakeMathRandom(seed: number): number;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getFakeMathRandom(seed: number): number;
|