@tempots/std 0.13.0 → 0.14.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/number.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- Constant value employed to see if two `number` values are very close.
3
- **/
2
+ * Constant value employed to see if two `number` values are very close.
3
+ * @public
4
+ */
4
5
  export declare const EPSILON = 1e-9;
5
6
  /**
6
7
  * Calculates the minimum difference between two angles in degrees.
@@ -10,7 +11,6 @@ export declare const EPSILON = 1e-9;
10
11
  * @param turn - The total number of degrees in a full turn. Default is 360.0.
11
12
  * @returns The difference between the two angles.
12
13
  * @public
13
- * @remarks
14
14
  * @example
15
15
  * ```ts
16
16
  * angleDifference(0, 90) // returns 90
@@ -19,7 +19,7 @@ export declare const EPSILON = 1e-9;
19
19
  * angleDifference(270, 0) // returns 90
20
20
  * ```
21
21
  */
22
- export declare function angleDifference(a: number, b: number, turn?: number): number;
22
+ export declare const angleDifference: (a: number, b: number, turn?: number) => number;
23
23
  /**
24
24
  * Rounds a number up to the specified number of decimals.
25
25
  *
@@ -27,7 +27,6 @@ export declare function angleDifference(a: number, b: number, turn?: number): nu
27
27
  * @param decimals - The number of decimals to round up to.
28
28
  * @returns The rounded up number.
29
29
  * @public
30
- * @remarks
31
30
  * @example
32
31
  * ```ts
33
32
  * ceilTo(1.234, 2) // returns 1.24
@@ -35,7 +34,7 @@ export declare function angleDifference(a: number, b: number, turn?: number): nu
35
34
  * ceilTo(1.234, 0) // returns 2
36
35
  * ```
37
36
  */
38
- export declare function ceilTo(v: number, decimals: number): number;
37
+ export declare const ceilTo: (v: number, decimals: number) => number;
39
38
  /**
40
39
  * `clamp` restricts a value within the specified range.
41
40
  *
@@ -44,7 +43,6 @@ export declare function ceilTo(v: number, decimals: number): number;
44
43
  * @param max - The maximum value.
45
44
  * @returns The clamped value.
46
45
  * @public
47
- * @remarks
48
46
  * @example
49
47
  * ```ts
50
48
  * clamp(1.3, 0, 1) // returns 1
@@ -52,7 +50,7 @@ export declare function ceilTo(v: number, decimals: number): number;
52
50
  * clamp(-0.5, 0, 1) // returns 0.0
53
51
  * ```
54
52
  **/
55
- export declare function clamp(value: number, min: number, max: number): number;
53
+ export declare const clamp: (value: number, min: number, max: number) => number;
56
54
  /**
57
55
  * Clamps a number to a specified range and returns an integer value.
58
56
  *
@@ -61,7 +59,6 @@ export declare function clamp(value: number, min: number, max: number): number;
61
59
  * @param max - The maximum value of the range.
62
60
  * @returns The clamped integer value.
63
61
  * @public
64
- * @remarks
65
62
  * @example
66
63
  * ```ts
67
64
  * clampInt(5, 0, 10) // returns 5
@@ -69,7 +66,7 @@ export declare function clamp(value: number, min: number, max: number): number;
69
66
  * clampInt(-5, 0, 10) // returns 0
70
67
  * ```
71
68
  **/
72
- export declare function clampInt(value: number, min: number, max: number): number;
69
+ export declare const clampInt: (value: number, min: number, max: number) => number;
73
70
  /**
74
71
  * Like clamp but you only pass one argument (`max`) that is used as the upper limit
75
72
  * and the opposite (additive inverse or `-max`) as the lower limit.
@@ -78,7 +75,6 @@ export declare function clampInt(value: number, min: number, max: number): numbe
78
75
  * @param max - The maximum value.
79
76
  * @returns The clamped value.
80
77
  * @public
81
- * @remarks
82
78
  * @example
83
79
  * ```ts
84
80
  * clampSym(5, 10) // returns 5
@@ -87,7 +83,7 @@ export declare function clampInt(value: number, min: number, max: number): numbe
87
83
  * clampSym(-15, 10) // returns -10
88
84
  * ```
89
85
  **/
