@oliversalzburg/js-utils 0.7.0 → 0.8.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/lib/async/async.d.ts +44 -0
- package/lib/async/async.js +76 -0
- package/lib/async/async.js.map +1 -0
- package/lib/async/async.test.d.ts +1 -0
- package/lib/async/async.test.js +26 -0
- package/lib/async/async.test.js.map +1 -0
- package/lib/cli/args.d.ts +9 -0
- package/lib/cli/args.js +49 -0
- package/lib/cli/args.js.map +1 -0
- package/lib/cli/args.test.d.ts +1 -0
- package/lib/cli/args.test.js +31 -0
- package/lib/cli/args.test.js.map +1 -0
- package/lib/core.d.ts +43 -0
- package/lib/core.js +2 -0
- package/lib/core.js.map +1 -0
- package/lib/data/array.d.ts +55 -0
- package/lib/data/array.js +90 -0
- package/lib/data/array.js.map +1 -0
- package/lib/data/nil.d.ts +92 -0
- package/lib/data/nil.js +131 -0
- package/lib/data/nil.js.map +1 -0
- package/lib/data/random.d.ts +111 -0
- package/lib/data/random.js +381 -0
- package/lib/data/random.js.map +1 -0
- package/lib/data/string.d.ts +30 -0
- package/lib/data/string.js +53 -0
- package/lib/data/string.js.map +1 -0
- package/lib/data/tree.d.ts +28 -0
- package/lib/data/tree.js +45 -0
- package/lib/data/tree.js.map +1 -0
- package/lib/device/shake.d.ts +79 -0
- package/lib/device/shake.js +135 -0
- package/lib/device/shake.js.map +1 -0
- package/lib/dom/core.d.ts +21 -0
- package/lib/dom/core.js +41 -0
- package/lib/dom/core.js.map +1 -0
- package/lib/errors/AbstractError.d.ts +29 -0
- package/lib/errors/AbstractError.js +59 -0
- package/lib/errors/AbstractError.js.map +1 -0
- package/lib/errors/InternalError.d.ts +19 -0
- package/lib/errors/InternalError.js +38 -0
- package/lib/errors/InternalError.js.map +1 -0
- package/lib/errors/InvalidArgumentError.d.ts +13 -0
- package/lib/errors/InvalidArgumentError.js +22 -0
- package/lib/errors/InvalidArgumentError.js.map +1 -0
- package/lib/errors/InvalidOperationError.d.ts +13 -0
- package/lib/errors/InvalidOperationError.js +22 -0
- package/lib/errors/InvalidOperationError.js.map +1 -0
- package/lib/errors/NotImplementedError.d.ts +12 -0
- package/lib/errors/NotImplementedError.js +21 -0
- package/lib/errors/NotImplementedError.js.map +1 -0
- package/lib/errors/PermissionViolationError.d.ts +13 -0
- package/lib/errors/PermissionViolationError.js +22 -0
- package/lib/errors/PermissionViolationError.js.map +1 -0
- package/lib/errors/ResourceConflictError.d.ts +12 -0
- package/lib/errors/ResourceConflictError.js +21 -0
- package/lib/errors/ResourceConflictError.js.map +1 -0
- package/lib/errors/UnknownError.d.ts +16 -0
- package/lib/errors/UnknownError.js +25 -0
- package/lib/errors/UnknownError.js.map +1 -0
- package/lib/errors/console.d.ts +7 -0
- package/lib/errors/console.js +13 -0
- package/lib/errors/console.js.map +1 -0
- package/lib/errors/error-serializer.d.ts +45 -0
- package/lib/errors/error-serializer.js +74 -0
- package/lib/errors/error-serializer.js.map +1 -0
- package/lib/errors/error-serializer.test.d.ts +1 -0
- package/lib/errors/error-serializer.test.js +109 -0
- package/lib/errors/error-serializer.test.js.map +1 -0
- package/lib/errors/stream.d.ts +7 -0
- package/lib/errors/stream.js +15 -0
- package/lib/errors/stream.js.map +1 -0
- package/lib/errors/tools.d.ts +10 -0
- package/lib/errors/tools.js +13 -0
- package/lib/errors/tools.js.map +1 -0
- package/lib/events/event.d.ts +9 -0
- package/lib/events/event.js +10 -0
- package/lib/events/event.js.map +1 -0
- package/lib/format/bytes.d.ts +118 -0
- package/lib/format/bytes.js +138 -0
- package/lib/format/bytes.js.map +1 -0
- package/lib/format/bytes.test.d.ts +1 -0
- package/lib/format/bytes.test.js +146 -0
- package/lib/format/bytes.test.js.map +1 -0
- package/lib/format/count.d.ts +14 -0
- package/lib/format/count.js +51 -0
- package/lib/format/count.js.map +1 -0
- package/lib/format/count.test.d.ts +1 -0
- package/lib/format/count.test.js +42 -0
- package/lib/format/count.test.js.map +1 -0
- package/lib/format/milliseconds.d.ts +100 -0
- package/lib/format/milliseconds.js +199 -0
- package/lib/format/milliseconds.js.map +1 -0
- package/lib/format/milliseconds.test.d.ts +1 -0
- package/lib/format/milliseconds.test.js +393 -0
- package/lib/format/milliseconds.test.js.map +1 -0
- package/lib/format/string.d.ts +24 -0
- package/lib/format/string.js +32 -0
- package/lib/format/string.js.map +1 -0
- package/lib/format/string.test.d.ts +1 -0
- package/lib/format/string.test.js +17 -0
- package/lib/format/string.test.js.map +1 -0
- package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
- package/lib/graphics/canvas-sandbox-mp.js +280 -0
- package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
- package/lib/graphics/canvas-sandbox.d.ts +255 -0
- package/lib/graphics/canvas-sandbox.js +358 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas.d.ts +57 -0
- package/lib/graphics/canvas.js +37 -0
- package/lib/graphics/canvas.js.map +1 -0
- package/lib/graphics/canvas2d-headless.d.ts +85 -0
- package/lib/graphics/canvas2d-headless.js +197 -0
- package/lib/graphics/canvas2d-headless.js.map +1 -0
- package/lib/graphics/canvas2d.d.ts +162 -0
- package/lib/graphics/canvas2d.js +332 -0
- package/lib/graphics/canvas2d.js.map +1 -0
- package/lib/graphics/canvas3d.d.ts +41 -0
- package/lib/graphics/canvas3d.js +67 -0
- package/lib/graphics/canvas3d.js.map +1 -0
- package/lib/graphics/color.d.ts +22 -0
- package/lib/graphics/color.js +38 -0
- package/lib/graphics/color.js.map +1 -0
- package/lib/graphics/core.d.ts +89 -0
- package/lib/graphics/core.js +146 -0
- package/lib/graphics/core.js.map +1 -0
- package/lib/graphics/palette-sampler.d.ts +7 -0
- package/lib/graphics/palette-sampler.js +21 -0
- package/lib/graphics/palette-sampler.js.map +1 -0
- package/lib/graphics/palette.d.ts +120 -0
- package/lib/graphics/palette.js +574 -0
- package/lib/graphics/palette.js.map +1 -0
- package/lib/graphics/palette.test.d.ts +1 -0
- package/lib/graphics/palette.test.js +43 -0
- package/lib/graphics/palette.test.js.map +1 -0
- package/lib/graphics/render-loop.d.ts +76 -0
- package/lib/graphics/render-loop.js +114 -0
- package/lib/graphics/render-loop.js.map +1 -0
- package/lib/graphics/shader.d.ts +56 -0
- package/lib/graphics/shader.js +80 -0
- package/lib/graphics/shader.js.map +1 -0
- package/lib/log/log.d.ts +11 -0
- package/lib/log/log.js +2 -0
- package/lib/log/log.js.map +1 -0
- package/lib/log/report.d.ts +57 -0
- package/lib/log/report.js +88 -0
- package/lib/log/report.js.map +1 -0
- package/lib/math/core.d.ts +85 -0
- package/lib/math/core.js +125 -0
- package/lib/math/core.js.map +1 -0
- package/lib/math/easing.d.ts +204 -0
- package/lib/math/easing.js +366 -0
- package/lib/math/easing.js.map +1 -0
- package/lib/math/euler.d.ts +18 -0
- package/lib/math/euler.js +22 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/matrix3.d.ts +227 -0
- package/lib/math/matrix3.js +508 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +119 -0
- package/lib/math/quaternion.js +270 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +26 -0
- package/lib/math/transformation.js +31 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +202 -0
- package/lib/math/vector2.js +310 -0
- package/lib/math/vector2.js.map +1 -0
- package/lib/math/vector3.d.ts +293 -0
- package/lib/math/vector3.js +492 -0
- package/lib/math/vector3.js.map +1 -0
- package/lib/math/vector4.d.ts +182 -0
- package/lib/math/vector4.js +302 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/measurement/performance.d.ts +13 -0
- package/lib/measurement/performance.js +19 -0
- package/lib/measurement/performance.js.map +1 -0
- package/package.json +5 -7
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A vector with 4 components, labeled: `X`, `Y`, `Z`, `W`.
|
|
3
|
+
*/
|
|
4
|
+
export class Vector4 {
|
|
5
|
+
/**
|
|
6
|
+
* The components of the vector.
|
|
7
|
+
*/
|
|
8
|
+
k = [0, 0, 0, 0];
|
|
9
|
+
/**
|
|
10
|
+
* Get the X component of the vector.
|
|
11
|
+
* @returns The X component of the vector.
|
|
12
|
+
*/
|
|
13
|
+
get x() {
|
|
14
|
+
return this.k[0];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Set the X component of the vector.
|
|
18
|
+
*/
|
|
19
|
+
set x(value) {
|
|
20
|
+
this.k[0] = value;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the Y component of the vector.
|
|
24
|
+
* @returns The Y component of the vector.
|
|
25
|
+
*/
|
|
26
|
+
get y() {
|
|
27
|
+
return this.k[1];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set the Y component of the vector.
|
|
31
|
+
*/
|
|
32
|
+
set y(value) {
|
|
33
|
+
this.k[1] = value;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the Z component of the vector.
|
|
37
|
+
* @returns The Z component of the vector.
|
|
38
|
+
*/
|
|
39
|
+
get z() {
|
|
40
|
+
return this.k[2];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the Z component of the vector.
|
|
44
|
+
*/
|
|
45
|
+
set z(value) {
|
|
46
|
+
this.k[2] = value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the W component of the vector.
|
|
50
|
+
* @returns The W component of the vector.
|
|
51
|
+
*/
|
|
52
|
+
get w() {
|
|
53
|
+
return this.k[3];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set the W component of the vector.
|
|
57
|
+
*/
|
|
58
|
+
set w(value) {
|
|
59
|
+
this.k[3] = value;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Constructs a new {@linkcode Vector4}.
|
|
63
|
+
* @param x - The X component.
|
|
64
|
+
* @param y - The Y component.
|
|
65
|
+
* @param z - The Z component.
|
|
66
|
+
* @param w - The W component.
|
|
67
|
+
*/
|
|
68
|
+
constructor(x, y, z, w) {
|
|
69
|
+
this.x = x;
|
|
70
|
+
this.y = y;
|
|
71
|
+
this.z = z;
|
|
72
|
+
this.w = w;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a copy of another {@linkcode Vector4}.
|
|
76
|
+
* @param vector - The vector to copy.
|
|
77
|
+
* @returns A new vector.
|
|
78
|
+
*/
|
|
79
|
+
static fromVector4(vector) {
|
|
80
|
+
return new Vector4(vector.x, vector.y, vector.z, vector.w);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets the vector to new coordinates.
|
|
84
|
+
* @param vector - The coordinates to set the vector to.
|
|
85
|
+
* @returns This instance.
|
|
86
|
+
*/
|
|
87
|
+
set(vector) {
|
|
88
|
+
return this.setXYZW(vector.x, vector.y, vector.z, vector.w);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Sets the vector to new coordinates.
|
|
92
|
+
* @param x - The new X component for the vector.
|
|
93
|
+
* @param y - The new Y component for the vector.
|
|
94
|
+
* @param z - The new Z component for the vector.
|
|
95
|
+
* @param w - The new W component for the vector.
|
|
96
|
+
* @returns This instance.
|
|
97
|
+
*/
|
|
98
|
+
setXYZW(x, y, z, w) {
|
|
99
|
+
this.x = x;
|
|
100
|
+
this.y = y;
|
|
101
|
+
this.z = z;
|
|
102
|
+
this.w = w;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Adds the XYZ components of another vector to this vector.
|
|
107
|
+
* @param vector - The vector to add to this vector.
|
|
108
|
+
* @returns This instance.
|
|
109
|
+
*/
|
|
110
|
+
add3(vector) {
|
|
111
|
+
return this.add3XYZ(vector.x, vector.y, vector.z);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Adds the XYZ components of another vector to this vector.
|
|
115
|
+
* @param x - The value to add to the X component.
|
|
116
|
+
* @param y - The value to add to the Y component.
|
|
117
|
+
* @param z - The value to add to the Z component.
|
|
118
|
+
* @returns This instance.
|
|
119
|
+
*/
|
|
120
|
+
add3XYZ(x, y, z) {
|
|
121
|
+
this.x += x;
|
|
122
|
+
this.y += y;
|
|
123
|
+
this.z += z;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Scales another vector and adds its XYZ components to this vector.
|
|
128
|
+
* @param vector - The vector to add to this vector.
|
|
129
|
+
* @param scale - The scaling to apply to the input vector.
|
|
130
|
+
* @returns This instance.
|
|
131
|
+
*/
|
|
132
|
+
addMultiply3(vector, scale) {
|
|
133
|
+
return this.addMultiply3XYZ(vector.x, vector.y, vector.z, scale);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Scales another vector and adds its XYZ components to this vector.
|
|
137
|
+
* @param x - The value to add to the X component.
|
|
138
|
+
* @param y - The value to add to the Y component.
|
|
139
|
+
* @param z - The value to add to the Z component.
|
|
140
|
+
* @param scale - The scaling to apply to the input vector.
|
|
141
|
+
* @returns This instance.
|
|
142
|
+
*/
|
|
143
|
+
addMultiply3XYZ(x, y, z, scale) {
|
|
144
|
+
this.x += x * scale;
|
|
145
|
+
this.y += y * scale;
|
|
146
|
+
this.z += z * scale;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Subtracts the XYZ components of another vector from this vector.
|
|
151
|
+
* @param vector - The vector to subtract from this vector.
|
|
152
|
+
* @returns This instance.
|
|
153
|
+
*/
|
|
154
|
+
subtract3(vector) {
|
|
155
|
+
return this.subtract3XYZ(vector.x, vector.y, vector.z);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Subtracts the XYZ components of another vector from this vector.
|
|
159
|
+
* @param x - The value to subtract from the X component.
|
|
160
|
+
* @param y - The value to subtract from the Y component.
|
|
161
|
+
* @param z - The value to subtract from the Z component.
|
|
162
|
+
* @returns This instance.
|
|
163
|
+
*/
|
|
164
|
+
subtract3XYZ(x, y, z) {
|
|
165
|
+
this.x -= x;
|
|
166
|
+
this.y -= y;
|
|
167
|
+
this.z -= z;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Multiplies the XYZ components of this vector by another vector.
|
|
172
|
+
* @param vector - The vector to multiply with this vector.
|
|
173
|
+
* @returns This instance.
|
|
174
|
+
*/
|
|
175
|
+
multiply3(vector) {
|
|
176
|
+
return this.multiply3XYZ(vector.x, vector.y, vector.z);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Multiplies the XYZ components of this vector by another vector.
|
|
180
|
+
* @param x - The value to multiply with the X component.
|
|
181
|
+
* @param y - The value to multiply with the Y component.
|
|
182
|
+
* @param z - The value to multiply with the Z component.
|
|
183
|
+
* @returns This instance.
|
|
184
|
+
*/
|
|
185
|
+
multiply3XYZ(x, y, z) {
|
|
186
|
+
this.x *= x;
|
|
187
|
+
this.y *= y;
|
|
188
|
+
this.z *= z;
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Multiplies the XYZ components of the vector by the given scale.
|
|
193
|
+
* @param scale - The scaling to apply to the vector.
|
|
194
|
+
* @returns This instance.
|
|
195
|
+
*/
|
|
196
|
+
multiply3Scale(scale) {
|
|
197
|
+
this.x *= scale;
|
|
198
|
+
this.y *= scale;
|
|
199
|
+
this.z *= scale;
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Divides the XYZ components of this vector by another vector.
|
|
204
|
+
* @param vector - The vector to divide this vector with.
|
|
205
|
+
* @returns This instance.
|
|
206
|
+
*/
|
|
207
|
+
divide3(vector) {
|
|
208
|
+
return this.divide3XYZ(vector.x, vector.y, vector.z);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Divides the XYZ components of this vector by another vector.
|
|
212
|
+
* @param x - The value to divide the X component with.
|
|
213
|
+
* @param y - The value to divide the Y component with.
|
|
214
|
+
* @param z - The value to divide the Z component with.
|
|
215
|
+
* @returns This instance.
|
|
216
|
+
*/
|
|
217
|
+
divide3XYZ(x, y, z) {
|
|
218
|
+
this.x /= x;
|
|
219
|
+
this.y /= y;
|
|
220
|
+
this.z /= z;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Divides the XYZ components of the vector by the given scale.
|
|
225
|
+
* @param scale - The scaling to apply to the vector.
|
|
226
|
+
* @returns This instance.
|
|
227
|
+
*/
|
|
228
|
+
divide3Scale(scale) {
|
|
229
|
+
this.x /= scale;
|
|
230
|
+
this.y /= scale;
|
|
231
|
+
this.z /= scale;
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Inverts the direction of the vector.
|
|
236
|
+
* @returns This instance.
|
|
237
|
+
*/
|
|
238
|
+
invertAdd3() {
|
|
239
|
+
this.x = -this.x;
|
|
240
|
+
this.y = -this.y;
|
|
241
|
+
this.z = -this.z;
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Inverts the vectors scale.
|
|
246
|
+
* @returns This instance.
|
|
247
|
+
*/
|
|
248
|
+
invertMultiply3() {
|
|
249
|
+
this.x = 1 / this.x;
|
|
250
|
+
this.y = 1 / this.y;
|
|
251
|
+
this.z = 1 / this.z;
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Clamps the components of the vector at the given boundary.
|
|
256
|
+
* @param floor - The lowest value to allow.
|
|
257
|
+
* @param ceil - The largest value to allow.
|
|
258
|
+
* @returns This instance.
|
|
259
|
+
*/
|
|
260
|
+
clamp(floor, ceil) {
|
|
261
|
+
if (this.x < floor) {
|
|
262
|
+
this.x = floor;
|
|
263
|
+
}
|
|
264
|
+
if (this.x > ceil) {
|
|
265
|
+
this.x = ceil;
|
|
266
|
+
}
|
|
267
|
+
if (this.y < floor) {
|
|
268
|
+
this.y = floor;
|
|
269
|
+
}
|
|
270
|
+
if (this.y > ceil) {
|
|
271
|
+
this.y = ceil;
|
|
272
|
+
}
|
|
273
|
+
if (this.z < floor) {
|
|
274
|
+
this.z = floor;
|
|
275
|
+
}
|
|
276
|
+
if (this.z > ceil) {
|
|
277
|
+
this.z = ceil;
|
|
278
|
+
}
|
|
279
|
+
if (this.w < floor) {
|
|
280
|
+
this.w = floor;
|
|
281
|
+
}
|
|
282
|
+
if (this.w > ceil) {
|
|
283
|
+
this.w = ceil;
|
|
284
|
+
}
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Linearly moves this vector towards a target vector.
|
|
289
|
+
* @param vector - The target vector.
|
|
290
|
+
* @param t - The location on the scale, from `0` to `1`.
|
|
291
|
+
* @returns This instance.
|
|
292
|
+
*/
|
|
293
|
+
lerp(vector, t) {
|
|
294
|
+
const tn = 1 - t;
|
|
295
|
+
this.x = this.x * tn + vector.x * t;
|
|
296
|
+
this.y = this.y * tn + vector.y * t;
|
|
297
|
+
this.z = this.z * tn + vector.z * t;
|
|
298
|
+
this.w = this.z * tn + vector.w * t;
|
|
299
|
+
return this;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=vector4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector4.js","sourceRoot":"","sources":["../../source/math/vector4.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACH,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAEjB;;;OAGG;IACH,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD;;OAEG;IACH,IAAI,CAAC,CAAC,KAAa;QAClB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IACnB,CAA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;QACf,CAAC;QACD,IAAI,IAAI,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QACf,CAAC;QACD,IAAI,IAAI,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;YACpB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,MAAyB,EAAE,CAAS;QACxC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AnyAsyncFunctionReturning, AnyFunctionReturning } from "../core.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executes the given function and measures how long the execution takes.
|
|
4
|
+
* @param context - The function of which the execution speed should be measured.
|
|
5
|
+
* @returns A tuple with the result of the function, and the execution time in milliseconds.
|
|
6
|
+
*/
|
|
7
|
+
export declare const measure: <TReturn>(context: AnyFunctionReturning<TReturn>) => [TReturn, number];
|
|
8
|
+
/**
|
|
9
|
+
* Executes the given async function and measures how long the execution takes.
|
|
10
|
+
* @param context - The async function of which the execution speed should be measured.
|
|
11
|
+
* @returns A tuple with the result of the function, and the execution time in milliseconds.
|
|
12
|
+
*/
|
|
13
|
+
export declare const measureAsync: <TReturn>(context: AnyAsyncFunctionReturning<TReturn>) => Promise<[TReturn, number]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes the given function and measures how long the execution takes.
|
|
3
|
+
* @param context - The function of which the execution speed should be measured.
|
|
4
|
+
* @returns A tuple with the result of the function, and the execution time in milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
export const measure = (context) => {
|
|
7
|
+
const entry = performance.now();
|
|
8
|
+
return [context(), performance.now() - entry];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Executes the given async function and measures how long the execution takes.
|
|
12
|
+
* @param context - The async function of which the execution speed should be measured.
|
|
13
|
+
* @returns A tuple with the result of the function, and the execution time in milliseconds.
|
|
14
|
+
*/
|
|
15
|
+
export const measureAsync = async (context) => {
|
|
16
|
+
const entry = performance.now();
|
|
17
|
+
return [await context(), performance.now() - entry];
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=performance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.js","sourceRoot":"","sources":["../../source/measurement/performance.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACtB,OAAsC,EAClB,EAAE;IACtB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,OAAO,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAChC,OAA2C,EACd,EAAE;IAC/B,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,OAAO,CAAC,MAAM,OAAO,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;AACrD,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@oliversalzburg/js-utils",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
|
|
7
7
|
"repository": {
|
|
@@ -16,17 +16,15 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"./lib
|
|
20
|
-
"./lib/**/*.js",
|
|
21
|
-
"./lib/**/*.map"
|
|
19
|
+
"./lib"
|
|
22
20
|
],
|
|
23
21
|
"scripts": {
|
|
24
|
-
"preversion": "make lint test",
|
|
22
|
+
"preversion": "make lint test && rm lib/tsconfig.tsbuildinfo",
|
|
25
23
|
"postversion": "git push"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
|
-
"@biomejs/biome": "2.5.
|
|
29
|
-
"@types/node": "26.
|
|
26
|
+
"@biomejs/biome": "2.5.11",
|
|
27
|
+
"@types/node": "26.4.1",
|
|
30
28
|
"@types/web": "0.0.354",
|
|
31
29
|
"typescript": "7.0.2"
|
|
32
30
|
},
|