@williamthorsen/toolbelt.arrays 3.3.9 → 4.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 +48 -0
- package/README.md +9 -1
- package/dist/esm/3-candidate/findWeightedIndex.d.ts +3 -0
- package/dist/esm/3-candidate/{getWeightedIndex.js → findWeightedIndex.js} +1 -1
- package/dist/esm/3-candidate/index.d.ts +3 -3
- package/dist/esm/3-candidate/index.js +3 -3
- package/dist/esm/3-candidate/listDuplicateItems.d.ts +1 -0
- package/dist/esm/3-candidate/{getDuplicateItems.js → listDuplicateItems.js} +1 -2
- package/dist/esm/3-candidate/listUniqueItems.d.ts +1 -0
- package/dist/esm/3-candidate/listUniqueItems.js +3 -0
- package/dist/esm/3-candidate/pickWeightedIndex.js +2 -2
- package/dist/esm/3-candidate/shuffle.js +8 -6
- package/package.json +3 -3
- package/dist/esm/0-strawman/getSetItems.d.ts +0 -1
- package/dist/esm/0-strawman/getSetItems.js +0 -3
- package/dist/esm/3-candidate/getDuplicateItems.d.ts +0 -2
- package/dist/esm/3-candidate/getUniqueItems.d.ts +0 -1
- package/dist/esm/3-candidate/getUniqueItems.js +0 -3
- package/dist/esm/3-candidate/getWeightedIndex.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 4.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
|
+
- Align stray modules with layout and TypeScript conventions (#118)
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
## 3.4.0 — 2026-08-08
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
- Use underscore separator at 4 digits or more
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
### Refactoring
|
|
28
|
+
|
|
29
|
+
- Fix slug punctuation and require safe integers (#86)
|
|
30
|
+
|
|
31
|
+
- Fixes an issue where the use of certain letters as the slug separator in `slugify` would leave punctuation marks in the result.
|
|
32
|
+
- Time-unit conversions, scaling range bounds, normal-distribution interval counts, and array indices in object paths now reject values too large to represent exactly instead of silently losing precision.
|
|
33
|
+
- Seeded number generators now produce distinct sequences for seeds at or beyond 2^53, where adjacent seeds previously collapsed onto nearly identical output. A seed of that size saved before this release no longer reproduces the same output.
|
|
34
|
+
|
|
35
|
+
### Tooling
|
|
36
|
+
|
|
37
|
+
- Migrate Vitest configs to the nmr projects model (#73)
|
|
38
|
+
|
|
39
|
+
Packages no longer need to declare their own Vitest config. Test suites are now selected by a test file's name suffix rather than by choosing a config file: `*.app.test.ts` and `*.int.test.ts` route to the app and integration suites, and everything else runs as a unit test. Local development is now declared to require Node 24.16 or later.
|
|
40
|
+
|
|
41
|
+
- Adopt the centralized tsconfig with more modern settings (#81)
|
|
42
|
+
|
|
43
|
+
Raises the language level for typechecking to ES2025, so code across the monorepo can now use `Promise.try`, `RegExp.escape`, the new `Set` methods, and iterator helpers. Typechecking is also stricter: properties reached through an index signature must now be read with bracket access. Published output is unchanged.
|
|
44
|
+
|
|
45
|
+
- Adopt four deferred unicorn lint rules (#90)
|
|
46
|
+
|
|
47
|
+
The strict-lint severity cap of four lint rules has been raised to error: `no-array-from-fill`, `no-return-array-push`, `no-unreadable-array-destructuring`, and `prefer-math-constants`.
|
|
48
|
+
|
|
49
|
+
- Use identical compiler settings for all packages (#105)
|
|
50
|
+
|
|
51
|
+
All packages now have identical compiler settings, using the settings from the `@williamthorsen/tsconfig` base config without modification.
|
|
52
|
+
|
|
5
53
|
## 3.3.9 — 2026-07-27
|
|
6
54
|
|
|
7
55
|
### Tooling
|
package/README.md
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Array utilities.
|
|
4
4
|
|
|
5
|
-
<!-- section:release-notes
|
|
5
|
+
<!-- section:release-notes -->
|
|
6
|
+
## Release notes — v4.0.0 (2026-08-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
11
|
+
|
|
12
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
13
|
+
<!-- /section:release-notes -->
|
|
6
14
|
|
|
7
15
|
## Installation
|
|
8
16
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { arraify } from './arraify.js';
|
|
2
2
|
export { extractWeights } from './extractWeights.js';
|
|
3
3
|
export { findOrThrow } from './findOrThrow.js';
|
|
4
|
+
export { findWeightedIndex } from './findWeightedIndex.js';
|
|
4
5
|
export { getAtIndexOrThrow } from './getAtIndexOrThrow.js';
|
|
5
|
-
export { getDuplicateItems } from './getDuplicateItems.js';
|
|
6
|
-
export { getUniqueItems } from './getUniqueItems.js';
|
|
7
|
-
export { getWeightedIndex } from './getWeightedIndex.js';
|
|
8
6
|
export { includes } from './includes.js';
|
|
7
|
+
export { listDuplicateItems } from './listDuplicateItems.js';
|
|
8
|
+
export { listUniqueItems } from './listUniqueItems.js';
|
|
9
9
|
export { makePickWeightedItemFromDistribution } from './makePickWeightedItemFromDistribution.js';
|
|
10
10
|
export { makeNullishCompare, nullishCompare } from './nullishCompare.js';
|
|
11
11
|
export { pickItem } from './pickItem.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { arraify } from "./arraify.js";
|
|
2
2
|
export { extractWeights } from "./extractWeights.js";
|
|
3
3
|
export { findOrThrow } from "./findOrThrow.js";
|
|
4
|
+
export { findWeightedIndex } from "./findWeightedIndex.js";
|
|
4
5
|
export { getAtIndexOrThrow } from "./getAtIndexOrThrow.js";
|
|
5
|
-
export { getDuplicateItems } from "./getDuplicateItems.js";
|
|
6
|
-
export { getUniqueItems } from "./getUniqueItems.js";
|
|
7
|
-
export { getWeightedIndex } from "./getWeightedIndex.js";
|
|
8
6
|
export { includes } from "./includes.js";
|
|
7
|
+
export { listDuplicateItems } from "./listDuplicateItems.js";
|
|
8
|
+
export { listUniqueItems } from "./listUniqueItems.js";
|
|
9
9
|
export { makePickWeightedItemFromDistribution } from "./makePickWeightedItemFromDistribution.js";
|
|
10
10
|
export { makeNullishCompare, nullishCompare } from "./nullishCompare.js";
|
|
11
11
|
export { pickItem } from "./pickItem.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listDuplicateItems<T>(items: Iterable<T>): T[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function listDuplicateItems(items) {
|
|
2
2
|
const duplicates = new Set();
|
|
3
3
|
const seen = new Set();
|
|
4
4
|
for (const item of items) {
|
|
@@ -11,4 +11,3 @@ export function getDuplicateItems(items) {
|
|
|
11
11
|
}
|
|
12
12
|
return [...duplicates];
|
|
13
13
|
}
|
|
14
|
-
export const getDuplicates = getDuplicateItems;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listUniqueItems<T>(items: Iterable<T>): T[];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { assert } from '@williamthorsen/toolbelt.guards';
|
|
2
2
|
import { generateRandom } from '@williamthorsen/toolbelt.numbers/candidate';
|
|
3
|
+
import { findWeightedIndex } from "./findWeightedIndex.js";
|
|
3
4
|
import { getAtIndexOrThrow } from "./getAtIndexOrThrow.js";
|
|
4
|
-
import { getWeightedIndex } from "./getWeightedIndex.js";
|
|
5
5
|
export function pickWeightedIndex(cumulativeWeights, options = {}) {
|
|
6
6
|
assertValidCumulativeWeights(cumulativeWeights);
|
|
7
7
|
const cumulativeWeight = getAtIndexOrThrow(cumulativeWeights, cumulativeWeights.length - 1);
|
|
8
8
|
const randomValue = generateRandom(options);
|
|
9
9
|
const targetWeight = randomValue * cumulativeWeight;
|
|
10
|
-
const pickedIndex =
|
|
10
|
+
const pickedIndex = findWeightedIndex(cumulativeWeights, targetWeight);
|
|
11
11
|
assert(pickedIndex !== undefined);
|
|
12
12
|
return pickedIndex;
|
|
13
13
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pickInteger, SeededRng } from '@williamthorsen/toolbelt.numbers/candidate';
|
|
2
2
|
import { getAtIndexOrThrow } from "./getAtIndexOrThrow.js";
|
|
3
3
|
export function shuffle(items, options = {}) {
|
|
4
|
-
const
|
|
5
|
-
shuffleInPlace(
|
|
6
|
-
return
|
|
4
|
+
const shuffled = [...items];
|
|
5
|
+
shuffleInPlace(shuffled, options);
|
|
6
|
+
return shuffled;
|
|
7
7
|
}
|
|
8
8
|
export function shuffleInPlace(items, options = {}) {
|
|
9
9
|
const seed = SeededRng.spawn(options.seed);
|
|
10
10
|
for (let i = items.length - 1; i > 0; i--) {
|
|
11
|
-
const j =
|
|
12
|
-
|
|
11
|
+
const j = pickInteger({ max: i, seed });
|
|
12
|
+
const swapped = getAtIndexOrThrow(items, i);
|
|
13
|
+
items[i] = getAtIndexOrThrow(items, j);
|
|
14
|
+
items[j] = swapped;
|
|
13
15
|
}
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@williamthorsen/toolbelt.arrays",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "API",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/williamthorsen/toolbelt/tree/main/packages/arrays#readme",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"CHANGELOG.md"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@williamthorsen/toolbelt.guards": "3.1.
|
|
38
|
-
"@williamthorsen/toolbelt.numbers": "
|
|
37
|
+
"@williamthorsen/toolbelt.guards": "3.1.9",
|
|
38
|
+
"@williamthorsen/toolbelt.numbers": "6.0.0"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=24.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getSetItems<T>(iterable: Iterable<T>): T[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getUniqueItems<T>(items: Iterable<T>): T[];
|