90
- export declare function clampSym(v: number, max: number): number;
86
+ export declare const clampSym: (v: number, max: number) => number;
91
87
  /**
92
88
  * It returns the comparison value (an integer number) between two `float` values.
93
89
  *
@@ -95,7 +91,6 @@ export declare function clampSym(v: number, max: number): number;
95
91
  * @param b - The second value to compare.
96
92
  * @returns A number indicating the relative order of the two values.
97
93
  * @public
98
- * @remarks
99
94
  * @example
100
95
  * ```ts
101
96
  * compare(5, 10) // returns -1
@@ -103,7 +98,7 @@ export declare function clampSym(v: number, max: number): number;
103
98
  * compare(5, 5) // returns 0
104
99
  * ```
105
100
  **/
106
- export declare function compareNumbers(a: number, b: number): number;
101
+ export declare const compareNumbers: (a: number, b: number) => number;
107
102
  /**
108
103
  * Rounds a number down to the specified number of decimals.
109
104
  *
@@ -111,7 +106,6 @@ export declare function compareNumbers(a: number, b: number): number;
111
106
  * @param decimals - The number of decimals to round down to.
112
107
  * @returns The rounded down number.
113
108
  * @public
114
- * @remarks
115
109
  * @example
116
110
  * ```ts
117
111
  * floorTo(1.234, 2) // returns 1.23
@@ -119,7 +113,7 @@ export declare function compareNumbers(a: number, b: number): number;
119
113
  * floorTo(1.234, 0) // returns 1
120
114
  * ```
121
115
  **/
122
- export declare function floorTo(v: number, decimals: number): number;
116
+ export declare const floorTo: (v: number, decimals: number) => number;
123
117
  /**
124
118
  * Converts a number to its hexadecimal representation.
125
119
  *
@@ -127,7 +121,6 @@ export declare function floorTo(v: number, decimals: number): number;
127
121
  * @param length - The desired length of the hexadecimal string. Defaults to 0.
128
122
  * @returns The hexadecimal representation of the number.
129
123
  * @public
130
- * @remarks
131
124
  * @example
132
125
  * ```ts
133
126
  * toHex(255) // returns 'ff'
@@ -135,7 +128,7 @@ export declare function floorTo(v: number, decimals: number): number;
135
128
  * toHex(255, 8) // returns '000000ff'
136
129
  * ```
137
130
  */
138
- export declare function toHex(num: number, length?: number): string;
131
+ export declare const toHex: (num: number, length?: number) => string;
139
132
  /**
140
133
  * `interpolate` returns a value between `a` and `b` for any value of `t` (normally between 0 and 1).
141
134
  *
@@ -144,7 +137,6 @@ export declare function toHex(num: number, length?: number): string;
144
137
  * @param t - The interpolation value.
145
138
  * @returns The interpolated value.
146
139
  * @public
147
- * @remarks
148
140
  * @example
149
141
  * ```ts
150
142
  * interpolate(0, 10, 0.5) // returns 5
@@ -152,7 +144,7 @@ export declare function toHex(num: number, length?: number): string;
152
144
  * interpolate(0, 10, 0.75) // returns 7.5
153
145
  * ```
154
146
  **/
155
- export declare function interpolate(a: number, b: number, t: number): number;
147
+ export declare const interpolate: (a: number, b: number, t: number) => number;
156
148
  /**
157
149
  * Interpolates values in a polar coordinate system looking for the narrowest delta angle.
158
150
  * It can be either clock-wise or counter-clock-wise.
@@ -163,7 +155,6 @@ export declare function interpolate(a: number, b: number, t: number): number;
163
155
  * @param turn - The total number of degrees in a full turn. Default is 360.0.
164
156
  * @returns The interpolated angle.
165
157
  * @public
166
- * @remarks
167
158
  * @example
168
159
  * ```ts
169
160
  * interpolateAngle(0, 90, 0.5) // returns 45
@@ -172,7 +163,7 @@ export declare function interpolate(a: number, b: number, t: number): number;
172
163
  * interpolateAngle(0, 270, 0.25) // returns 337.5
173
164
  * ```
174
165
  **/
175
- export declare function interpolateAngle(a: number, b: number, t: number, turn?: number): number;
166
+ export declare const interpolateAngle: (a: number, b: number, t: number, turn?: number) => number;
176
167
  /**
177
168
  * Calculates the widest angle difference between two angles.
178
169
  *
@@ -181,7 +172,6 @@ export declare function interpolateAngle(a: number, b: number, t: number, turn?:
181
172
  * @param turn - The total angle of a full turn. Defaults to 360 degrees.
182
173
  * @returns The widest angle difference between `a` and `b`.
183
174
  * @public
184
- * @remarks
185
175
  * @example
186
176
  * ```ts
187
177
  * widestAngleDifference(0, 90) // returns 90
@@ -190,7 +180,7 @@ export declare function interpolateAngle(a: number, b: number, t: number, turn?:
190
180
  * widestAngleDifference(270, 0) // returns 90
191
181
  * ```
192
182
  */
