@williamthorsen/toolbelt.arrays 3.4.0 → 4.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,29 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 4.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
+ ## 4.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
+ - Align stray modules with layout and TypeScript conventions (#118)
25
+
26
+ 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.
27
+
5
28
  ## 3.4.0 — 2026-08-08
6
29
 
7
30
  ### Features
package/README.md CHANGED
@@ -2,15 +2,7 @@
2
2
 
3
3
  Array utilities.
4
4
 
5
- <!-- section:release-notes -->
6
- ## Release notes — v3.4.0 (2026-08-08)
7
-
8
- ### Features
9
-
10
- - Use underscore separator at 4 digits or more
11
-
12
- 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.
13
- <!-- /section:release-notes -->
5
+ <!-- section:release-notes --><!-- /section:release-notes -->
14
6
 
15
7
  ## Installation
16
8
 
@@ -0,0 +1,3 @@
1
+ export declare function findWeightedIndex(cumulativeWeights: ReadonlyArray<number>, targetWeight: number): Integer | undefined;
2
+ type Integer = number;
3
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { getAtIndexOrThrow } from "./getAtIndexOrThrow.js";
2
- export function getWeightedIndex(cumulativeWeights, targetWeight) {
2
+ export function findWeightedIndex(cumulativeWeights, targetWeight) {
3
3
  if (cumulativeWeights.length === 0) {
4
4
  return undefined;
5
5
  }
@@ -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 getDuplicateItems(items) {
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[];
@@ -0,0 +1,3 @@
1
+ export function listUniqueItems(items) {
2
+ return [...new Set(items)];
3
+ }
@@ -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 = getWeightedIndex(cumulativeWeights, targetWeight);
10
+ const pickedIndex = findWeightedIndex(cumulativeWeights, targetWeight);
11
11
  assert(pickedIndex !== undefined);
12
12
  return pickedIndex;
13
13
  }
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.arrays",
3
- "version": "3.4.0",
4
- "description": "API",
5
- "keywords": [],
3
+ "version": "4.0.1",
4
+ "description": "Array utilities",
5
+ "keywords": [
6
+ "array",
7
+ "deduplicate",
8
+ "esm",
9
+ "shuffle",
10
+ "toolbelt",
11
+ "typescript",
12
+ "utilities",
13
+ "weighted-random"
14
+ ],
6
15
  "homepage": "https://github.com/williamthorsen/toolbelt/tree/main/packages/arrays#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
  ".": {
@@ -34,8 +44,8 @@
34
44
  "CHANGELOG.md"
35
45
  ],
36
46
  "dependencies": {
37
- "@williamthorsen/toolbelt.guards": "3.1.9",
38
- "@williamthorsen/toolbelt.numbers": "5.0.0"
47
+ "@williamthorsen/toolbelt.guards": "3.1.10",
48
+ "@williamthorsen/toolbelt.numbers": "6.0.1"
39
49
  },
40
50
  "engines": {
41
51
  "node": ">=24.0.0"
@@ -1 +0,0 @@
1
- export declare function getSetItems<T>(iterable: Iterable<T>): T[];
@@ -1,3 +0,0 @@
1
- export function getSetItems(iterable) {
2
- return [...new Set(iterable)];
3
- }
@@ -1,2 +0,0 @@
1
- export declare function getDuplicateItems<T>(items: Iterable<T>): T[];
2
- export declare const getDuplicates: typeof getDuplicateItems;
@@ -1 +0,0 @@
1
- export declare function getUniqueItems<T>(items: Iterable<T>): T[];
@@ -1,3 +0,0 @@
1
- export function getUniqueItems(items) {
2
- return [...new Set(items)];
3
- }
@@ -1,3 +0,0 @@
1
- export declare function getWeightedIndex(cumulativeWeights: ReadonlyArray<number>, targetWeight: number): Integer | undefined;
2
- type Integer = number;
3
- export {};