@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 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 — v3.4.0 (2026-08-08)
6
+ ## Release notes — v4.0.0 (2026-08-12)
7
7
 
8
8
  ### Features
9
9
 
10
- - Use underscore separator at 4 digits or more
10
+ - 🚨 **Breaking:** Rename get* functions by return kind and verb specificity (#119)
11
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.
12
+ Renames thirteen functions across various packages to align with a consistent naming pattern.
13
13
  <!-- /section:release-notes -->
14
14
 
15
15
  ## Installation
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.arrays",
3
- "version": "3.4.0",
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": "5.0.0"
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,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 {};