193
- export declare function widestAngleDifference(a: number, b: number, turn?: number): number;
183
+ export declare const widestAngleDifference: (a: number, b: number, turn?: number) => number;
194
184
  /**
195
185
  * Interpolates values in a polar coordinate system looking for the wideset delta angle.
196
186
  * It can be either clock-wise or counter-clock-wise.
@@ -201,7 +191,6 @@ export declare function widestAngleDifference(a: number, b: number, turn?: numbe
201
191
  * @param turn - The total number of degrees in a full turn. Default is 360.0.
202
192
  * @returns The interpolated angle.
203
193
  * @public
204
- * @remarks
205
194
  * @example
206
195
  * ```ts
207
196
  * interpolateWidestAngle(0, 90, 0.5) // returns 45
@@ -210,7 +199,7 @@ export declare function widestAngleDifference(a: number, b: number, turn?: numbe
210
199
  * interpolateWidestAngle(0, 270, 0.25) // returns 337.5
211
200
  * ```
212
201
  **/
213
- export declare function interpolateWidestAngle(a: number, b: number, t: number, turn?: number): number;
202
+ export declare const interpolateWidestAngle: (a: number, b: number, t: number, turn?: number) => number;
214
203
  /**
215
204
  * Interpolates values in a polar coordinate system always in clock-wise direction.
216
205
  *
@@ -220,7 +209,6 @@ export declare function interpolateWidestAngle(a: number, b: number, t: number,
220
209
  * @param turn - The total number of degrees in a full turn. Default is 360.0.
221
210
  * @returns The interpolated angle.
222
211
  * @public
223
- * @remarks
224
212
  * @example
225
213
  * ```ts
226
214
  * interpolateAngleCW(0, 90, 0.5) // returns 45
@@ -229,7 +217,7 @@ export declare function interpolateWidestAngle(a: number, b: number, t: number,
229
217
  * interpolateAngleCW(0, 270, 0.25) // returns 337.5
230
218
  * ```
231
219
  **/
232
- export declare function interpolateAngleCW(a: number, b: number, t: number, turn?: number): number;
220
+ export declare const interpolateAngleCW: (a: number, b: number, t: number, turn?: number) => number;
233
221
  /**
234
222
  * Interpolates values in a polar coordinate system always in counter-clock-wise direction.
235
223
  *
@@ -239,7 +227,6 @@ export declare function interpolateAngleCW(a: number, b: number, t: number, turn
239
227
  * @param turn - The total number of degrees in a full turn. Default is 360.0.
240
228
  * @returns The interpolated angle.
241
229
  * @public
242
- * @remarks
243
230
  * @example
244
231
  * ```ts
245
232
  * interpolateAngleCCW(0, 90, 0.5) // returns 45
@@ -248,7 +235,7 @@ export declare function interpolateAngleCW(a: number, b: number, t: number, turn
248
235
  * interpolateAngleCCW(0, 270, 0.25) // returns 337.5
249
236
  * ```
250
237
  **/
251
- export declare function interpolateAngleCCW(a: number, b: number, t: number, turn?: number): number;
238
+ export declare const interpolateAngleCCW: (a: number, b: number, t: number, turn?: number) => number;
252
239
  /**
253
240
  * number numbers can sometime introduce tiny errors even for simple operations.
254
241
  * `nearEquals` compares two floats using a tiny tollerance (last optional
@@ -259,7 +246,6 @@ export declare function interpolateAngleCCW(a: number, b: number, t: number, tur
259
246
  * @param tollerance - The tollerance value. Default is `EPSILON`.
260
247
  * @returns `true` if the numbers are very close, `false` otherwise.
261
248
  * @public
262
- * @remarks
263
249
  * @example
264
250
  * ```ts
265
251
  * nearEquals(5, 5.000000000000001) // returns true
@@ -267,7 +253,7 @@ export declare function interpolateAngleCCW(a: number, b: number, t: number, tur
267
253
  * nearEquals(5, 5.000000000001, 1e-9) // returns true
268
254
  * ```
269
255
  **/
