bias-random 1.1.0 → 1.2.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
@@ -1,5 +1,11 @@
1
1
  # bias-random
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5972a1d: Added an export for the BiasedRandomOptions type. Improved documentation and added stricter type and value checking for inputs.
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Reid Moffat
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Reid Moffat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/v/bias-random)](https://www.npmjs.com/package/bias-random)
4
4
  [![npm](https://img.shields.io/npm/dt/bias-random)](https://www.npmjs.com/package/bias-random)
5
5
  [![npm](https://img.shields.io/npm/l/bias-random)](https://www.npmjs.com/package/bias-random)
6
+ [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-support-yellow?logo=buy-me-a-coffee)](https://buymeacoffee.com/reidmoffat)
6
7
 
7
8
  Generates biased random numbers with a customizable bias level, direction, and range
8
9
 
@@ -32,29 +33,6 @@ const defaultResult = biasedRandom();
32
33
  const customResult = biasedRandom({ upperBias: true, biasLevel: 4, min: 10, max: 1000 });
33
34
  ```
34
35
 
35
- ## 🌐 CDN Usage
36
-
37
- You can also use bias-random directly in the browser via CDN:
38
- ```html
39
- <!-- Using unpkg -->
40
- <script src="https://unpkg.com/bias-random"></script>
41
-
42
- <!-- Using jsdelivr -->
43
- <script src="https://cdn.jsdelivr.net/npm/bias-random"></script>
44
-
45
- <!-- Specify version (recommended for production) -->
46
- <script src="https://unpkg.com/bias-random@1.1.0"></script>
47
- <script src="https://cdn.jsdelivr.net/npm/bias-random@1.1.0"></script>
48
- ```
49
-
50
- When loaded via CDN, the library is available as the global variable `biasRandom`:
51
- ```html
52
- <script>
53
- const result = biasRandom();
54
- console.log(result);
55
- </script>
56
- ```
57
-
58
36
  ## 📃 Changelog
59
37
 
60
38
  To view the release notes for each version, view the changelog:
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var i=(a,e)=>{for(var r in e)n(a,r,{get:e[r],enumerable:!0})},p=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of s(e))!m.call(a,o)&&o!==r&&n(a,o,{get:()=>e[o],enumerable:!(t=u(e,o))||t.enumerable});return a};var b=a=>p(n({},"__esModule",{value:!0}),a);var f={};i(f,{default:()=>d});module.exports=b(f);var l=({upperBias:a=!1,biasLevel:e=2,min:r=0,max:t=1}={})=>{if(typeof e!="number"||e<1)throw new TypeError(`Parameter 'biasLevel' must be a number least 1 (value: ${e}); use upperBias to swap bias direction`);if(typeof r!="number"||typeof t!="number"||r>=t)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${r} Max value: ${t}`);if(typeof a!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${a}' is invalid`);let o=Math.pow(Math.random(),e);return a&&(o=1-o),r+o*(t-r)},d=l;
1
+ "use strict";var n=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},f=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of u(e))!p.call(t,a)&&a!==r&&n(t,a,{get:()=>e[a],enumerable:!(o=m(e,a))||o.enumerable});return t};var d=t=>f(n({},"__esModule",{value:!0}),t);var w={};s(w,{default:()=>y});module.exports=d(w);var b=({upperBias:t=!1,biasLevel:e=2,min:r=0,max:o=1}={})=>{if(typeof e!="number")throw new TypeError(`Parameter 'biasLevel' must be a number, received ${e} (type: ${typeof e})`);if(!Number.isFinite(e))throw new TypeError(`Parameter biasLevel must be a finite number (value: ${e})`);if(e<1)throw new TypeError(`Parameter 'biasLevel' must be >= 1 (value: ${e}); use upperBias to swap bias direction`);if(typeof r!="number"||typeof o!="number")throw new TypeError(`Parameters 'min' and 'max' must be numbers. Received min: ${r} (type: ${typeof r}), max: ${o} (type: ${typeof o})`);if(!Number.isFinite(r)||!Number.isFinite(o))throw new TypeError(`Parameters 'min' and 'max' must be finite numbers. Min value: ${r} Max value: ${o}`);if(r>=o)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${r} Max value: ${o}`);if(typeof t!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${t}' (type: ${typeof t}) is invalid`);let a=Math.pow(Math.random(),e);return t&&(a=1-a),r+a*(o-r)},i=b;var y=i;
package/dist/index.d.cts CHANGED
@@ -1,33 +1,34 @@
1
1
  /**
2
- * Options object to customize the biased random generated result.
2
+ * Options object to customize the biased random generated result
3
3
  *
4
- * The whole object as well as every field is optional.
4
+ * Every field, as well as providing this object itself, is optional
5
5
  */
6
6
  type BiasedRandomOptions = {
7
- /** Bias towards the higher number if true, otherwise lower */
7
+ /** Bias towards the maximum number if true, otherwise biased towards the minimum number (default false) */
8
8
  upperBias?: boolean;
9
- /** Bias factor, must be 1 or greater, default is 2 (1 is no bias) */
9
+ /** Bias factor (power to raise the random result by). Must be 1 (no bias) or greater, default is 2 */
10
10
  biasLevel?: number;
11
- /** Minimum value, default is 0 */
11
+ /** Minimum value (default 0) */
12
12
  min?: number;
13
- /** Maximum value, default is 1 */
13
+ /** Maximum value (default 1) */
14
14
  max?: number;
15
15
  };
16
+
16
17
  /**
17
- * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound.
18
+ * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
18
19
  *
19
- * @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation.
20
- * @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`). Default is `false`.
21
- * @param {number} [options.biasLevel=2] - Determines the strength of the bias. Must be 1 or greater, where `1` means no bias and higher values increase the bias. Default is `2`.
22
- * @param {number} [options.min=0] - The minimum value for the random number range. Default is `0`.
23
- * @param {number} [options.max=1] - The maximum value for the random number range. Default is `1`.
20
+ * @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
21
+ * @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
22
+ * @param {number} [options.biasLevel=2] - Determines the strength of the bias (power to raise the random result by). Must be 1 or greater, where `1` means no bias and higher values increase the bias
23
+ * @param {number} [options.min=0] - The minimum value for the random number range
24
+ * @param {number} [options.max=1] - The maximum value for the random number range
24
25
  *
25
- * @returns {number} A random number between `min` and `max`, optionally biased based on the provided options.
26
+ * @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
26
27
  *
27
- * @throws {TypeError} If `biasLevel` is not a number or is less than 1.
28
- * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number.
29
- * @throws {TypeError} If `upperBias` is not a boolean.
28
+ * @throws {TypeError} If `biasLevel` is not a number or is less than 1
29
+ * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
30
+ * @throws {TypeError} If `upperBias` is not a boolean
30
31
  */
31
32
  declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
32
33
 
33
- export { biasedRandom as default };
34
+ export { type BiasedRandomOptions, biasedRandom as default };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,34 @@
1
1
  /**
2
- * Options object to customize the biased random generated result.
2
+ * Options object to customize the biased random generated result
3
3
  *
4
- * The whole object as well as every field is optional.
4
+ * Every field, as well as providing this object itself, is optional
5
5
  */
6
6
  type BiasedRandomOptions = {
7
- /** Bias towards the higher number if true, otherwise lower */
7
+ /** Bias towards the maximum number if true, otherwise biased towards the minimum number (default false) */
8
8
  upperBias?: boolean;
9
- /** Bias factor, must be 1 or greater, default is 2 (1 is no bias) */
9
+ /** Bias factor (power to raise the random result by). Must be 1 (no bias) or greater, default is 2 */
10
10
  biasLevel?: number;
11
- /** Minimum value, default is 0 */
11
+ /** Minimum value (default 0) */
12
12
  min?: number;
13
- /** Maximum value, default is 1 */
13
+ /** Maximum value (default 1) */
14
14
  max?: number;
15
15
  };
16
+
16
17
  /**
17
- * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound.
18
+ * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
18
19
  *
19
- * @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation.
20
- * @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`). Default is `false`.
21
- * @param {number} [options.biasLevel=2] - Determines the strength of the bias. Must be 1 or greater, where `1` means no bias and higher values increase the bias. Default is `2`.
22
- * @param {number} [options.min=0] - The minimum value for the random number range. Default is `0`.
23
- * @param {number} [options.max=1] - The maximum value for the random number range. Default is `1`.
20
+ * @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
21
+ * @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
22
+ * @param {number} [options.biasLevel=2] - Determines the strength of the bias (power to raise the random result by). Must be 1 or greater, where `1` means no bias and higher values increase the bias
23
+ * @param {number} [options.min=0] - The minimum value for the random number range
24
+ * @param {number} [options.max=1] - The maximum value for the random number range
24
25
  *
25
- * @returns {number} A random number between `min` and `max`, optionally biased based on the provided options.
26
+ * @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
26
27
  *
27
- * @throws {TypeError} If `biasLevel` is not a number or is less than 1.
28
- * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number.
29
- * @throws {TypeError} If `upperBias` is not a boolean.
28
+ * @throws {TypeError} If `biasLevel` is not a number or is less than 1
29
+ * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
30
+ * @throws {TypeError} If `upperBias` is not a boolean
30
31
  */
31
32
  declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
32
33
 
33
- export { biasedRandom as default };
34
+ export { type BiasedRandomOptions, biasedRandom as default };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var n=({upperBias:o=!1,biasLevel:a=2,min:e=0,max:r=1}={})=>{if(typeof a!="number"||a<1)throw new TypeError(`Parameter 'biasLevel' must be a number least 1 (value: ${a}); use upperBias to swap bias direction`);if(typeof e!="number"||typeof r!="number"||e>=r)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${e} Max value: ${r}`);if(typeof o!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${o}' is invalid`);let t=Math.pow(Math.random(),a);return o&&(t=1-t),e+t*(r-e)},u=n;export{u as default};
1
+ var i=({upperBias:o=!1,biasLevel:r=2,min:e=0,max:t=1}={})=>{if(typeof r!="number")throw new TypeError(`Parameter 'biasLevel' must be a number, received ${r} (type: ${typeof r})`);if(!Number.isFinite(r))throw new TypeError(`Parameter biasLevel must be a finite number (value: ${r})`);if(r<1)throw new TypeError(`Parameter 'biasLevel' must be >= 1 (value: ${r}); use upperBias to swap bias direction`);if(typeof e!="number"||typeof t!="number")throw new TypeError(`Parameters 'min' and 'max' must be numbers. Received min: ${e} (type: ${typeof e}), max: ${t} (type: ${typeof t})`);if(!Number.isFinite(e)||!Number.isFinite(t))throw new TypeError(`Parameters 'min' and 'max' must be finite numbers. Min value: ${e} Max value: ${t}`);if(e>=t)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${e} Max value: ${t}`);if(typeof o!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${o}' (type: ${typeof o}) is invalid`);let a=Math.pow(Math.random(),r);return o&&(a=1-a),e+a*(t-e)},n=i;var p=n;export{p as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bias-random",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Generates biased random numbers with a customizable bias level, direction, and range",
5
5
  "author": "Reid Moffat <reid.moffat9@gmail.com>",
6
6
  "license": "MIT",
@@ -28,8 +28,6 @@
28
28
  "main": "dist/index.cjs",
29
29
  "module": "dist/index.js",
30
30
  "types": "dist/index.d.ts",
31
- "unpkg": "dist/index.js",
32
- "jsdelivr": "dist/index.js",
33
31
  "exports": {
34
32
  ".": {
35
33
  "types": "./dist/index.d.ts",
@@ -60,18 +58,20 @@
60
58
  "package.json"
61
59
  ],
62
60
  "devDependencies": {
63
- "@changesets/cli": "^2.29.7",
61
+ "@changesets/cli": "^2.29.8",
64
62
  "@types/chai": "^5.2.3",
65
63
  "@types/mocha": "^10.0.10",
66
- "@types/node": "^24.9.1",
67
- "chai": "^6.2.0",
64
+ "@types/node": "^25.0.9",
65
+ "@types/stringify-object": "^4.0.5",
66
+ "chai": "^6.2.2",
68
67
  "cross-env": "^10.1.0",
69
68
  "generate-arrays": "^2.0.0",
70
- "mocha": "^11.7.4",
71
- "suite-metrics": "^2.4.0",
72
- "test-inputs": "^1.3.0",
69
+ "mocha": "^11.7.5",
70
+ "stringify-object": "^6.0.0",
71
+ "suite-metrics": "^2.5.0",
72
+ "test-inputs": "^1.4.0",
73
73
  "ts-node": "^10.9.2",
74
- "tsup": "^8.5.0",
74
+ "tsup": "^8.5.1",
75
75
  "typescript": "^5.9.3"
76
76
  },
77
77
  "repository": {