bias-random 1.0.3 → 1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # bias-random
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2d99f0: Added package.json and explicit CDN import options. Explicitly stated the package has no side effects. Improved
8
+ documentation and fixed the yarn install command in README.
9
+
3
10
  ## 1.0.3
4
11
 
5
12
  ### Patch Changes
package/README.md CHANGED
@@ -7,19 +7,17 @@
7
7
  Generates biased random numbers with a customizable bias level, direction, and range
8
8
 
9
9
  ## 📦 Installation
10
-
11
10
  ```bash
12
11
  npm i bias-random
13
12
 
14
13
  # or
15
- yarn add install bias-random
14
+ yarn add bias-random
16
15
 
17
16
  # or
18
17
  pnpm i bias-random
19
18
  ```
20
19
 
21
20
  ## 🚀 Usage
22
-
23
21
  ```ts
24
22
  import biasedRandom from "bias-random";
25
23
 
@@ -33,3 +31,38 @@ const defaultResult = biasedRandom();
33
31
  // Cutomize the parmeters (all parameters are optional, defaulting to the values above)
34
32
  const customResult = biasedRandom({ upperBias: true, biasLevel: 4, min: 10, max: 1000 });
35
33
  ```
34
+
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
+ ## 📃 Changelog
59
+
60
+ To view the release notes for each version, view the changelog:
61
+
62
+ * On GitHub: [Link](https://github.com/reid-moffat/bias-random/blob/main/CHANGELOG.md)
63
+ * On npm: [package page](https://www.npmjs.com/package/bias-random?activeTab=code) -> CHANGELOG.md
64
+ * In the repository: CHANGELOG.md
65
+
66
+ ---
67
+
68
+ ☕ [Buy me a coffee](https://buymeacoffee.com/reidmoffat) if this package helped you!
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var m=(a,e)=>{for(var r in e)n(a,r,{get:e[r],enumerable:!0})},l=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of i(e))!s.call(a,o)&&o!==r&&n(a,o,{get:()=>e[o],enumerable:!(t=u(e,o))||t.enumerable});return a};var b=a=>l(n({},"__esModule",{value:!0}),a);var d={};m(d,{default:()=>f});module.exports=b(d);var p=({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' muist 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)},f=p;
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;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,18 @@
1
- interface BiasedRandomOptions {
1
+ /**
2
+ * Options object to customize the biased random generated result.
3
+ *
4
+ * The whole object as well as every field is optional.
5
+ */
6
+ type BiasedRandomOptions = {
7
+ /** Bias towards the higher number if true, otherwise lower */
2
8
  upperBias?: boolean;
9
+ /** Bias factor, must be 1 or greater, default is 2 (1 is no bias) */
3
10
  biasLevel?: number;
11
+ /** Minimum value, default is 0 */
4
12
  min?: number;
13
+ /** Maximum value, default is 1 */
5
14
  max?: number;
6
- }
15
+ };
7
16
  /**
8
17
  * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound.
9
18
  *
@@ -19,6 +28,6 @@ interface BiasedRandomOptions {
19
28
  * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number.
20
29
  * @throws {TypeError} If `upperBias` is not a boolean.
21
30
  */
22
- declare const biasedRandom: ({ upperBias, biasLevel, min, max }?: BiasedRandomOptions) => number;
31
+ declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
23
32
 
24
33
  export { biasedRandom as default };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,18 @@
1
- interface BiasedRandomOptions {
1
+ /**
2
+ * Options object to customize the biased random generated result.
3
+ *
4
+ * The whole object as well as every field is optional.
5
+ */
6
+ type BiasedRandomOptions = {
7
+ /** Bias towards the higher number if true, otherwise lower */
2
8
  upperBias?: boolean;
9
+ /** Bias factor, must be 1 or greater, default is 2 (1 is no bias) */
3
10
  biasLevel?: number;
11
+ /** Minimum value, default is 0 */
4
12
  min?: number;
13
+ /** Maximum value, default is 1 */
5
14
  max?: number;
6
- }
15
+ };
7
16
  /**
8
17
  * Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound.
9
18
  *
@@ -19,6 +28,6 @@ interface BiasedRandomOptions {
19
28
  * @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number.
20
29
  * @throws {TypeError} If `upperBias` is not a boolean.
21
30
  */
22
- declare const biasedRandom: ({ upperBias, biasLevel, min, max }?: BiasedRandomOptions) => number;
31
+ declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
23
32
 
24
33
  export { 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' muist 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 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bias-random",
3
- "version": "1.0.3",
3
+ "version": "1.1.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,6 +28,8 @@
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",
31
33
  "exports": {
32
34
  ".": {
33
35
  "types": "./dist/index.d.ts",
@@ -39,7 +41,8 @@
39
41
  "types": "./dist/index.d.cts",
40
42
  "default": "./dist/index.cjs"
41
43
  }
42
- }
44
+ },
45
+ "./package.json": "./package.json"
43
46
  },
44
47
  "scripts": {
45
48
  "lint": "tsc",
@@ -56,25 +59,40 @@
56
59
  "README.md",
57
60
  "package.json"
58
61
  ],
59
- "repository": {
60
- "type": "git",
61
- "url": "https://github.com/reid-moffat/bias-random"
62
- },
63
- "bugs": "https://github.com/reid-moffat/bias-random/issues",
64
62
  "devDependencies": {
65
- "@changesets/cli": "^2.27.8",
66
- "@types/chai": "^4.3.19",
67
- "@types/mocha": "^10.0.8",
68
- "@types/node": "^22.6.1",
69
- "chai": "^5.1.1",
70
- "cross-env": "^7.0.3",
63
+ "@changesets/cli": "^2.29.7",
64
+ "@types/chai": "^5.2.3",
65
+ "@types/mocha": "^10.0.10",
66
+ "@types/node": "^24.9.1",
67
+ "chai": "^6.2.0",
68
+ "cross-env": "^10.1.0",
71
69
  "generate-arrays": "^2.0.0",
72
- "mocha": "^10.7.3",
73
- "suite-metrics": "^1.3.1",
70
+ "mocha": "^11.7.4",
71
+ "suite-metrics": "^2.4.0",
74
72
  "test-inputs": "^1.3.0",
75
73
  "ts-node": "^10.9.2",
76
74
  "tsup": "^8.5.0",
77
- "typescript": "^5.6.2"
75
+ "typescript": "^5.9.3"
76
+ },
77
+ "repository": {
78
+ "type": "git",
79
+ "url": "https://github.com/reid-moffat/bias-random"
80
+ },
81
+ "homepage": "https://www.npmjs.com/package/bias-random?activeTab=readme",
82
+ "funding": {
83
+ "type": "buymeacoffee",
84
+ "url": "https://buymeacoffee.com/reidmoffat"
85
+ },
86
+ "bugs": "https://github.com/reid-moffat/bias-random/issues",
87
+ "engines": {
88
+ "node": ">=18.0.0"
89
+ },
90
+ "sideEffects": false,
91
+ "pnpm": {
92
+ "onlyBuiltDependencies": [
93
+ "esbuild",
94
+ "microtime"
95
+ ]
78
96
  },
79
97
  "packageManager": "pnpm@10.18.3"
80
98
  }