270
- export declare function nearEquals(a: number, b: number, tollerance?: number): boolean;
256
+ export declare const nearEquals: (a: number, b: number, tollerance?: number) => boolean;
271
257
  /**
272
258
  * number numbers can sometime introduce tiny errors even for simple operations.
273
259
  * `nearEqualAngles` compares two angles (default is 360deg) using a tiny
@@ -280,7 +266,6 @@ export declare function nearEquals(a: number, b: number, tollerance?: number): b
280
266
  * @param tollerance - The tollerance value. Default is `EPSILON`.
281
267
  * @returns `true` if the angles are very close, `false` otherwise.
282
268
  * @public
283
- * @remarks
284
269
  * @example
285
270
  * ```ts
286
271
  * nearEqualAngles(0, 360) // returns true
@@ -289,7 +274,7 @@ export declare function nearEquals(a: number, b: number, tollerance?: number): b
289
274
  * nearEqualAngles(0, 361, 360, 1) // returns true
290
275
  * ```
291
276
  **/
292
- export declare function nearEqualAngles(a: number, b: number, turn?: number, tollerance?: number): boolean;
277
+ export declare const nearEqualAngles: (a: number, b: number, turn?: number, tollerance?: number) => boolean;
293
278
  /**
294
279
  * `nearZero` finds if the passed number is zero or very close to it. By default
295
280
  * `EPSILON` is used as the tollerance value.
@@ -298,7 +283,6 @@ export declare function nearEqualAngles(a: number, b: number, turn?: number, tol
298
283
  * @param tollerance - The tollerance value. Default is `EPSILON`.
299
284
  * @returns `true` if the number is zero or very close to it, `false` otherwise.
300
285
  * @public
301
- * @remarks
302
286
  * @example
303
287
  * ```ts
304
288
  * nearZero(0.000000000000001) // returns true
@@ -306,7 +290,7 @@ export declare function nearEqualAngles(a: number, b: number, turn?: number, tol
306
290
  * nearZero(0.000000001, 1e-9) // returns true
307
291
  * ```
308
292
  **/
309
- export declare function nearZero(n: number, tollerance?: number): boolean;
293
+ export declare const nearZero: (n: number, tollerance?: number) => boolean;
310
294
  /**
311
295
  * Computes the nth root (`index`) of `base`.
312
296
  *
@@ -314,7 +298,6 @@ export declare function nearZero(n: number, tollerance?: number): boolean;
314
298
  * @param index - The index of the root.
315
299
  * @returns The nth root of the base number.
316
300
  * @public
317
- * @remarks
318
301
  * @example
319
302
  * ```ts
320
303
  * root(8, 3) // returns 2
@@ -322,7 +305,7 @@ export declare function nearZero(n: number, tollerance?: number): boolean;
322
305
  * root(16, 4) // returns 2
323
306
  * ```
324
307
  **/
325
- export declare function root(base: number, index: number): number;
308
+ export declare const root: (base: number, index: number) => number;
326
309
  /**
327
310
  * Rounds a number to the specified number of decimals.
328
311
  *
@@ -330,7 +313,6 @@ export declare function root(base: number, index: number): number;
330
313
  * @param decimals - The number of decimals to round to.
331
314
  * @returns The rounded number.
332
315
  * @public
333
- * @remarks
334
316
  * @example
335
317
  * ```ts
336
318
  * roundTo(1.234, 2) // returns 1.23
@@ -338,21 +320,20 @@ export declare function root(base: number, index: number): number;
338
320
  * roundTo(1.234, 0) // returns 1
339
321
  * ```
340
322
  **/
341
- export declare function roundTo(f: number, decimals: number): number;
323
+ export declare const roundTo: (f: number, decimals: number) => number;
342
324
  /**
343
325
  * `sign` returns `-1` if `value` is a negative number, `1` otherwise.
344
326
  *
345
327
  * @param value - The number to check.
346
328
  * @returns `-1` if the number is negative, `1` otherwise.
347
329
  * @public
348
- * @remarks
349
330
  * @example
350
331
  * ```ts
351
332
  * sign(-5) // returns -1
352
333
  * sign(5) // returns 1
353
334
  * ```
354
335
  */
