uom-types 2.0.0 → 3.0.1

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.
@@ -1,54 +1,83 @@
1
- import { Multiply, Divide, UnknownUnit, Inverse, DivideUnitExponents } from './index.mjs';
2
- import { Decimal } from './si-units.mjs';
1
+ import { M as Multiply, D as Divide, U as UnknownUnit, b as UnknownAbstractUnit, I as Inverse, a as Unit, A as AbstractUnit, c as DivideUnitExponents } from './_index.mjs';
3
2
 
4
- type OperationIO<T extends number> = T extends UnknownUnit ? T : number;
5
3
  /**
6
- * Add a value by the given value.
4
+ * @module uom-types/functions/higher-order
5
+ */
6
+
7
+ type OperationIO<T extends number> = [T] extends [
8
+ UnknownUnit | UnknownAbstractUnit
9
+ ] ? T : number;
10
+ /**
11
+ * Add two values with the same units together.
12
+ *
13
+ * @category Math
7
14
  */
8
15
  declare function add<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => OperationIO<T>;
9
16
  /**
10
- * Subtract one value from the given value.
17
+ * Subtract one value from another with the same units.
18
+ *
19
+ * @category Math
11
20
  */
12
21
  declare function sub<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => OperationIO<T>;
13
22
  /**
14
23
  * Multiple a value by the given value.
24
+ *
25
+ * @category Math
15
26
  */
16
- declare function mul<A extends number>(a: OperationIO<A>): <B extends number>(b: OperationIO<B>) => OperationIO<Multiply<B, A>>;
27
+ declare function mul<A extends number>(a: A): <B extends number>(b: B) => Multiply<B, A>;
17
28
  /**
18
29
  * Divide one value by the given value.
30
+ *
31
+ * @category Math
19
32
  */
20
- declare function div<A extends number>(a: OperationIO<A>): <B extends number>(b: OperationIO<B>) => OperationIO<Divide<B, A>>;
33
+ declare function div<A extends number>(a: A): <B extends number>(b: B) => Divide<B, A>;
21
34
  /**
22
35
  * Modulo operator.
36
+ *
37
+ * @category Math
23
38
  */
24
39
  declare function mod<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => OperationIO<T>;
25
40
  /**
26
41
  * Perform mathematic modular arithmetic.
42
+ *
43
+ * @category Math
27
44
  */
28
45
  declare function modSafe<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => OperationIO<T>;
29
- type PowFunction<E extends number, B extends number> = E extends UnknownUnit ? never : E extends -1 ? (b: OperationIO<B>) => OperationIO<Inverse<B>> : E extends 0 ? (b: OperationIO<B>) => OperationIO<B> extends UnknownUnit ? Decimal : 1 : E extends 0.5 ? (b: OperationIO<B>) => OperationIO<DivideUnitExponents<B, 2>> : E extends 1 ? (b: OperationIO<B>) => OperationIO<B> : E extends 2 ? (b: OperationIO<B>) => OperationIO<Multiply<B, B>> : E extends 3 ? (b: OperationIO<B>) => OperationIO<Multiply<B, Multiply<B, B>>> : E extends 4 ? (b: OperationIO<B>) => OperationIO<Multiply<B, Multiply<B, Multiply<B, B>>>> : (b: OperationIO<B>) => OperationIO<number>;
46
+ type PowFunction<E extends number, B extends number> = E extends UnknownUnit ? never : E extends UnknownAbstractUnit ? never : E extends -1 ? (b: B) => Inverse<B> : E extends 0 ? (b: B) => B extends UnknownUnit ? Unit<{}> : B extends UnknownAbstractUnit ? AbstractUnit<{}> : 1 : E extends 0.5 ? (b: B) => DivideUnitExponents<B, 2> : E extends 1 ? (b: B) => B : E extends 2 ? (b: B) => Multiply<B, B> : E extends 3 ? (b: B) => Multiply<B, Multiply<B, B>> : E extends 4 ? (b: B) => Multiply<B, Multiply<B, Multiply<B, B>>> : (b: B) => number;
30
47
  /**
31
48
  * Put a number to the power of the given value.
49
+ *
50
+ * @category Math
32
51
  */
33
52
  declare function pow<E extends number>(exponent: E): <B extends number>(base: Parameters<PowFunction<E, B>>[0]) => ReturnType<PowFunction<E, B>>;
