@tmlmobilidade/utils 20260326.2139.30 → 20260327.0.15

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/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './caching/index.js';
3
3
  export * from './generic/index.js';
4
4
  export * from './get-public-trip-id.js';
5
5
  export * from './http.js';
6
+ export * from './numbers/index.js';
6
7
  export * from './objects/index.js';
7
8
  export * from './permissions.js';
8
9
  export * from './run-on-interval.js';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './caching/index.js';
3
3
  export * from './generic/index.js';
4
4
  export * from './get-public-trip-id.js';
5
5
  export * from './http.js';
6
+ export * from './numbers/index.js';
6
7
  export * from './objects/index.js';
7
8
  export * from './permissions.js';
8
9
  export * from './run-on-interval.js';
@@ -0,0 +1 @@
1
+ export * from './to-int.js';
@@ -0,0 +1 @@
1
+ export * from './to-int.js';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Utility function to convert a number to an integer,
3
+ * handling null and undefined values gracefully.
4
+ * @param value The value to convert to an integer. Can be a number, null, or undefined.
5
+ * @returns The rounded integer value if the input is a number, or null if the input is null or undefined.
6
+ * @example
7
+ * roundToInt(3.7); // returns 4
8
+ * roundToInt(-2.3); // returns -2
9
+ * roundToInt(null); // returns null
10
+ * roundToInt(undefined); // returns null
11
+ */
12
+ export declare function roundToInt(value: null | number | string | undefined): null | number;
13
+ /**
14
+ * Utility function to convert a number to an integer,
15
+ * handling null and undefined values gracefully.
16
+ * @param value The value to convert to an integer. Can be a number, null, or undefined.
17
+ * @returns The truncated integer value if the input is a number, or null if the input is null or undefined.
18
+ * @example
19
+ * truncToInt(3.7); // returns 3
20
+ * truncToInt(-2.3); // returns -2
21
+ * truncToInt(null); // returns null
22
+ * truncToInt(undefined); // returns null
23
+ */
24
+ export declare function truncToInt(value: null | number | string | undefined): null | number;
@@ -0,0 +1,39 @@
1
+ /* * */
2
+ /**
3
+ * Utility function to convert a number to an integer,
4
+ * handling null and undefined values gracefully.
5
+ * @param value The value to convert to an integer. Can be a number, null, or undefined.
6
+ * @returns The rounded integer value if the input is a number, or null if the input is null or undefined.
7
+ * @example
8
+ * roundToInt(3.7); // returns 4
9
+ * roundToInt(-2.3); // returns -2
10
+ * roundToInt(null); // returns null
11
+ * roundToInt(undefined); // returns null
12
+ */
13
+ export function roundToInt(value) {
14
+ if (value === null || value === undefined)
15
+ return null;
16
+ const num = typeof value === 'string' ? parseFloat(value) : value;
17
+ if (isNaN(num))
18
+ return null;
19
+ return Math.round(num);
20
+ }
21
+ /**
22
+ * Utility function to convert a number to an integer,
23
+ * handling null and undefined values gracefully.
24
+ * @param value The value to convert to an integer. Can be a number, null, or undefined.
25
+ * @returns The truncated integer value if the input is a number, or null if the input is null or undefined.
26
+ * @example
27
+ * truncToInt(3.7); // returns 3
28
+ * truncToInt(-2.3); // returns -2
29
+ * truncToInt(null); // returns null
30
+ * truncToInt(undefined); // returns null
31
+ */
32
+ export function truncToInt(value) {
33
+ if (value === null || value === undefined)
34
+ return null;
35
+ const num = typeof value === 'string' ? parseFloat(value) : value;
36
+ if (isNaN(num))
37
+ return null;
38
+ return Math.trunc(num);
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/utils",
3
- "version": "20260326.2139.30",
3
+ "version": "20260327.0.15",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"