355
- export declare function sign<T extends number>(value: T): number;
336
+ export declare const sign: <T extends number>(value: T) => number;
356
337
  /**
357
338
  * Passed two boundaries values (`min`, `max`), `wrap` ensures that the passed value `v` will
358
339
  * be included in the boundaries. If the value exceeds `max`, the value is reduced by `min`
@@ -364,7 +345,6 @@ export declare function sign<T extends number>(value: T): number;
364
345
  * @param max - The maximum value of the range.
365
346
  * @returns The wrapped value.
366
347
  * @public
367
- * @remarks
368
348
  * @example
369
349
  * ```ts
370
350
  * wrap(5, 0, 10) // returns 5
@@ -372,7 +352,7 @@ export declare function sign<T extends number>(value: T): number;
372
352
  * wrap(-5, 0, 10) // returns 5
373
353
  * ```
374
354
  **/
375
- export declare function wrap(v: number, min: number, max: number): number;
355
+ export declare const wrap: (v: number, min: number, max: number) => number;
376
356
  /**
377
357
  * Similar to `wrap`, it works for numbers between 0 and `max`.
378
358
  *
@@ -380,7 +360,6 @@ export declare function wrap(v: number, min: number, max: number): number;
380
360
  * @param max - The maximum value of the range.
381
361
  * @returns The wrapped value.
382
362
  * @public
383
- * @remarks
384
363
  * @example
385
364
  * ```ts
386
365
  * wrapCircular(5, 10) // returns 5
@@ -388,4 +367,4 @@ export declare function wrap(v: number, min: number, max: number): number;
388
367
  * wrapCircular(-5, 10) // returns 5
389
368
  * ```
390
369
  **/