34
53
  /**
35
54
  * Equal: Compare if a value is equal to the given value.
55
+ *
56
+ * @category Math
36
57
  */
37
58
  declare function eq<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => boolean;
38
59
  /**
39
60
  * Greater Than: Compare if a value is greater than the given value.
61
+ *
62
+ * @category Math
40
63
  */
41
64
  declare function gt<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => boolean;
42
65
  /**
43
66
  * Greater Than or Equal: Compare if a value is greater than or equal to the given value.
67
+ *
68
+ * @category Math
44
69
  */
45
70
  declare function gte<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => boolean;
46
71
  /**
47
72
  * Less Than: Compare if a value is less than the given value.
73
+ *
74
+ * @category Math
48
75
  */
49
76
  declare function lt<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => boolean;
50
77
  /**
51
78
  * Less Than or Equal: Compare if a value is less than or equal to the given value.
79
+ *
80
+ * @category Math
52
81
  */
53
82
  declare function lte<T extends number>(a: OperationIO<T>): (b: OperationIO<T>) => boolean;
54
83
 
@@ -1,73 +1,100 @@
1
1
  /**
2
- * Add a value by the given value.
2
+ * @module uom-types/functions/higher-order
3
+ */
4
+ /**
5
+ * Add two values with the same units together.
6
+ *
7
+ * @category Math
3
8
  */
4
9
  function add(a) {
5
10
  return (b) => (b + a);
6
11
  }
7
12
  /**
8
- * Subtract one value from the given value.
13
+ * Subtract one value from another with the same units.
14
+ *
15
+ * @category Math
9
16
  */
10
17
  function sub(a) {
11
18
  return (b) => (b - a);
12
19
  }
13
20
  /**
14
21
  * Multiple a value by the given value.
22
+ *
23
+ * @category Math
15
24
  */
16
25
  function mul(a) {
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Casting to actual type fails for some reason.
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return -- Casting to actual type fails for some reason.
18
27
  return (b) => (b * a);
19
28
  }
20
29
  /**
21
30
  * Divide one value by the given value.
31
+ *
32
+ * @category Math
22
33
  */
23
34
  function div(a) {
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Casting to actual type fails for some reason.
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return -- Casting to actual type fails for some reason.
25
36
  return (b) => (b / a);
26
37
  }
27
38
  /**
28
39
  * Modulo operator.
40
+ *
41
+ * @category Math
29
42
  */
30
43
  function mod(a) {
31
44
  return (b) => (b % a);
32
45
  }
33
46
  /**
34
47
  * Perform mathematic modular arithmetic.
48
+ *
49
+ * @category Math
35
50
  */
36
51
  function modSafe(a) {
37
52
  return (b) => (((b % a) + a) % a);
38
53
  }
39
54
  /**
40
55
  * Put a number to the power of the given value.
56
+ *
57
+ * @category Math
41
58
  */
42
59
  function pow(exponent) {
43
60
  return (base) => (base ** exponent);
44
61
  }
45
62
  /**
46
63
  * Equal: Compare if a value is equal to the given value.
64
+ *
65
+ * @category Math
47
66
  */
48
67
  function eq(a) {
49
68
  return (b) => b === a;
50
69
  }
51
70
  /**
52
71
  * Greater Than: Compare if a value is greater than the given value.
72
+ *
73
+ * @category Math
53
74
  */
54
75
  function gt(a) {
55
76
  return (b) => b > a;
56
77
  }
57
78
  /**
58
79
  * Greater Than or Equal: Compare if a value is greater than or equal to the given value.
80
+ *
81
+ * @category Math
59
82
  */
60
83
  function gte(a) {
61
84
  return (b) => b >= a;
62
85
  }
63
86
  /**
64
87
  * Less Than: Compare if a value is less than the given value.
88
+ *
89
+ * @category Math
65
90
  */
66
91
  function lt(a) {
67
92
  return (b) => b < a;
68
93
  }
69
94
  /**
70
95
  * Less Than or Equal: Compare if a value is less than or equal to the given value.
96
+ *
97
+ * @category Math
71
98
  */
