toosoon-utils 3.1.0 → 4.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.
- package/README.md +1 -1
- package/lib/classes/_pool.js +4 -7
- package/lib/classes/color-scale.d.ts +1 -1
- package/lib/classes/color-scale.js +37 -40
- package/lib/classes/frame-rate.js +3 -5
- package/lib/colors.d.ts +1 -1
- package/lib/colors.js +35 -57
- package/lib/constants.js +6 -9
- package/lib/dom.js +3 -9
- package/lib/files.js +2 -7
- package/lib/functions.js +14 -18
- package/lib/geometry.d.ts +1 -1
- package/lib/geometry.js +13 -25
- package/lib/maths.js +19 -41
- package/lib/prng.js +16 -35
- package/lib/query.js +3 -9
- package/lib/random.d.ts +1 -1
- package/lib/random.js +15 -31
- package/lib/strings.js +10 -23
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.js +1 -2
- package/package.json +3 -1
- package/tsconfig.json +2 -0
package/lib/prng.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomGaussian = exports.randomIndex = exports.randomObjectProperty = exports.randomItem = exports.randomHexColor = exports.randomInt = exports.randomFloat = exports.randomSign = exports.randomBoolean = exports.random = exports.xoshiro128ss = exports.jsf32 = exports.mulberry32 = exports.splitmix32 = exports.sfc32 = exports.cyrb128 = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Produce a 128-bit hash value from a seed
|
|
6
3
|
*
|
|
7
4
|
* @param {string} seed Initial seed state
|
|
8
5
|
* @returns {[number, number, number, number]} Hash numbers
|
|
9
6
|
*/
|
|
10
|
-
function cyrb128(seed) {
|
|
7
|
+
export function cyrb128(seed) {
|
|
11
8
|
var h1 = 1779033703;
|
|
12
9
|
var h2 = 3144134277;
|
|
13
10
|
var h3 = 1013904242;
|
|
@@ -25,7 +22,6 @@ function cyrb128(seed) {
|
|
|
25
22
|
h4 = Math.imul(h2 ^ (h4 >>> 19), 2716044179);
|
|
26
23
|
return [(h1 ^ h2 ^ h3 ^ h4) >>> 0, (h2 ^ h1) >>> 0, (h3 ^ h1) >>> 0, (h4 ^ h1) >>> 0];
|
|
27
24
|
}
|
|
28
|
-
exports.cyrb128 = cyrb128;
|
|
29
25
|
// *********************
|
|
30
26
|
// PRNG Algorithms
|
|
31
27
|
// *********************
|
|
@@ -38,7 +34,7 @@ exports.cyrb128 = cyrb128;
|
|
|
38
34
|
* @param {number} d
|
|
39
35
|
* @returns {number} Pseudo-random number
|
|
40
36
|
*/
|
|
41
|
-
function sfc32(a, b, c, d) {
|
|
37
|
+
export function sfc32(a, b, c, d) {
|
|
42
38
|
a >>>= 0;
|
|
43
39
|
b >>>= 0;
|
|
44
40
|
c >>>= 0;
|
|
@@ -52,14 +48,13 @@ function sfc32(a, b, c, d) {
|
|
|
52
48
|
c = (c + t) | 0;
|
|
53
49
|
return (t >>> 0) / 4294967296;
|
|
54
50
|
}
|
|
55
|
-
exports.sfc32 = sfc32;
|
|
56
51
|
/**
|
|
57
52
|
* SplitMix32, Generator with a 32-bit state
|
|
58
53
|
*
|
|
59
54
|
* @param {number} a
|
|
60
55
|
* @returns {number} Pseudo-random number
|
|
61
56
|
*/
|
|
62
|
-
function splitmix32(a) {
|
|
57
|
+
export function splitmix32(a) {
|
|
63
58
|
a |= 0;
|
|
64
59
|
a = (a + 0x9e3779b9) | 0;
|
|
65
60
|
var t = a ^ (a >>> 16);
|
|
@@ -68,27 +63,25 @@ function splitmix32(a) {
|
|
|
68
63
|
t = Math.imul(t, 0x735a2d97);
|
|
69
64
|
return ((t = t ^ (t >>> 15)) >>> 0) / 4294967296;
|
|
70
65
|
}
|
|
71
|
-
exports.splitmix32 = splitmix32;
|
|
72
66
|
/**
|
|
73
67
|
* Mulberry32, Generator with a 32-bit state
|
|
74
68
|
*
|
|
75
69
|
* @param {number} a
|
|
76
70
|
* @returns {number} Pseudo-random number
|
|
77
71
|
*/
|
|
78
|
-
function mulberry32(a) {
|
|
72
|
+
export function mulberry32(a) {
|
|
79
73
|
var t = (a += 0x6d2b79f5);
|
|
80
74
|
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
81
75
|
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
82
76
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
83
77
|
}
|
|
84
|
-
exports.mulberry32 = mulberry32;
|
|
85
78
|
/**
|
|
86
79
|
* Jenkins' Small Fast, Generator with a 32-bit state
|
|
87
80
|
*
|
|
88
81
|
* @param {number} a
|
|
89
82
|
* @returns {number} Pseudo-random number
|
|
90
83
|
*/
|
|
91
|
-
function jsf32(a, b, c, d) {
|
|
84
|
+
export function jsf32(a, b, c, d) {
|
|
92
85
|
a |= 0;
|
|
93
86
|
b |= 0;
|
|
94
87
|
c |= 0;
|
|
@@ -100,14 +93,13 @@ function jsf32(a, b, c, d) {
|
|
|
100
93
|
d = (a + t) | 0;
|
|
101
94
|
return (d >>> 0) / 4294967296;
|
|
102
95
|
}
|
|
103
|
-
exports.jsf32 = jsf32;
|
|
104
96
|
/**
|
|
105
97
|
* xoshiro128**, Generator with a 128-bit state
|
|
106
98
|
*
|
|
107
99
|
* @param {number} a
|
|
108
100
|
* @returns {number} Pseudo-random number
|
|
109
101
|
*/
|
|
110
|
-
function xoshiro128ss(a, b, c, d) {
|
|
102
|
+
export function xoshiro128ss(a, b, c, d) {
|
|
111
103
|
var t = b << 9;
|
|
112
104
|
var r = a * 5;
|
|
113
105
|
r = ((r << 7) | (r >>> 25)) * 9;
|
|
@@ -119,7 +111,6 @@ function xoshiro128ss(a, b, c, d) {
|
|
|
119
111
|
d = (d << 11) | (d >>> 21);
|
|
120
112
|
return (r >>> 0) / 4294967296;
|
|
121
113
|
}
|
|
122
|
-
exports.xoshiro128ss = xoshiro128ss;
|
|
123
114
|
/**
|
|
124
115
|
* Generate a pseudo-random number in the interval [0, 1]
|
|
125
116
|
* PRNG equivalent of `Math.random()`
|
|
@@ -127,13 +118,12 @@ exports.xoshiro128ss = xoshiro128ss;
|
|
|
127
118
|
* @param {PRNGParameters} prng PRNG parameters
|
|
128
119
|
* @returns {number} Pseudo-random number
|
|
129
120
|
*/
|
|
130
|
-
function random(prng) {
|
|
121
|
+
export function random(prng) {
|
|
131
122
|
var seed = typeof prng === 'string' ? prng : prng.seed;
|
|
132
123
|
var algorithm = typeof prng === 'string' ? splitmix32 : prng.algorithm;
|
|
133
124
|
var hashes = cyrb128(seed);
|
|
134
125
|
return algorithm.apply(void 0, hashes);
|
|
135
126
|
}
|
|
136
|
-
exports.random = random;
|
|
137
127
|
/**
|
|
138
128
|
* Generate a pseudo-random boolean (true or false)
|
|
139
129
|
*
|
|
@@ -141,11 +131,10 @@ exports.random = random;
|
|
|
141
131
|
* @param {number} [probability=0.5] Probability to get true
|
|
142
132
|
* @returns {boolean} Either `true` or `false`
|
|
143
133
|
*/
|
|
144
|
-
function randomBoolean(prng, probability) {
|
|
134
|
+
export function randomBoolean(prng, probability) {
|
|
145
135
|
if (probability === void 0) { probability = 0.5; }
|
|
146
136
|
return random(prng) < probability;
|
|
147
137
|
}
|
|
148
|
-
exports.randomBoolean = randomBoolean;
|
|
149
138
|
/**
|
|
150
139
|
* Generate a pseudo-random sign (1 or -1)
|
|
151
140
|
*
|
|
@@ -153,11 +142,10 @@ exports.randomBoolean = randomBoolean;
|
|
|
153
142
|
* @param {number} [probability=0.5] Probability to get 1
|
|
154
143
|
* @returns {number} Either 1 or -1
|
|
155
144
|
*/
|
|
156
|
-
function randomSign(prng, probability) {
|
|
145
|
+
export function randomSign(prng, probability) {
|
|
157
146
|
if (probability === void 0) { probability = 0.5; }
|
|
158
147
|
return randomBoolean(prng, probability) ? 1 : -1;
|
|
159
148
|
}
|
|
160
|
-
exports.randomSign = randomSign;
|
|
161
149
|
/**
|
|
162
150
|
* Generate a pseudo-random floating-point number within a specified range
|
|
163
151
|
*
|
|
@@ -167,13 +155,12 @@ exports.randomSign = randomSign;
|
|
|
167
155
|
* @param {number} [precision=2] Number of digits after the decimal point
|
|
168
156
|
* @returns {number} Generated float
|
|
169
157
|
*/
|
|
170
|
-
function randomFloat(prng, min, max, precision) {
|
|
158
|
+
export function randomFloat(prng, min, max, precision) {
|
|
171
159
|
if (min === void 0) { min = 0; }
|
|
172
160
|
if (max === void 0) { max = 1; }
|
|
173
161
|
if (precision === void 0) { precision = 2; }
|
|
174
162
|
return parseFloat(Math.min(min + random(prng) * (max - min), max).toFixed(precision));
|
|
175
163
|
}
|
|
176
|
-
exports.randomFloat = randomFloat;
|
|
177
164
|
/**
|
|
178
165
|
* Generate a pseudo-random integer number within a specified range
|
|
179
166
|
*
|
|
@@ -182,20 +169,18 @@ exports.randomFloat = randomFloat;
|
|
|
182
169
|
* @param {number} max Maximum boundary
|
|
183
170
|
* @returns {number} Generated integer
|
|
184
171
|
*/
|
|
185
|
-
function randomInt(prng, min, max) {
|
|
172
|
+
export function randomInt(prng, min, max) {
|
|
186
173
|
return Math.floor(random(prng) * (max - min + 1) + min);
|
|
187
174
|
}
|
|
188
|
-
exports.randomInt = randomInt;
|
|
189
175
|
/**
|
|
190
176
|
* Generate a pseudo-random hexadecimal color
|
|
191
177
|
*
|
|
192
178
|
* @param {PRNGParameters} prng PRNG parameters
|
|
193
179
|
* @returns {string} Generated hexadecimal color
|
|
194
180
|
*/
|
|
195
|
-
function randomHexColor(prng) {
|
|
181
|
+
export function randomHexColor(prng) {
|
|
196
182
|
return '#' + ('00000' + ((random(prng) * (1 << 24)) | 0).toString(16)).slice(-6);
|
|
197
183
|
}
|
|
198
|
-
exports.randomHexColor = randomHexColor;
|
|
199
184
|
/**
|
|
200
185
|
* Pick a pseudo-random item from a given array
|
|
201
186
|
*
|
|
@@ -203,12 +188,11 @@ exports.randomHexColor = randomHexColor;
|
|
|
203
188
|
* @param {T[]} array Array to pick the item from
|
|
204
189
|
* @returns {T|undefined} Random item picked
|
|
205
190
|
*/
|
|
206
|
-
function randomItem(prng, array) {
|
|
191
|
+
export function randomItem(prng, array) {
|
|
207
192
|
if (array.length === 0)
|
|
208
193
|
return undefined;
|
|
209
194
|
return array[randomInt(prng, 0, array.length - 1)];
|
|
210
195
|
}
|
|
211
|
-
exports.randomItem = randomItem;
|
|
212
196
|
/**
|
|
213
197
|
* Pick a pseudo-random property value from a given object
|
|
214
198
|
*
|
|
@@ -216,14 +200,13 @@ exports.randomItem = randomItem;
|
|
|
216
200
|
* @param {object} object Object to pick the property from
|
|
217
201
|
* @returns {T|undefined} Random item picked
|
|
218
202
|
*/
|
|
219
|
-
function randomObjectProperty(prng, object) {
|
|
203
|
+
export function randomObjectProperty(prng, object) {
|
|
220
204
|
var keys = Object.keys(object);
|
|
221
205
|
var key = randomItem(prng, keys);
|
|
222
206
|
if (key && object.hasOwnProperty(key)) {
|
|
223
207
|
return object[key];
|
|
224
208
|
}
|
|
225
209
|
}
|
|
226
|
-
exports.randomObjectProperty = randomObjectProperty;
|
|
227
210
|
/**
|
|
228
211
|
* Select a pseudo-random index from an array of weighted items
|
|
229
212
|
*
|
|
@@ -231,7 +214,7 @@ exports.randomObjectProperty = randomObjectProperty;
|
|
|
231
214
|
* @param {number[]} weights Array of weights
|
|
232
215
|
* @returns {number} Random index based on weights
|
|
233
216
|
*/
|
|
234
|
-
function randomIndex(prng, weights) {
|
|
217
|
+
export function randomIndex(prng, weights) {
|
|
235
218
|
if (weights.length === 0)
|
|
236
219
|
return -1;
|
|
237
220
|
var totalWeight = 0;
|
|
@@ -249,7 +232,6 @@ function randomIndex(prng, weights) {
|
|
|
249
232
|
}
|
|
250
233
|
return 0;
|
|
251
234
|
}
|
|
252
|
-
exports.randomIndex = randomIndex;
|
|
253
235
|
/**
|
|
254
236
|
* Generate a pseudo-random number fitting a Gaussian (normal) distribution
|
|
255
237
|
*
|
|
@@ -258,7 +240,7 @@ exports.randomIndex = randomIndex;
|
|
|
258
240
|
* @param {number} [spread=1] Standard deviation
|
|
259
241
|
* @returns {number} Generated number
|
|
260
242
|
*/
|
|
261
|
-
function randomGaussian(prng, mean, spread) {
|
|
243
|
+
export function randomGaussian(prng, mean, spread) {
|
|
262
244
|
if (mean === void 0) { mean = 0; }
|
|
263
245
|
if (spread === void 0) { spread = 1; }
|
|
264
246
|
var seed = typeof prng === 'string' ? prng : prng.seed;
|
|
@@ -269,4 +251,3 @@ function randomGaussian(prng, mean, spread) {
|
|
|
269
251
|
var z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
|
|
270
252
|
return mean + z * spread;
|
|
271
253
|
}
|
|
272
|
-
exports.randomGaussian = randomGaussian;
|
package/lib/query.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasQuery = exports.setQuery = exports.getQuery = void 0;
|
|
4
1
|
var search = typeof window !== 'undefined' ? window.location.search : undefined;
|
|
5
2
|
var history = typeof window !== 'undefined' ? window.history : undefined;
|
|
6
3
|
/**
|
|
@@ -9,31 +6,28 @@ var history = typeof window !== 'undefined' ? window.history : undefined;
|
|
|
9
6
|
* @param {string} property Query property to check
|
|
10
7
|
* @returns {string|null} Value associated to the given search parameter
|
|
11
8
|
*/
|
|
12
|
-
function getQuery(property) {
|
|
9
|
+
export function getQuery(property) {
|
|
13
10
|
var params = new URLSearchParams(search);
|
|
14
11
|
return params.get(property);
|
|
15
12
|
}
|
|
16
|
-
exports.getQuery = getQuery;
|
|
17
13
|
/**
|
|
18
14
|
* Set a query parameter
|
|
19
15
|
*
|
|
20
16
|
* @param {string} property Query property to set
|
|
21
17
|
* @param {string} value Value to set
|
|
22
18
|
*/
|
|
23
|
-
function setQuery(property, value) {
|
|
19
|
+
export function setQuery(property, value) {
|
|
24
20
|
var params = new URLSearchParams(search);
|
|
25
21
|
params.set(property, value);
|
|
26
22
|
var string = '?' + params.toString().replace(/\=$/, '').replace(/\=\&/g, '&');
|
|
27
23
|
history === null || history === void 0 ? void 0 : history.pushState({ str: string }, '', string);
|
|
28
24
|
}
|
|
29
|
-
exports.setQuery = setQuery;
|
|
30
25
|
/**
|
|
31
26
|
* Check if a query parameter exists
|
|
32
27
|
*
|
|
33
28
|
* @param {string} property Query property to check
|
|
34
29
|
* @returns {boolean} True if the given property has a query parameter value, false otherwise
|
|
35
30
|
*/
|
|
36
|
-
function hasQuery(property) {
|
|
31
|
+
export function hasQuery(property) {
|
|
37
32
|
return getQuery(property) !== null;
|
|
38
33
|
}
|
|
39
|
-
exports.hasQuery = hasQuery;
|
package/lib/random.d.ts
CHANGED
package/lib/random.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.insideSphere = exports.onSphere = exports.insideCircle = exports.onCircle = exports.randomGaussian = exports.randomIndex = exports.randomObjectProperty = exports.randomItem = exports.randomHexColor = exports.randomInt = exports.randomFloat = exports.randomSign = exports.randomBoolean = void 0;
|
|
4
|
-
var geometry_1 = require("./geometry");
|
|
1
|
+
import { radToSphere } from './geometry';
|
|
5
2
|
/**
|
|
6
3
|
* Generate a random boolean (true or false)
|
|
7
4
|
*
|
|
8
5
|
* @param {number} [probability=0.5] Probability to get true
|
|
9
6
|
* @returns {boolean} Either `true` or `false`
|
|
10
7
|
*/
|
|
11
|
-
function randomBoolean(probability) {
|
|
8
|
+
export function randomBoolean(probability) {
|
|
12
9
|
if (probability === void 0) { probability = 0.5; }
|
|
13
10
|
return Math.random() < probability;
|
|
14
11
|
}
|
|
15
|
-
exports.randomBoolean = randomBoolean;
|
|
16
12
|
/**
|
|
17
13
|
* Generate a random sign (1 or -1)
|
|
18
14
|
*
|
|
19
15
|
* @param {number} [probability=0.5] Probability to get 1
|
|
20
16
|
* @returns {number} Either 1 or -1
|
|
21
17
|
*/
|
|
22
|
-
function randomSign(probability) {
|
|
18
|
+
export function randomSign(probability) {
|
|
23
19
|
if (probability === void 0) { probability = 0.5; }
|
|
24
20
|
return randomBoolean(probability) ? 1 : -1;
|
|
25
21
|
}
|
|
26
|
-
exports.randomSign = randomSign;
|
|
27
22
|
/**
|
|
28
23
|
* Generate a random floating-point number within a specified range
|
|
29
24
|
*
|
|
@@ -32,13 +27,12 @@ exports.randomSign = randomSign;
|
|
|
32
27
|
* @param {number} [precision=2] Number of digits after the decimal point
|
|
33
28
|
* @returns {number} Generated float
|
|
34
29
|
*/
|
|
35
|
-
function randomFloat(min, max, precision) {
|
|
30
|
+
export function randomFloat(min, max, precision) {
|
|
36
31
|
if (min === void 0) { min = 0; }
|
|
37
32
|
if (max === void 0) { max = 1; }
|
|
38
33
|
if (precision === void 0) { precision = 2; }
|
|
39
34
|
return parseFloat(Math.min(min + Math.random() * (max - min), max).toFixed(precision));
|
|
40
35
|
}
|
|
41
|
-
exports.randomFloat = randomFloat;
|
|
42
36
|
/**
|
|
43
37
|
* Generate a random integer number within a specified range
|
|
44
38
|
*
|
|
@@ -46,52 +40,48 @@ exports.randomFloat = randomFloat;
|
|
|
46
40
|
* @param {number} max Maximum boundary
|
|
47
41
|
* @returns {number} Generated integer
|
|
48
42
|
*/
|
|
49
|
-
function randomInt(min, max) {
|
|
43
|
+
export function randomInt(min, max) {
|
|
50
44
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
51
45
|
}
|
|
52
|
-
exports.randomInt = randomInt;
|
|
53
46
|
/**
|
|
54
47
|
* Generate a random hexadecimal color
|
|
55
48
|
*
|
|
56
49
|
* @returns {string} Generated hexadecimal color
|
|
57
50
|
*/
|
|
58
|
-
function randomHexColor() {
|
|
51
|
+
export function randomHexColor() {
|
|
59
52
|
return '#' + ('00000' + ((Math.random() * (1 << 24)) | 0).toString(16)).slice(-6);
|
|
60
53
|
}
|
|
61
|
-
exports.randomHexColor = randomHexColor;
|
|
62
54
|
/**
|
|
63
55
|
* Pick a random item from a given array
|
|
64
56
|
*
|
|
65
57
|
* @param {T[]} array Array to pick the item from
|
|
66
58
|
* @returns {T|undefined} Random item picked
|
|
67
59
|
*/
|
|
68
|
-
function randomItem(array) {
|
|
60
|
+
export function randomItem(array) {
|
|
69
61
|
if (array.length === 0)
|
|
70
62
|
return undefined;
|
|
71
63
|
return array[randomInt(0, array.length - 1)];
|
|
72
64
|
}
|
|
73
|
-
exports.randomItem = randomItem;
|
|
74
65
|
/**
|
|
75
66
|
* Pick a random property value from a given object
|
|
76
67
|
*
|
|
77
68
|
* @param {object} object Object to pick the property from
|
|
78
69
|
* @returns {T|undefined} Random item picked
|
|
79
70
|
*/
|
|
80
|
-
function randomObjectProperty(object) {
|
|
71
|
+
export function randomObjectProperty(object) {
|
|
81
72
|
var keys = Object.keys(object);
|
|
82
73
|
var key = randomItem(keys);
|
|
83
74
|
if (key && object.hasOwnProperty(key)) {
|
|
84
75
|
return object[key];
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
|
-
exports.randomObjectProperty = randomObjectProperty;
|
|
88
78
|
/**
|
|
89
79
|
* Select a random index from an array of weighted items
|
|
90
80
|
*
|
|
91
81
|
* @param {number[]} weights Array of weights
|
|
92
82
|
* @returns {number} Random index based on weights
|
|
93
83
|
*/
|
|
94
|
-
function randomIndex(weights) {
|
|
84
|
+
export function randomIndex(weights) {
|
|
95
85
|
if (weights.length === 0)
|
|
96
86
|
return -1;
|
|
97
87
|
var totalWeight = 0;
|
|
@@ -110,7 +100,6 @@ function randomIndex(weights) {
|
|
|
110
100
|
}
|
|
111
101
|
return 0;
|
|
112
102
|
}
|
|
113
|
-
exports.randomIndex = randomIndex;
|
|
114
103
|
/**
|
|
115
104
|
* Generate a random number fitting a Gaussian (normal) distribution
|
|
116
105
|
*
|
|
@@ -118,7 +107,7 @@ exports.randomIndex = randomIndex;
|
|
|
118
107
|
* @param {number} [spread=1] Standard deviation
|
|
119
108
|
* @returns {number} Generated number
|
|
120
109
|
*/
|
|
121
|
-
function randomGaussian(mean, spread) {
|
|
110
|
+
export function randomGaussian(mean, spread) {
|
|
122
111
|
if (mean === void 0) { mean = 0; }
|
|
123
112
|
if (spread === void 0) { spread = 1; }
|
|
124
113
|
var u = Math.random();
|
|
@@ -126,7 +115,6 @@ function randomGaussian(mean, spread) {
|
|
|
126
115
|
var z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
|
|
127
116
|
return mean + z * spread;
|
|
128
117
|
}
|
|
129
|
-
exports.randomGaussian = randomGaussian;
|
|
130
118
|
// *********************
|
|
131
119
|
// Geometry
|
|
132
120
|
// *********************
|
|
@@ -137,7 +125,7 @@ exports.randomGaussian = randomGaussian;
|
|
|
137
125
|
* @param {Vector2} [target] Target vector
|
|
138
126
|
* @returns {Vector2} Random 2D point on circle
|
|
139
127
|
*/
|
|
140
|
-
function onCircle(radius, target) {
|
|
128
|
+
export function onCircle(radius, target) {
|
|
141
129
|
if (radius === void 0) { radius = 1; }
|
|
142
130
|
if (target === void 0) { target = { x: 0, y: 0 }; }
|
|
143
131
|
var angle = Math.random() * 2.0 * Math.PI;
|
|
@@ -145,7 +133,6 @@ function onCircle(radius, target) {
|
|
|
145
133
|
target.y = radius * Math.sin(angle);
|
|
146
134
|
return target;
|
|
147
135
|
}
|
|
148
|
-
exports.onCircle = onCircle;
|
|
149
136
|
/**
|
|
150
137
|
* Produce a random 2D point inside a unit circle
|
|
151
138
|
*
|
|
@@ -153,13 +140,12 @@ exports.onCircle = onCircle;
|
|
|
153
140
|
* @param {Vector2} [target] Target vector
|
|
154
141
|
* @returns {Vector2} Random 2D point inside circle
|
|
155
142
|
*/
|
|
156
|
-
function insideCircle(radius, target) {
|
|
143
|
+
export function insideCircle(radius, target) {
|
|
157
144
|
if (radius === void 0) { radius = 1; }
|
|
158
145
|
if (target === void 0) { target = { x: 0, y: 0 }; }
|
|
159
146
|
radius *= Math.random();
|
|
160
147
|
return onCircle(radius, target);
|
|
161
148
|
}
|
|
162
|
-
exports.insideCircle = insideCircle;
|
|
163
149
|
/**
|
|
164
150
|
* Produce a random 3D point on the surface of a unit sphere
|
|
165
151
|
*
|
|
@@ -167,16 +153,15 @@ exports.insideCircle = insideCircle;
|
|
|
167
153
|
* @param {Vector3} [target] Target vector
|
|
168
154
|
* @returns {Vector3} Random 3D point on sphere
|
|
169
155
|
*/
|
|
170
|
-
function onSphere(radius, target) {
|
|
156
|
+
export function onSphere(radius, target) {
|
|
171
157
|
if (radius === void 0) { radius = 1; }
|
|
172
158
|
if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
|
|
173
159
|
var u = Math.random() * Math.PI * 2;
|
|
174
160
|
var v = Math.random() * 2 - 1;
|
|
175
161
|
var phi = u;
|
|
176
162
|
var theta = Math.acos(v);
|
|
177
|
-
return
|
|
163
|
+
return radToSphere(radius, phi, theta, target);
|
|
178
164
|
}
|
|
179
|
-
exports.onSphere = onSphere;
|
|
180
165
|
/**
|
|
181
166
|
* Produce a random 3D point inside a unit sphere
|
|
182
167
|
*
|
|
@@ -184,10 +169,9 @@ exports.onSphere = onSphere;
|
|
|
184
169
|
* @param {Vector3} [target] Target vector
|
|
185
170
|
* @returns {Vector3} Random 3D point inside sphere
|
|
186
171
|
*/
|
|
187
|
-
function insideSphere(radius, target) {
|
|
172
|
+
export function insideSphere(radius, target) {
|
|
188
173
|
if (radius === void 0) { radius = 1; }
|
|
189
174
|
if (target === void 0) { target = { x: 0, y: 0, z: 0 }; }
|
|
190
175
|
radius *= Math.random();
|
|
191
176
|
return onSphere(radius, target);
|
|
192
177
|
}
|
|
193
|
-
exports.insideSphere = insideSphere;
|
package/lib/strings.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// ******************************************
|
|
3
2
|
// Cases
|
|
4
3
|
// ******************************************
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.removeTrailingSlash = exports.addTrailingSlash = exports.cleanPath = exports.toConstantCase = exports.toTrainCase = exports.toPascalCase = exports.toCamelCase = exports.toSnakeCase = exports.toKebabCase = exports.capitalize = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Capitalize a string
|
|
9
6
|
*
|
|
10
7
|
* @param {string} string String to capitalize
|
|
11
8
|
* @returns {string} Capitalized string
|
|
12
9
|
*/
|
|
13
|
-
function capitalize(string) {
|
|
10
|
+
export function capitalize(string) {
|
|
14
11
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
15
12
|
}
|
|
16
|
-
exports.capitalize = capitalize;
|
|
17
13
|
/**
|
|
18
14
|
* Convert a string to kebab-case: 'Hello world' -> 'hello-world'
|
|
19
15
|
*
|
|
20
16
|
* @param {string} string String to convert
|
|
21
17
|
* @returns {string} Converted string
|
|
22
18
|
*/
|
|
23
|
-
function toKebabCase(string) {
|
|
19
|
+
export function toKebabCase(string) {
|
|
24
20
|
return (string
|
|
25
21
|
// Insert a hyphen between lowercase and uppercase letters
|
|
26
22
|
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
@@ -28,14 +24,13 @@ function toKebabCase(string) {
|
|
|
28
24
|
.replace(/[\s_]+/g, '-')
|
|
29
25
|
.toLowerCase());
|
|
30
26
|
}
|
|
31
|
-
exports.toKebabCase = toKebabCase;
|
|
32
27
|
/**
|
|
33
28
|
* Convert a string to snake_case: 'Hello world' -> 'hello_world'
|
|
34
29
|
*
|
|
35
30
|
* @param {string} string String to convert
|
|
36
31
|
* @returns {string} Converted string
|
|
37
32
|
*/
|
|
38
|
-
function toSnakeCase(string) {
|
|
33
|
+
export function toSnakeCase(string) {
|
|
39
34
|
return (string
|
|
40
35
|
// Insert an underscore between lowercase and uppercase letters
|
|
41
36
|
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
@@ -43,42 +38,39 @@ function toSnakeCase(string) {
|
|
|
43
38
|
.replace(/[\s-]+/g, '_')
|
|
44
39
|
.toLowerCase());
|
|
45
40
|
}
|
|
46
|
-
exports.toSnakeCase = toSnakeCase;
|
|
47
41
|
/**
|
|
48
42
|
* Convert a string to camelCase: 'Hello world' -> 'helloWorld'
|
|
49
43
|
*
|
|
50
44
|
* @param {string} string String to convert
|
|
51
45
|
* @returns {string} Converted string
|
|
52
46
|
*/
|
|
53
|
-
function toCamelCase(string) {
|
|
47
|
+
export function toCamelCase(string) {
|
|
54
48
|
return (string
|
|
55
49
|
// Remove separators and capitalize the following letter
|
|
56
50
|
.replace(/[-_\s]+(.)?/g, function (_, c) { return (c ? c.toUpperCase() : ''); })
|
|
57
51
|
// Ensure the first letter is lowercase
|
|
58
52
|
.replace(/^([A-Z])/, function (c) { return c.toLowerCase(); }));
|
|
59
53
|
}
|
|
60
|
-
exports.toCamelCase = toCamelCase;
|
|
61
54
|
/**
|
|
62
55
|
* Convert a string to PascalCase: 'Hello world' -> 'HelloWorld'
|
|
63
56
|
*
|
|
64
57
|
* @param {string} string String to convert
|
|
65
58
|
* @returns {string} Converted string
|
|
66
59
|
*/
|
|
67
|
-
function toPascalCase(string) {
|
|
60
|
+
export function toPascalCase(string) {
|
|
68
61
|
return (string
|
|
69
62
|
// Remove separators and capitalizes the following letter
|
|
70
63
|
.replace(/[-_\s]+(.)?/g, function (_, c) { return (c ? c.toUpperCase() : ''); })
|
|
71
64
|
// Ensure the first letter is uppercase
|
|
72
65
|
.replace(/^([a-z])/, function (c) { return c.toUpperCase(); }));
|
|
73
66
|
}
|
|
74
|
-
exports.toPascalCase = toPascalCase;
|
|
75
67
|
/**
|
|
76
68
|
* Convert a string to Train-Case: 'Hello world' -> 'Hello-World'
|
|
77
69
|
*
|
|
78
70
|
* @param {string} string String to convert
|
|
79
71
|
* @returns {string} Converted string
|
|
80
72
|
*/
|
|
81
|
-
function toTrainCase(string) {
|
|
73
|
+
export function toTrainCase(string) {
|
|
82
74
|
return (string
|
|
83
75
|
// Insert a hyphen between lowercase and uppercase letters
|
|
84
76
|
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
@@ -88,14 +80,13 @@ function toTrainCase(string) {
|
|
|
88
80
|
// Capitalizes each word
|
|
89
81
|
.replace(/\b\w/g, function (c) { return c.toUpperCase(); }));
|
|
90
82
|
}
|
|
91
|
-
exports.toTrainCase = toTrainCase;
|
|
92
83
|
/**
|
|
93
84
|
* Convert a string to CONSTANT_CASE: 'Hello world' -> 'HELLO_WORLD'
|
|
94
85
|
*
|
|
95
86
|
* @param {string} string String to convert
|
|
96
87
|
* @returns {string} Converted string
|
|
97
88
|
*/
|
|
98
|
-
function toConstantCase(string) {
|
|
89
|
+
export function toConstantCase(string) {
|
|
99
90
|
return (string
|
|
100
91
|
// Insert an underscore between lowercase and uppercase letters
|
|
101
92
|
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
@@ -103,7 +94,6 @@ function toConstantCase(string) {
|
|
|
103
94
|
.replace(/[\s-]+/g, '_')
|
|
104
95
|
.toUpperCase());
|
|
105
96
|
}
|
|
106
|
-
exports.toConstantCase = toConstantCase;
|
|
107
97
|
// ******************************************
|
|
108
98
|
// Paths
|
|
109
99
|
// ******************************************
|
|
@@ -113,31 +103,28 @@ exports.toConstantCase = toConstantCase;
|
|
|
113
103
|
* @param {string} path Path to clean
|
|
114
104
|
* @returns {string} Cleaned path
|
|
115
105
|
*/
|
|
116
|
-
function cleanPath(path) {
|
|
106
|
+
export function cleanPath(path) {
|
|
117
107
|
return path.split('#')[0].split('?')[0];
|
|
118
108
|
}
|
|
119
|
-
exports.cleanPath = cleanPath;
|
|
120
109
|
/**
|
|
121
110
|
* Convert a path by ensuring it has a trailing slash
|
|
122
111
|
*
|
|
123
112
|
* @param {string} path Path to convert
|
|
124
113
|
* @returns {string}
|
|
125
114
|
*/
|
|
126
|
-
function addTrailingSlash(path) {
|
|
115
|
+
export function addTrailingSlash(path) {
|
|
127
116
|
if (path.match(/\.[a-z]{2,4}$/i) || path.match(/^mailto:/) || path.endsWith('/'))
|
|
128
117
|
return path;
|
|
129
118
|
return "".concat(path, "/");
|
|
130
119
|
}
|
|
131
|
-
exports.addTrailingSlash = addTrailingSlash;
|
|
132
120
|
/**
|
|
133
121
|
* Convert a path by ensuring it has not a trailing slash
|
|
134
122
|
*
|
|
135
123
|
* @param {string} path Path to convert
|
|
136
124
|
* @returns {string}
|
|
137
125
|
*/
|
|
138
|
-
function removeTrailingSlash(path) {
|
|
126
|
+
export function removeTrailingSlash(path) {
|
|
139
127
|
if (path.endsWith('/'))
|
|
140
128
|
return path.slice(0, -1);
|
|
141
129
|
return "".concat(path);
|
|
142
130
|
}
|
|
143
|
-
exports.removeTrailingSlash = removeTrailingSlash;
|