toosoon-utils 1.5.0 → 2.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.
Files changed (49) hide show
  1. package/package.json +6 -3
  2. package/tsconfig.json +1 -3
  3. package/lib/classes/_pool.d.ts +0 -56
  4. package/lib/classes/_pool.js +0 -92
  5. package/lib/classes/color-scale.d.ts +0 -52
  6. package/lib/classes/color-scale.js +0 -160
  7. package/lib/classes/frame-rate.d.ts +0 -25
  8. package/lib/classes/frame-rate.js +0 -48
  9. package/lib/colors.d.ts +0 -155
  10. package/lib/colors.js +0 -367
  11. package/lib/constants.d.ts +0 -162
  12. package/lib/constants.js +0 -170
  13. package/lib/dom.d.ts +0 -25
  14. package/lib/dom.js +0 -47
  15. package/lib/files.d.ts +0 -14
  16. package/lib/files.js +0 -38
  17. package/lib/functions.d.ts +0 -22
  18. package/lib/functions.js +0 -53
  19. package/lib/geometry.d.ts +0 -89
  20. package/lib/geometry.js +0 -128
  21. package/lib/index.d.ts +0 -10
  22. package/lib/index.js +0 -39
  23. package/lib/maths.d.ts +0 -161
  24. package/lib/maths.js +0 -219
  25. package/lib/now.d.ts +0 -5
  26. package/lib/now.js +0 -28
  27. package/lib/prng.d.ts +0 -124
  28. package/lib/prng.js +0 -234
  29. package/lib/random.d.ts +0 -91
  30. package/lib/random.js +0 -162
  31. package/lib/strings.d.ts +0 -14
  32. package/lib/strings.js +0 -18
  33. package/lib/tsconfig.tsbuildinfo +0 -1
  34. package/lib/types.d.ts +0 -18
  35. package/lib/types.js +0 -1
  36. package/src/classes/_pool.ts +0 -92
  37. package/src/classes/color-scale.ts +0 -181
  38. package/src/classes/frame-rate.ts +0 -49
  39. package/src/colors.ts +0 -389
  40. package/src/constants.ts +0 -172
  41. package/src/dom.ts +0 -50
  42. package/src/files.ts +0 -42
  43. package/src/functions.ts +0 -56
  44. package/src/geometry.ts +0 -160
  45. package/src/maths.ts +0 -241
  46. package/src/prng.ts +0 -249
  47. package/src/random.ts +0 -162
  48. package/src/strings.ts +0 -19
  49. package/src/types.ts +0 -33
