fiberx-backend-toolkit 0.1.18 → 0.1.20

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.
@@ -83,6 +83,7 @@ declare class InputTransformerUtil {
83
83
  * Safely parse JSON input
84
84
  */
85
85
  static toJson<T = unknown>(json_input: string | unknown | null | undefined): T | null;
86
+ static toValidNumber(input: unknown): number | null;
86
87
  /**
87
88
  * Calculate pagination offset and limit
88
89
  */
@@ -237,6 +237,14 @@ class InputTransformerUtil {
237
237
  return null;
238
238
  }
239
239
  }
240
+ static toValidNumber(input) {
241
+ if (typeof input === "number")
242
+ return input;
243
+ if (typeof input === "string" && input.trim() !== "" && !isNaN(Number(input))) {
244
+ return Number(input);
245
+ }
246
+ return null;
247
+ }
240
248
  /**
241
249
  * Calculate pagination offset and limit
242
250
  */
@@ -24,7 +24,7 @@ declare class InputValidatorUtil {
24
24
  static isValidEmail(email: string): boolean;
25
25
  static isValidPhoneNumber(tel: string): boolean;
26
26
  static isValidPassword(password: string): boolean;
27
- static isDigit(input: any): boolean;
27
+ static isDigit(input: string | number): boolean;
28
28
  static isValidInteger(input: any): boolean;
29
29
  static isValidFloat(input: any): boolean;
30
30
  static isValidURLY(url: string): boolean;
@@ -36,9 +36,9 @@ class InputValidatorUtil {
36
36
  static isValidEmail(email) { return this.email_regex_reg_exp.test(email) && email.length <= 254; }
37
37
  static isValidPhoneNumber(tel) { return this.tel_regex_reg_exp.test(tel); }
38
38
  static isValidPassword(password) { return this.pass_regex_reg_exp.test(password); }
39
- static isDigit(input) { return !isNaN(input); }
39
+ static isDigit(input) { return typeof input === "number" || !isNaN(Number(input)); }
40
40
  static isValidInteger(input) { return Number.isInteger(input) && input > 0; }
41
- static isValidFloat(input) { return !isNaN(input) && parseFloat(input) > 0; }
41
+ static isValidFloat(input) { return !isNaN(Number(input)) && parseFloat(input) > 0; }
42
42
  static isValidURLY(url) {
43
43
  try {
44
44
  new URL(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiberx-backend-toolkit",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",