@williamthorsen/toolbelt.numbers 5.0.0 → 6.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 CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 6.0.1 — 2026-08-13
6
+
7
+ ### Tooling
8
+
9
+ - Remove redundant .gitignore files
10
+ - Populate manifest metadata and adopt a pnpm catalog (#140)
11
+
12
+ Adopts a pnpm catalog to avoid specifying the version of a common dependency in multiple places. Separately, fixes violations of newly activated `package-json` lint rules. Missing values have been added to `package.json` fields across the repo, and package descriptions are improved.
13
+
14
+ ## 6.0.0 — 2026-08-12
15
+
16
+ ### Features
17
+
18
+ - 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
19
+
20
+ Renames thirteen functions across various packages to align with a consistent naming pattern.
21
+
22
+ ### Refactoring
23
+
24
+ - Stop shipping test-only and dead support modules (#117)
25
+
26
+ Fixes an issue where `@williamthorsen/toolbelt.numbers`, `@williamthorsen/toolbelt.objects`, and `@williamthorsen/toolbelt.strings` each shipped a module that was never importable.
27
+
28
+ - Align stray modules with layout and TypeScript conventions (#118)
29
+
30
+ 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.
31
+
5
32
  ## 5.0.0 — 2026-08-08
6
33
 
7
34
  ### Features
package/README.md CHANGED
@@ -2,19 +2,7 @@
2
2
 
3
3
  Utility functions for working with numbers.
4
4
 
5
- <!-- section:release-notes -->
6
- ## Release notes — v5.0.0 (2026-08-08)
7
-
8
- ### Features
9
-
10
- - 🚨 **Breaking:** Spawn seeded number generator of same subclass (#84)
11
-
12
- A seeded generator spawned from a subclass now matches that subclass, so `IntSeededRng.withSeed` supplies the wrapped function integers where it previously supplied floats. Callers relying on values derived through that path must re-baseline. A detached reference such as `const { withSeed } = SeededRng` now throws.
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.
17
- <!-- /section:release-notes -->
5
+ <!-- section:release-notes --><!-- /section:release-notes -->
18
6
 
19
7
  ## Installation
20
8
 
@@ -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 getFakeMathRandom(base);
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() : getFakeMathRandom(seed);
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 getFakeMathRandom(this._seed);
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: getFakeMathRandom(this.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: getFakeMathRandom(this.seed) });
86
+ return pickInteger({ min: 1, max: 2 ** 32 - 1, seed: computeFakeMathRandom(this.seed) });
87
87
  }
88
88
  }
@@ -1,4 +1,4 @@
1
- import { getFakeMathRandom } from "./getFakeMathRandom.js";
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(getFakeMathRandom(value) * MAX_INTEGER);
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;
@@ -1,4 +1,4 @@
1
- export function getFakeMathRandom(seed) {
1
+ export function computeFakeMathRandom(seed) {
2
2
  const strSeed = seed.toString().replace('.', '');
3
3
  let hash = 0;
4
4
  for (const char of strSeed) {
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.numbers",
3
- "version": "5.0.0",
4
- "description": "API",
5
- "keywords": [],
3
+ "version": "6.0.1",
4
+ "description": "Utility functions for working with numbers",
5
+ "keywords": [
6
+ "esm",
7
+ "math",
8
+ "number",
9
+ "random",
10
+ "seeded-random",
11
+ "toolbelt",
12
+ "typescript",
13
+ "utilities"
14
+ ],
6
15
  "homepage": "https://github.com/williamthorsen/toolbelt/tree/main/packages/numbers#readme",
7
16
  "bugs": {
8
17
  "url": "https://github.com/williamthorsen/toolbelt/issues"
@@ -14,6 +23,7 @@
14
23
  },
15
24
  "license": "ISC",
16
25
  "author": "William Thorsen <william@thorsen.dev> (https://github.com/williamthorsen)",
26
+ "sideEffects": false,
17
27
  "type": "module",
18
28
  "exports": {
19
29
  ".": {
@@ -1,2 +0,0 @@
1
- export type FunctionOrValue<T> = T | (() => T);
2
- export declare function evaluate<T>(input: FunctionOrValue<T>): T;
@@ -1,6 +0,0 @@
1
- function isFunction(value) {
2
- return typeof value === 'function';
3
- }
4
- export function evaluate(input) {
5
- return isFunction(input) ? input() : input;
6
- }
@@ -1 +0,0 @@
1
- export declare function getFakeMathRandom(seed: number): number;