package/src/random.ts DELETED
@@ -1,162 +0,0 @@
1
- import { radToSphere } from './geometry';
2
- import { Vector2, Vector3 } from './types';
3
-
4
- /**
5
- * Generate a random boolean (true or false)
6
- *
7
- * @param {number} [probability=0.5] Probability to get true
8
- * @returns {boolean} Either `true` or `false`
9
- */
10
- export function randomBoolean(probability: number = 0.5): boolean {
11
- return Math.random() < probability;
12
- }
13
-
14
- /**
15
- * Generate a random sign (1 or -1)
16
- *
17
- * @param {number} [probability=0.5] Probability to get 1
18
- * @returns {number} Either 1 or -1
19
- */
20
- export function randomSign(probability: number = 0.5): number {
21
- return randomBoolean(probability) ? 1 : -1;
22
- }
23
-
24
- /**
25
- * Generate a random floating-point number within a specified range
26
- *
27
- * @param {number} [min=0] Minimum boundary
28
- * @param {number} [max=1] Maximum boundary
29
- * @param {number} [precision=2] Number of digits after the decimal point
30
- * @returns {number} Generated float
31
- */
32
- export function randomFloat(min: number = 0, max: number = 1, precision: number = 2): number {
33
- return parseFloat(Math.min(min + Math.random() * (max - min), max).toFixed(precision));
34
- }
35
-
36
- /**
37
- * Generate a random integer number within a specified range
38
- *
39
- * @param {number} min Minimum boundary
40
- * @param {number} max Maximum boundary
41
- * @returns {number} Generated integer
42
- */
43
- export function randomInt(min: number, max: number): number {
44
- return Math.floor(Math.random() * (max - min + 1) + min);
45
- }
46
-
47
- /**
48
- * Generate a random hexadecimal color
49
- *
50
- * @returns {string} Generated hexadecimal color
51
- */
52
- export function randomHexColor(): string {
53
- return '#' + ('00000' + ((Math.random() * (1 << 24)) | 0).toString(16)).slice(-6);
54
- }
55
-
56
- /**
57
- * Pick a random item from a given array
58
- *
59
- * @param {T[]} array Array to pick the item from
60
- * @returns {T|undefined} Random item picked
61
- */
62
- export function randomItem<T = unknown>(array: T[]): T | undefined {
63
- if (array.length === 0) return undefined;
64
- return array[randomInt(0, array.length - 1)];
65
- }
66
-
67
- /**
68
- * Pick a random property value from a given object
69
- *
70
- * @param {object} object Object to pick the property from
71
- * @returns {T|undefined} Random item picked
72
- */
73
- export function randomObjectProperty<T = unknown>(object: Record<string, T>): T | undefined {
74
- const keys = Object.keys(object);
75
- const key = randomItem(keys);
76
- if (key && object.hasOwnProperty(key)) {
77
- return object[key as keyof object];
78
- }
79
- }
80
-
81
- /**
82
- * Select a random index from an array of weighted items
83
- *
84
- * @param {number[]} weights Array of weights
85
- * @returns {number} Random index based on weights
86
- */
87
- export function randomIndex(weights: number[]): number {
88
- if (weights.length === 0) return -1;
89
-
90
- let totalWeight = 0;
91
- for (let weight of weights) {
92
- totalWeight += weight;
93
- }
94
-
95
- if (totalWeight <= 0) {
96
- console.warn('randomIndex()', 'Weights must sum to > 0', totalWeight);
97
- }
98
-
99
- let weight = Math.random() * totalWeight;
100
- for (let i = 0; i < weights.length; i++) {
101
- if (weight < weights[i]) return i;
102
- weight -= weights[i];
103
- }
104
-
105
- return 0;
106
- }
107
-
108
- // *********************
109
- // Geometry
110
- // *********************
111
- /**
112
- * Produce a random 2D point around the perimiter of a unit circle
113
- *
114
- * @param {number} [radius=1] Radius of the circle
115
- * @param {Vector2} [target] Target vector
116
- * @returns {Vector2} Random 2D point on circle
117
- */
118
- export function onCircle(radius: number = 1, target: Vector2 = { x: 0, y: 0 }): Vector2 {
119
- const angle = Math.random() * 2.0 * Math.PI;
120
- target.x = radius * Math.cos(angle);
121
- target.y = radius * Math.sin(angle);
122
- return target;
123
- }
124
-
125
- /**
126
- * Produce a random 2D point inside a unit circle
127
- *
128
- * @param {number} [radius=1] Radius of the circle
129
- * @param {Vector2} [target] Target vector
130
- * @returns {Vector2} Random 2D point inside circle
131
- */
132
- export function insideCircle(radius: number = 1, target: Vector2 = { x: 0, y: 0 }): Vector2 {
133
- radius *= Math.random();
134
- return onCircle(radius, target);
135
- }
136
-
137
- /**
138
- * Produce a random 3D point on the surface of a unit sphere
139
- *
140
- * @param {number} [radius=1] Radius of the sphere
141
- * @param {Vector3} [target] Target vector
142
- * @returns {Vector3} Random 3D point on sphere
143
- */
144
- export function onSphere(radius: number = 1, target: Vector3 = { x: 0, y: 0, z: 0 }): Vector3 {
145
- const u = Math.random() * Math.PI * 2;
146
- const v = Math.random() * 2 - 1;
147
- const phi = u;
148
- const theta = Math.acos(v);
149
- return radToSphere(radius, phi, theta, target);
150
- }
151
-
152
- /**
153
- * Produce a random 3D point inside a unit sphere
154
- *
155
- * @param {number} [radius=1] Radius of the sphere
156
- * @param {Vector3} [target] Target vector
157
- * @returns {Vector3} Random 3D point inside sphere
158
- */
159
- export function insideSphere(radius: number = 1, target: Vector3 = { x: 0, y: 0, z: 0 }): Vector3 {
160
- radius *= Math.random();
161
- return onSphere(radius, target);
162
- }
package/src/strings.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Capitalize a string
3
- *
4
- * @param {string} string String to capitalize
5
- * @returns {string} Capitalized string
6
- */
7
- export function capitalize(string: string): string {
8
- return string.charAt(0).toUpperCase() + string.slice(1);
9
- }
10
-
11
- /**
12
- * Clean a path by removing params
13
- *
14
- * @param {string} path Path to clean
15
- * @returns {string} Cleaned path
16
- */
17
- export function cleanPath(path: string): string {
18
- return path.split('#')[0].split('?')[0];
19
- }
package/src/types.ts DELETED
@@ -1,33 +0,0 @@
1
- import { W3CX11 } from './constants';
2
-
3
- // *********************
4
- // Colors
5
- // *********************
6
- export type ColorName = keyof typeof W3CX11;
7
-
8
- export type ColorRepresentation = ColorName | string | number | [number, number, number];
9
-
10
- // *********************
11
- // Functions
12
- // *********************
13
- export interface Deferred<T> {
14
- promise: Promise<T>;
15
- resolve: (value: T | PromiseLike<T>) => void;
16
- reject: (reason?: unknown) => void;
17
- }
18
-
19
- // *********************
20
- // Geometry
21
- // *********************
22
- export interface Vector2 {
23
- x: number;
24
- y: number;
25
- }
26
-
27
- export interface Vector3 extends Vector2 {
28
- z: number;
29
- }
30
-
31
- export interface Vector4 extends Vector3 {
32
- w: number;
33
- }