toosoon-utils 1.4.0 → 1.5.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.
Files changed (3) hide show
  1. package/README.md +27 -23
  2. package/package.json +3 -2
  3. package/src/prng.ts +15 -16
package/README.md CHANGED
@@ -687,104 +687,108 @@ xoshiro128ss(a: number, b: number, c: number, d: number): number;
687
687
 
688
688
  #### PRNG functions
689
689
 
690
- Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) are available with a `seed` string and a PRNG `algorithm` function additionnal parameters.
690
+ Thanks to the above algorithms, a seed-based version of most of the [random functions](#random) are exist with additionnal parameters for a `seed` string and a PRNG `algorithm` function.
691
691
 
692
- ##### random(seed)
692
+ PRNG parameters:
693
693
 
694
- Generate a pseudo-random number in the interval [0, 1]. It's the PRNG equivalent of `Math.random()`.
694
+ ```ts
695
+ type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) => number };
696
+ ```
697
+
698
+ ##### random(prng)
699
+
700
+ Generate a pseudo-random number in the interval [0, 1]. It is the PRNG equivalent of `Math.random()`.
695
701
 
696
- - `prng`: Can be a seed string or a PRNG parameters object containing the seed and a PRNG algorithm function.
697
- - `[prng.seed]`: Seed used for pseudo-random number generation.
698
- - `[prng.algorithm=splitmix32]`: PRNG algorithm function generating a pseudo-random number.
702
+ - `prng`: PRNG parameters.
699
703
 
700
704
  ```ts
701
- random(prng: string | object): number;
705
+ random(prng: PRNGParameters): number;
702
706
  ```
703
707
 
704
708
  ##### randomBoolean(prng)
705
709
 
706
710
  Generate a pseudo-random boolean (true or false).
707
711
 
708
- - `prng`
712
+ - `prng`: PRNG parameters.
709
713
  - `[probability=0.5]`: Probability to get true.
710
714
 
711
715
  ```ts
712
- randomBoolean(prng: string | object, probability?: number): boolean;
716
+ randomBoolean(prng: PRNGParameters, probability?: number): boolean;
713
717
  ```
714
718
 
715
719
  ##### randomSign(prng)
716
720
 
717
721
  Generate a pseudo-random sign (1 or -1).
718
722
 
719
- - `prng`
723
+ - `prng`: PRNG parameters.
720
724
  - `[probability=0.5]`: Probability to get 1.
721
725
 
722
726
  ```ts
723
- randomSign(prng: string | object, probability?: number): number;
727
+ randomSign(prng: PRNGParameters, probability?: number): number;
724
728
  ```
725
729
 
726
730
  ##### randomFloat(prng, min, max)
727
731
 
728
732
  Generate a pseudo-random floating-point number within a specified range.
729
733
 
730
- - `prng`
734
+ - `prng`: PRNG parameters.
731
735
  - `[min=0]`: Minimum boundary.
732
736
  - `[max=1]`: Maximum boundary.
733
737
  - `[precision=2]`: Number of digits after the decimal point.
734
738
 
735
739
  ```ts
736
- randomFloat(prng: string | object, min?: number, max?: number, precision?: number): number;
740
+ randomFloat(prng: PRNGParameters, min?: number, max?: number, precision?: number): number;
737
741
  ```
738
742
 
739
743
  ##### randomInt(prng, min, max)
740
744
 
741
745
  Generate a pseudo-random integer number within a specified range.
742
746
 
743
- - `prng`
747
+ - `prng`: PRNG parameters.
744
748
  - `min`: Minimum boundary.
745
749
  - `max`: Maximum boundary.
746
750
 
747
751
  ```ts
748
- randomInt(prng: string | object, min: number, max: number): number;
752
+ randomInt(prng: PRNGParameters, min: number, max: number): number;
749
753
  ```
750
754
 
751
755
  ##### randomHexColor(prng)
752
756
 
753
757
  Generate a pseudo-random hexadecimal color.
754
758
 
755
- - `prng`
759
+ - `prng`: PRNG parameters.
756
760
 
757
761
  ```ts
758
- randomHexColor(prng: string | object): string;
762
+ randomHexColor(prng: PRNGParameters): string;
759
763
  ```
760
764
 
761
765
  ##### randomItem(prng, array)
762
766
 
763
767
  Pick a pseudo-random item from a given array.
764
768
 
765
- - `prng`
769
+ - `prng`: PRNG parameters.
766
770
  - `array`: Array to pick the item from.
767
771
 
768
772
  ```ts
769
- randomItem<T>(prng: string | object, array: T[]): T | undefined;
773
+ randomItem<T>(prng: PRNGParameters, array: T[]): T | undefined;
770
774
  ```
771
775
 
772
776
  ##### randomObjectProperty(prng)
773
777
 
774
778
  Pick a pseudo-random property value from a given object.
775
779
 
776
- - `prng`
780
+ - `prng`: PRNG parameters.
777
781
  - `object`: Object to pick the property from.
778
782
 
779
783
  ```ts
780
- randomObjectProperty<T>(prng: string | object, object: Record<string, T>): T | undefined;
784
+ randomObjectProperty<T>(prng: PRNGParameters, object: Record<string, T>): T | undefined;
781
785
  ```
782
786
 
783
787
  ##### randomIndex(prng)
784
788
 
785
789
  Select a pseudo-random index from an array of weighted items.
786
790
 
787
- - `prng`
791
+ - `prng`: PRNG parameters.
788
792
  - `weights`: Array of weights.
789
793
 
790
794
  ```ts
@@ -1074,4 +1078,4 @@ FrameRate.update(): boolean;
1074
1078
 
1075
1079
  ## License
1076
1080
 
1077
- MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-utils/tree/master/LICENSE) for details
1081
+ MIT License, see [LICENSE](https://github.com/toosoon-dev/toosoon-utils/tree/master/LICENSE) for details.
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "toosoon-utils",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Utility functions & classes",
5
5
  "main": "",
6
+ "types": "./lib/types.d.ts",
6
7
  "exports": {
7
8
  "./colors": "./lib/colors.js",
8
9
  "./dom": "./lib/dom.js",
@@ -27,7 +28,7 @@
27
28
  "url": "git+https://github.com/toosoon-dev/toosoon-utils.git"
28
29
  },
29
30
  "keywords": [
30
- "tooson",
31
+ "toosoon",
31
32
  "utils",
32
33
  "colors",
33
34
  "dom",
package/src/prng.ts CHANGED
@@ -121,14 +121,13 @@ export function xoshiro128ss(a: number, b: number, c: number, d: number): number
121
121
  // *********************
122
122
  // PRNG Functions
123
123
  // *********************
124
-
125
- type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) => number };
124
+ export type PRNGParameters = string | { seed: string; algorithm: (...args: number[]) => number };
126
125
 
127
126
  /**
128
127
  * Generate a pseudo-random number in the interval [0, 1]
129
128
  * PRNG equivalent of `Math.random()`
130
129
  *
131
- * @param {string|object} prng
130
+ * @param {PRNGParameters} prng PRNG parameters
132
131
  * @returns {number} Pseudo-random number
133
132
  */
134
133
  export function random(prng: PRNGParameters): number {
@@ -142,7 +141,7 @@ export function random(prng: PRNGParameters): number {
142
141
  /**
143
142
  * Generate a pseudo-random boolean (true or false)
144
143
  *
145
- * @param {string|object} prng
144
+ * @param {PRNGParameters} prng PRNG parameters
146
145
  * @param {number} [probability=0.5] Probability to get true
147
146
  * @returns {boolean} Either `true` or `false`
148
147
  */
@@ -153,7 +152,7 @@ export function randomBoolean(prng: PRNGParameters, probability: number = 0.5):
153
152
  /**
154
153
  * Generate a pseudo-random sign (1 or -1)
155
154
  *
156
- * @param {string|object} prng
155
+ * @param {PRNGParameters} prng PRNG parameters
157
156
  * @param {number} [probability=0.5] Probability to get 1
158
157
  * @returns {number} Either 1 or -1
159
158
  */
@@ -164,7 +163,7 @@ export function randomSign(prng: PRNGParameters, probability: number = 0.5): num
164
163
  /**
165
164
  * Generate a pseudo-random floating-point number within a specified range
166
165
  *
167
- * @param {string|object} prng
166
+ * @param {PRNGParameters} prng PRNG parameters
168
167
  * @param {number} [min=0] Minimum boundary
169
168
  * @param {number} [max=1] Maximum boundary
170
169
  * @param {number} [precision=2] Number of digits after the decimal point
@@ -177,9 +176,9 @@ export function randomFloat(prng: PRNGParameters, min: number = 0, max: number =
177
176
  /**
178
177
  * Generate a pseudo-random integer number within a specified range
179
178
  *
180
- * @param {string|object} prng
181
- * @param {number} min Minimum boundary
182
- * @param {number} max Maximum boundary
179
+ * @param {PRNGParameters} prng PRNG parameters
180
+ * @param {number} min Minimum boundary
181
+ * @param {number} max Maximum boundary
183
182
  * @returns {number} Generated integer
184
183
  */
185
184
  export function randomInt(prng: PRNGParameters, min: number, max: number): number {
@@ -189,7 +188,7 @@ export function randomInt(prng: PRNGParameters, min: number, max: number): numbe
189
188
  /**
190
189
  * Generate a pseudo-random hexadecimal color
191
190
  *
192
- * @param {string|object} prng
191
+ * @param {PRNGParameters} prng PRNG parameters
193
192
  * @returns {string} Generated hexadecimal color
194
193
  */
195
194
  export function randomHexColor(prng: PRNGParameters): string {
@@ -199,8 +198,8 @@ export function randomHexColor(prng: PRNGParameters): string {
199
198
  /**
200
199
  * Pick a pseudo-random item from a given array
201
200
  *
202
- * @param {string|object} prng
203
- * @param {T[]} array Array to pick the item from
201
+ * @param {PRNGParameters} prng PRNG parameters
202
+ * @param {T[]} array Array to pick the item from
204
203
  * @returns {T|undefined} Random item picked
205
204
  */
206
205
  export function randomItem<T = unknown>(prng: PRNGParameters, array: T[]): T | undefined {
@@ -211,8 +210,8 @@ export function randomItem<T = unknown>(prng: PRNGParameters, array: T[]): T | u
211
210
  /**
212
211
  * Pick a pseudo-random property value from a given object
213
212
  *
214
- * @param {string|object} prng
215
- * @param {object} object Object to pick the property from
213
+ * @param {PRNGParameters} prng PRNG parameters
214
+ * @param {object} object Object to pick the property from
216
215
  * @returns {T|undefined} Random item picked
217
216
  */
218
217
  export function randomObjectProperty<T = unknown>(prng: PRNGParameters, object: Record<string, T>): T | undefined {
@@ -226,8 +225,8 @@ export function randomObjectProperty<T = unknown>(prng: PRNGParameters, object:
226
225
  /**
227
226
  * Select a pseudo-random index from an array of weighted items
228
227
  *
229
- * @param {string|object} prng
230
- * @param {number[]} weights Array of weights
228
+ * @param {PRNGParameters} prng PRNG parameters
229
+ * @param {number[]} weights Array of weights
231
230
  * @returns {number} Random index based on weights
232
231
  */
233
232
  export function randomIndex(prng: PRNGParameters, weights: number[]): number {