@williamthorsen/toolbelt.arrays 3.4.0 → 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 +14 -0
- package/README.md +3 -3
- 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/package.json +2 -2
- 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,20 @@
|
|
|
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
|
+
|
|
5
19
|
## 3.4.0 — 2026-08-08
|
|
6
20
|
|
|
7
21
|
### Features
|
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Array utilities.
|
|
4
4
|
|
|
5
5
|
<!-- section:release-notes -->
|
|
6
|
-
## Release notes —
|
|
6
|
+
## Release notes — v4.0.0 (2026-08-12)
|
|
7
7
|
|
|
8
8
|
### Features
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Renames thirteen functions across various packages to align with a consistent naming pattern.
|
|
13
13
|
<!-- /section:release-notes -->
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
@@ -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
|
}
|
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",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@williamthorsen/toolbelt.guards": "3.1.9",
|
|
38
|
-
"@williamthorsen/toolbelt.numbers": "
|
|
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[];
|