random-weighted-pick 2.0.1 → 2.1.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.
@@ -1,61 +0,0 @@
1
- /* Smoke test for random-weighted-pick (CJS) */
2
- const lib = require('random-weighted-pick')
3
-
4
- // Library should expose default function and named exports
5
- if (typeof lib !== 'function') {
6
- console.error('Default export is not a function')
7
- process.exit(1)
8
- }
9
-
10
- const { weightedPick, pickMany, createWeightedPicker } = lib
11
-
12
- if (typeof weightedPick !== 'function' || typeof pickMany !== 'function' || typeof createWeightedPicker !== 'function') {
13
- console.error('Named exports missing')
14
- process.exit(1)
15
- }
16
-
17
- const options = [
18
- { id: 0, weight: 0.2, item: 'A' },
19
- { id: 1, weight: 0.3, item: 'B' },
20
- { id: 2, weight: 0.5, item: 'C' },
21
- ]
22
-
23
- // Deterministic RNG for repeatability
24
- let i = 0
25
- const values = [0.05, 0.35, 0.85, 0.49, 0.51]
26
- const rng = () => values[i++ % values.length]
27
-
28
- // Single pick via default export
29
- const one = lib(options, { rng })
30
- console.log('one:', one)
31
-
32
- // Single pick via named export
33
- const one2 = weightedPick(options, { rng })
34
- console.log('one2:', one2)
35
-
36
- // Many picks
37
- const many = pickMany(options, 3, { rng })
38
- console.log('many:', many)
39
-
40
- // Picker API
41
- const picker = createWeightedPicker(options, { method: 'alias', rng })
42
- const p1 = picker.pick()
43
- const p2 = picker.pick()
44
- const many2 = picker.pickMany(2)
45
- console.log('picker:', { p1, p2, many2 })
46
-
47
- // Basic assertions
48
- const assertResult = r => {
49
- if (!r || typeof r.id !== 'number' || !['A', 'B', 'C'].includes(r.item)) {
50
- throw new Error('Invalid result shape: ' + JSON.stringify(r))
51
- }
52
- }
53
-
54
- assertResult(one)
55
- assertResult(one2)
56
- many.forEach(assertResult)
57
- many2.forEach(assertResult)
58
-
59
- console.log('Smoke test passed.')
60
-
61
-
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "singleQuote": true,
3
- "semi": false
4
- }
package/CONTRIBUTING.md DELETED
@@ -1,9 +0,0 @@
1
- # Contributing
2
-
3
- ## Development Setup
4
-
5
- 1. Install dependencies: `npm install`
6
- 2. Run tests: `npm test`
7
- 3. Build the library: `npm run build`
8
-
9
- Please make sure tests and build pass before submitting a pull request.
package/jest.config.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- testMatch: ['**/*.test.ts']
5
- }
Binary file
Binary file
package/tsconfig.cjs.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "outDir": "dist/cjs",
6
- "declaration": false
7
- }
8
- }
package/tsconfig.esm.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "outDir": "dist/esm",
7
- "declaration": true
8
- }
9
- }
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "types": ["node"],
11
- "moduleResolution": "node"
12
- },
13
- "include": ["src/**/*"],
14
- "exclude": [
15
- "node_modules",
16
- "dist",
17
- "**/*.test.ts",
18
- "src/utils/tests.utils.ts"
19
- ]
20
- }