391
- export declare function wrapCircular(v: number, max: number): number;
370
+ export declare const wrapCircular: (v: number, max: number) => number;
package/number.js CHANGED
@@ -1,90 +1,33 @@
1
- import { lpad as l } from "./string.js";
2
- const f = 1e-9;
3
- function u(n, t, e = 360) {
4
- let r = (t - n) % e;
5
- return r < 0 && (r += e), r > e / 2 && (r -= e), r;
6
- }
7
- function p(n, t) {
8
- const e = Math.pow(10, t);
9
- return Math.ceil(n * e) / e;
10
- }
11
- function c(n, t, e) {
12
- return Math.min(Math.max(n, t), e);
13
- }
14
- function h(n, t, e) {
15
- return Math.trunc(c(n, t, e));
16
- }
17
- function M(n, t) {
18
- return c(n, -t, t);
19
- }
20
- function g(n, t) {
21
- return n < t ? -1 : n > t ? 1 : 0;
22
- }
23
- function N(n, t) {
24
- const e = Math.pow(10, t);
25
- return Math.floor(n * e) / e;
26
- }
27
- function w(n, t = 0) {
28
- return l(n.toString(16), "0", t);
29
- }
30
- function o(n, t, e) {
31
- return (t - n) * e + n;
32
- }
33
- function A(n, t, e, r = 360) {
34
- return i(o(n, n + u(n, t, r), e), r);
35
- }
36
- function a(n, t, e = 360) {
37
- let r = (t - n) % e;
38
- return r < 0 && (r += e), r > e / 2 && (r -= e), r;
39
- }
40
- function d(n, t, e, r = 360) {
41
- return i(
42
- o(n, n + a(n, t, r), e),
43
- r
44
- );
45
- }
46
- function m(n, t, e, r = 360) {
47
- return n = i(n, r), t = i(t, r), t < n && (t += r), i(o(n, t, e), r);
48
- }
49
- function C(n, t, e, r = 360) {
50
- return n = i(n, r), t = i(t, r), t > n && (t -= r), i(o(n, t, e), r);
51
- }
52
- function E(n, t, e = f) {
53
- return isFinite(n) ? isFinite(t) ? Math.abs(n - t) <= e : !1 : isNaN(n) ? isNaN(t) : isNaN(t) || isFinite(t) ? !1 : n > 0 == t > 0;
54
- }
55
- function F(n, t, e = 360, r = f) {
56
- return Math.abs(u(n, t, e)) <= r;
57
- }
58
- function S(n, t = f) {
59
- return Math.abs(n) <= t;
60
- }
61
- function T(n, t) {
62
- return Math.pow(n, 1 / t);
63
- }
64
- function W(n, t) {
65
- const e = Math.pow(10, t);
66
- return Math.round(n * e) / e;
67
- }
68
- function q(n) {
69
- return n < 0 ? -1 : 1;
70
- }
71
- function D(n, t, e) {
72
- const r = e - t + 1;
73
- return n < t && (n += r * ((t - n) / r + 1)), t + (n - t) % r;
74
- }
75
- function i(n, t) {
76
- return n = n % t, n < 0 && (n += t), n;
77
- }
1
+ import { lpad as a } from "./string.js";
2
+ const c = 1e-9, i = (t, e, n = 360) => {
3
+ let o = (e - t) % n;
4
+ return o < 0 && (o += n), o > n / 2 && (o -= n), o;
5
+ }, h = (t, e) => {
6
+ const n = Math.pow(10, e);
7
+ return Math.ceil(t * n) / n;
8
+ }, l = (t, e, n) => Math.min(Math.max(t, e), n), M = (t, e, n) => Math.trunc(l(t, e, n)), u = (t, e) => l(t, -e, e), g = (t, e) => t < e ? -1 : t > e ? 1 : 0, N = (t, e) => {
9
+ const n = Math.pow(10, e);
10
+ return Math.floor(t * n) / n;
11
+ }, w = (t, e = 0) => a(t.toString(16), "0", e), s = (t, e, n) => (e - t) * n + t, A = (t, e, n, o = 360) => r(s(t, t + i(t, e, o), n), o), f = (t, e, n = 360) => {
12
+ let o = (e - t) % n;
13
+ return o < 0 && (o += n), o > n / 2 && (o -= n), o;
14
+ }, d = (t, e, n, o = 360) => r(s(t, t + f(t, e, o), n), o), m = (t, e, n, o = 360) => (t = r(t, o), e = r(e, o), e < t && (e += o), r(s(t, e, n), o)), C = (t, e, n, o = 360) => (t = r(t, o), e = r(e, o), e > t && (e -= o), r(s(t, e, n), o)), E = (t, e, n = c) => isFinite(t) ? isFinite(e) ? Math.abs(t - e) <= n : !1 : isNaN(t) ? isNaN(e) : isNaN(e) || isFinite(e) ? !1 : t > 0 == e > 0, F = (t, e, n = 360, o = c) => Math.abs(i(t, e, n)) <= o, S = (t, e = c) => Math.abs(t) <= e, T = (t, e) => Math.pow(t, 1 / e), W = (t, e) => {
15
+ const n = Math.pow(10, e);
16
+ return Math.round(t * n) / n;
17
+ }, q = (t) => t < 0 ? -1 : 1, D = (t, e, n) => {
18
+ const o = n - e + 1;
19
+ return t < e && (t += o * ((e - t) / o + 1)), e + (t - e) % o;
20
+ }, r = (t, e) => (t = t % e, t < 0 && (t += e), t);
78
21
  export {
79
- f as EPSILON,
80
- u as angleDifference,
81
- p as ceilTo,
82
- c as clamp,
83
- h as clampInt,
84
- M as clampSym,
22
+ c as EPSILON,
23
+ i as angleDifference,
24
+ h as ceilTo,
25
+ l as clamp,
26
+ M as clampInt,
27
+ u as clampSym,
85
28
  g as compareNumbers,
86
29
  N as floorTo,
87
- o as interpolate,
30
+ s as interpolate,
88
31
  A as interpolateAngle,
89
32
  C as interpolateAngleCCW,
90
33
  m as interpolateAngleCW,
@@ -96,7 +39,7 @@ export {
96
39
  W as roundTo,
97
40
  q as sign,
98
41
  w as toHex,
99
- a as widestAngleDifference,
42
+ f as widestAngleDifference,
100
43
  D as wrap,
101
- i as wrapCircular
44
+ r as wrapCircular
102
45
  };
package/object.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function c(e){return Object.keys(e)}function o(e,t){const s=c(e),r=c(t);if(s.length!==r.length)return!1;for(const n of s)if(!(n in t))return!1;return!0}function u(e){return e!=null&&Object.getPrototypeOf(e)===Object.prototype}function i(e,...t){return c(e).reduce((r,n)=>(t.includes(n)||(r[n]=e[n]),r),{})}function b(e,t){return Object.assign({},e,t)}function j(e){return Object.keys(e).length===0}exports.isEmptyObject=j;exports.isObject=u;exports.mergeObjects=b;exports.objectKeys=c;exports.removeObjectFields=i;exports.sameObjectKeys=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=e=>Object.keys(e),o=(e,t)=>{const r=n(e),c=n(t);if(r.length!==c.length)return!1;for(const s of r)if(!(s in t))return!1;return!0},b=e=>e!=null&&Object.getPrototypeOf(e)===Object.prototype,j=(e,...t)=>n(e).reduce((c,s)=>(t.includes(s)||(c[s]=e[s]),c),{}),O=(e,t)=>Object.assign({},e,t),i=e=>Object.keys(e).length===0;exports.isEmptyObject=i;exports.isObject=b;exports.mergeObjects=O;exports.objectKeys=n;exports.removeObjectFields=j;exports.sameObjectKeys=o;
package/object.d.ts CHANGED
@@ -7,7 +7,7 @@ import { IndexKey, Merge, TupleToUnion } from './domain';
7
7
  * @returns An array of keys from the object.
8
8
  * @public
9
9
  */
10
- export declare function objectKeys<T extends object>(obj: T): Array<keyof T>;
10
+ export declare const objectKeys: <T extends object>(obj: T) => Array<keyof T>;
11
11
  /**
12
12
  * Checks if two objects have the same keys.
13
13
  *
@@ -16,7 +16,7 @@ export declare function objectKeys<T extends object>(obj: T): Array<keyof T>;
16
16
  * @returns `true` if both objects have the same keys, `false` otherwise.
17
17
  * @public
18
18
  */
19
- export declare function sameObjectKeys<T extends object>(a: T, b: T): boolean;
19
+ export declare const sameObjectKeys: <T extends object>(a: T, b: T) => boolean;
20
20
  /**
21
21
  * Checks if the given value is an object.
22
22
  *
@@ -24,7 +24,7 @@ export declare function sameObjectKeys<T extends object>(a: T, b: T): boolean;
24
24
  * @returns `true` if the value is an object, `false` otherwise.
25
25
  * @public
26
26
  */
27
- export declare function isObject(obj: unknown): obj is Record<IndexKey, unknown>;
27
+ export declare const isObject: (obj: unknown) => obj is Record<IndexKey, unknown>;
28
28
  /**
29
29
  * Removes specified fields from an object and returns a new object without those fields.
30
30
  *
@@ -33,7 +33,7 @@ export declare function isObject(obj: unknown): obj is Record<IndexKey, unknown>
33
33
  * @returns A new object without the specified fields.
34
34
  * @public
35
35
  */
36
- export declare function removeObjectFields<T extends object, F extends Array<keyof T>>(ob: T, ...fields: F): Omit<T, TupleToUnion<F>>;
36
+ export declare const removeObjectFields: <T extends object, F extends Array<keyof T>>(ob: T, ...fields: F) => Omit<T, TupleToUnion<F>>;
37
37
  /**
38
38
  * Merges two objects together.
39
39
  *
@@ -44,7 +44,7 @@ export declare function removeObjectFields<T extends object, F extends Array<key
44
44
  * @returns The merged object.
45
45
  * @public
46
46
  */
47
- export declare function mergeObjects<A extends Record<IndexKey, unknown>, B extends Record<IndexKey, unknown>>(a: A, b: B): Merge<A, B>;
47
+ export declare const mergeObjects: <A extends Record<IndexKey, unknown>, B extends Record<IndexKey, unknown>>(a: A, b: B) => Merge<A, B>;
48
48
  /**
49
49
  * Checks if an object is empty.
50
50
  * An object is considered empty if it has no own enumerable properties.
@@ -53,4 +53,4 @@ export declare function mergeObjects<A extends Record<IndexKey, unknown>, B exte
53
53
  * @returns `true` if the object is empty, `false` otherwise.
54
54
  * @public
55
55
  */
56
- export declare function isEmptyObject(obj: object): boolean;
56
+ export declare const isEmptyObject: (obj: object) => boolean;
package/object.js CHANGED
@@ -1,30 +1,15 @@
1
- function s(e) {
2
- return Object.keys(e);
3
- }
4
- function u(e, t) {
5
- const c = s(e), r = s(t);
6
- if (c.length !== r.length) return !1;
7
- for (const n of c)
8
- if (!(n in t)) return !1;
1
+ const r = (e) => Object.keys(e), o = (e, t) => {
2
+ const c = r(e), n = r(t);
3
+ if (c.length !== n.length) return !1;
4
+ for (const s of c)
5
+ if (!(s in t)) return !1;
9
6
  return !0;
10
- }
11
- function o(e) {
12
- return e != null && Object.getPrototypeOf(e) === Object.prototype;
13
- }
14
- function i(e, ...t) {
15
- return s(e).reduce((r, n) => (t.includes(n) || (r[n] = e[n]), r), {});
16
- }
17
- function f(e, t) {
18
- return Object.assign({}, e, t);
19
- }
20
- function O(e) {
21
- return Object.keys(e).length === 0;
22
- }
7
+ }, O = (e) => e != null && Object.getPrototypeOf(e) === Object.prototype, j = (e, ...t) => r(e).reduce((n, s) => (t.includes(s) || (n[s] = e[s]), n), {}), b = (e, t) => Object.assign({}, e, t), i = (e) => Object.keys(e).length === 0;
23
8
  export {
24
- O as isEmptyObject,
25
- o as isObject,
26
- f as mergeObjects,
27
- s as objectKeys,
28
- i as removeObjectFields,
29
- u as sameObjectKeys
9
+ i as isEmptyObject,
10
+ O as isObject,
11
+ b as mergeObjects,
12
+ r as objectKeys,
13
+ j as removeObjectFields,
14
+ o as sameObjectKeys
30
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/std",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "priority": 8,
5
5
  "description": "Std library for TypeScript. Natural complement to the Tempo libraries.",
6
6
  "keywords": [
@@ -49,6 +49,10 @@
49
49
  "import": "./equal.js",
50
50
  "require": "./equal.cjs"
51
51
  },
52
+ "./error": {
53
+ "import": "./error.js",
54
+ "require": "./error.cjs"
55
+ },
52
56
  "./function": {
53
57
  "import": "./function.js",
54
58
  "require": "./function.cjs"
@@ -65,6 +69,10 @@
65
69
  "import": "./object.js",
66
70
  "require": "./object.cjs"
67
71
  },
72
+ "./promise": {
73
+ "import": "./promise.js",
74
+ "require": "./promise.cjs"
75
+ },
68
76
  "./regexp": {
69
77
  "import": "./regexp.js",
70
78
  "require": "./regexp.cjs"
@@ -110,6 +118,9 @@
110
118
  "equal": [
111
119
  "./equal.d.ts"
112
120
  ],
121
+ "error": [
122
+ "./error.d.ts"
123
+ ],
113
124
  "function": [
114
125
  "./function.d.ts"
115
126
  ],
@@ -122,6 +133,9 @@
122
133
  "object": [
123
134
  "./object.d.ts"
124
135
  ],
136
+ "promise": [
137
+ "./promise.d.ts"
138
+ ],
125
139
  "regexp": [
126
140
  "./regexp.d.ts"
127
141
  ],
package/promise.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=(t,{abortSignal:e}={})=>new Promise((o,r)=>{const i=setTimeout(o,t);e&&e.addEventListener("abort",()=>{clearTimeout(i),r(new DOMException("Aborted","AbortError"))})});exports.sleep=s;
package/promise.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sleep for a given number of milliseconds.
3
+ *
4
+ * @param ms - The number of milliseconds to sleep.
5
+ * @param options - The options for the sleep function.
6
+ * @returns A promise that resolves after the given number of milliseconds.
7
+ * @public
8
+ */
9
+ export declare const sleep: (ms: number, { abortSignal }?: {
10
+ abortSignal?: AbortSignal;
11
+ }) => Promise<void>;
package/promise.js ADDED
@@ -0,0 +1,9 @@
1
+ const n = (t, { abortSignal: e } = {}) => new Promise((o, r) => {
2
+ const i = setTimeout(o, t);
3
+ e && e.addEventListener("abort", () => {
4
+ clearTimeout(i), r(new DOMException("Aborted", "AbortError"));
5
+ });
6
+ });
7
+ export {
8
+ n as sleep
9
+ };
package/regexp.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(i,s,u){const n=[];let l=0,e;if(s.global)for(s.lastIndex=0;(e=s.exec(i))!==null;)n.push(i.substring(l,e.index)),n.push(u(...e)),l=e.index+e[0].length;else for(;(e=s.exec(i.substring(l)))!==null;)n.push(i.substring(l,l+e.index)),n.push(u(...e)),l+=e.index+e[0].length;return n.push(i.substring(l)),n.join("")}exports.mapRegExp=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=(n,i,u)=>{const s=[];let l=0,e;if(i.global)for(i.lastIndex=0;(e=i.exec(n))!==null;)s.push(n.substring(l,e.index)),s.push(u(...e)),l=e.index+e[0].length;else for(;(e=i.exec(n.substring(l)))!==null;)s.push(n.substring(l,l+e.index)),s.push(u(...e)),l+=e.index+e[0].length;return s.push(n.substring(l)),s.join("")};exports.mapRegExp=g;