72
99
  function lte(a) {
73
100
  return (b) => b <= a;
@@ -1,25 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Add two values together.
4
+ * @module uom-types/functions
5
+ */
6
+ /**
7
+ * Add two values with the same units together.
8
+ *
9
+ * @category Math
5
10
  */
6
11
  function add(a, b) {
7
12
  return (a + b);
8
13
  }
9
14
  /**
10
- * Subtract one value from another.
15
+ * Subtract one value from another with the same units.
16
+ *
17
+ * @category Math
11
18
  */
12
19
  function sub(a, b) {
13
20
  return (a - b);
14
21
  }
15
22
  /**
16
23
  * Multiple two values together.
24
+ *
25
+ * @category Math
17
26
  */
18
27
  function mul(a, b) {
19
28
  return (a * b);
20
29
  }
21
30
  /**
22
31
  * Divide one value by another.
32
+ *
33
+ * @category Math
23
34
  */
24
35
  function div(a, b) {
25
36
  return (a / b);
@@ -27,6 +38,7 @@ function div(a, b) {
27
38
  /**
28
39
  * Modulo operator.
29
40
  *
41
+ * @category Math
30
42
  * @param a - Must be an integer.
31
43
  * @param b - Must be an integer.
32
44
  * @returns `a % b`
@@ -37,6 +49,7 @@ function mod(a, b) {
37
49
  /**
38
50
  * Perform mathematic modular arithmetic.
39
51
  *
52
+ * @category Math
40
53
  * @param a - Must be an integer.
41
54
  * @param b - Must be a positive integer.
42
55
  * @returns An integer between zero (inclusive) and `b` (exclusive).
@@ -49,98 +62,243 @@ function pow(base, exponent) {
49
62
  }
50
63
  /**
51
64
  * Take the square root of the given value.
65
+ *
66
+ * @category Math
52
67
  */
53
68
  function sqrt(value) {
54
69
  return pow(value, 0.5);
55
70
  }
56
71
  /**
57
72
  * Inverse the given value.
73
+ *
74
+ * @category Math
58
75
  */
59
76
  function inverse(value) {
60
77
  return pow(value, -1);
61
78
  }
62
79
  /**
63
- * Make the given value negative.
80
+ * Returns the negative of the given value.
81
+ *
82
+ * @category Math
64
83
  */
65
84
  function negate(value) {
66
85
  return -value;
67
86
  }
68
87
  /**
69
- * Returns the absolute value of a number.
88
+ * Returns the absolute value of the given value.
89
+ *
90
+ * @category Math
70
91
  */
71
92
  function abs(value) {
72
93
  return Math.abs(value);
73
94
  }
74
95
  /**
75
96
  * Returns the greatest integer less than or equal to the given value.
97
+ *
98
+ * @category Math
76
99
  */
77
100
  function floor(value) {
78
101
  return Math.floor(value);
79
102
  }
80
103
  /**
81
104
  * Returns the smallest integer greater than or equal the given value.
105
+ *
106
+ * @category Math
82
107
  */
83
108
  function ceil(value) {
84
109
  return Math.ceil(value);
85
110
  }
86
111
  /**
87
112
  * Returns the given value rounded to the nearest integer.
113
+ *
114
+ * @category Math
88
115
  */
89
116
  function round(value) {
90
117
  return Math.round(value);
91
118
  }
92
119
  /**
93
120
  * Returns the larger value in the given collection.
121
+ *
122
+ * @category Math
94
123
  */
95
124
  function max(values) {
96
125
  return Math.max(...values);
97
126
  }
98
127
  /**
99
128
  * Returns the smallest value in the given collection.
129
+ *
130
+ * @category Math
100
131
  */
101
132
  function min(values) {
102
133
  return Math.min(...values);
103
134
  }
104
135
  /**
105
136
  * Takes the sum of all the values in the given collection.
137
+ *
138
+ * @category Math
106
139
  */
107
140
  function sum(values) {
108
- return values.reduce((add), 0);
141
+ return [...values].reduce(add, 0);
109
142
  }
110
143
  /**
111
144
  * Equal: Compare if two values are equal.
145
+ *
146
+ * @category Math
112
147
  */
113
148
  function eq(a, b) {
114
149
  return a === b;
115
150
  }
116
151
  /**
117
152
  * Greater Than: Compare if the first value is greater than the second.
153
+ *
154
+ * @category Math
118
155
  */
119
156
  function gt(a, b) {
120
157
  return a > b;
121
158
  }
122
159
  /**
123
160
  * Greater Than or Equal: Compare if the first value is greater than or equal to the second.
161
+ *
162
+ * @category Math
124
163
  */
125
164
  function gte(a, b) {
126
165
  return a >= b;
127
166
  }
128
167
  /**
129
168
  * Less Than: Compare if the first value is less than the second.
169
+ *
170
+ * @category Math
130
171
  */
131
172
  function lt(a, b) {
132
173
  return a < b;
133
174
  }
134
175
  /**
135
176
  * Less Than or Equal: Compare if the first value is less than or equal to the second.
177
+ *
178
+ * @category Math
136
179
  */
137
180
  function lte(a, b) {
138
181
  return a <= b;
139
182
  }
183
+ /**
184
+ * Returns the sine of a number.
185
+ *
186
+ * @category Math
187
+ */
188
+ function sin(angle) {
189
+ return Math.sin(angle);
190
+ }
191
+ /**
192
+ * Returns the cosine of a number.
193
+ *
194
+ * @category Math
195
+ */
196
+ function cos(angle) {
197
+ return Math.cos(angle);
198
+ }
199
+ /**
200
+ * Returns the tangent of a number.
201
+ *
202
+ * @category Math
203
+ */
204
+ function tan(angle) {
205
+ return Math.tan(angle);
206
+ }
207
+ /**
208
+ * Returns the arcsine of a number.
209
+ *
210
+ * @category Math
211
+ */
212
+ function asin(value) {
213
+ return Math.asin(value);
214
+ }
215
+ /**
216
+ * Returns the arc cosine (or inverse cosine) of a number.
217
+ *
218
+ * @category Math
219
+ */
220
+ function acos(value) {
221
+ return Math.acos(value);
222
+ }
223
+ /**
224
+ * Returns the arctangent of a number.
225
+ *
226
+ * @category Math
227
+ */
228
+ function atan(value) {
229
+ return Math.atan(value);
230
+ }
231
+ /**
232
+ * Returns the angle (in radians) from the X axis to a point.
233
+ *
234
+ * @category Math
235
+ * @param x - A number representing the cartesian x-coordinate.
236
+ * @param y - A number representing the cartesian y-coordinate.
237
+ */
238
+ function atan2(x, y) {
239
+ return Math.atan2(x, y);
240
+ }
241
+ /**
242
+ * Returns the hyperbolic sine of a number.
243
+ *
244
+ * @category Math
245
+ */
246
+ function sinh(angle) {
247
+ return Math.sinh(angle);
248
+ }
249
+ /**
250
+ * Returns the hyperbolic cosine of a number.
251
+ *
252
+ * @category Math
253
+ */
254
+ function cosh(angle) {
255
+ return Math.cosh(angle);
256
+ }
257
+ /**
258
+ * Returns the hyperbolic tangent of a number.
259
+ *
260
+ * @category Math
261
+ */
262
+ function tanh(angle) {
263
+ return Math.tanh(angle);
264
+ }
265
+ /**
266
+ * Returns the inverse hyperbolic sine of a number.
267
+ *
268
+ * @category Math
269
+ */
270
+ function asinh(value) {
271
+ return Math.asinh(value);
272
+ }
273
+ /**
274
+ * Returns the inverse hyperbolic cosine of a number.
275
+ *
276
+ * @category Math
277
+ */
278
+ function acosh(value) {
279
+ return Math.acosh(value);
280
+ }
281
+ /**
282
+ * Returns the inverse hyperbolic tangent of a number.
283
+ *
284
+ * @category Math
285
+ */
286
+ function atanh(value) {
287
+ return Math.atanh(value);
288
+ }
140
289
 
141
290
  exports.abs = abs;
291
+ exports.acos = acos;
292
+ exports.acosh = acosh;
142
293
  exports.add = add;
294
+ exports.asin = asin;
295
+ exports.asinh = asinh;
296
+ exports.atan = atan;
297
+ exports.atan2 = atan2;
298
+ exports.atanh = atanh;
143
299
  exports.ceil = ceil;
300
+ exports.cos = cos;
301
+ exports.cosh = cosh;
144
302
  exports.div = div;
145
303
  exports.eq = eq;
146
304
  exports.floor = floor;
@@ -157,6 +315,10 @@ exports.mul = mul;
157
315
  exports.negate = negate;
158
316
  exports.pow = pow;
159
317
  exports.round = round;
318
+ exports.sin = sin;
319
+ exports.sinh = sinh;
160
320
  exports.sqrt = sqrt;
161
321
  exports.sub = sub;
162
322
  exports.sum = sum;
323
+ exports.tan = tan;
324
+ exports.tanh = tanh;