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