@tmlmobilidade/go-types-shared 20260829.1045.9 → 20260829.1122.26

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,15 +1,22 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
3
  * A schema for floats.
4
- * It coerces the value to a number.
4
+ * It transforms the value to a number.
5
+ * @throws if the value cannot be coerced to a number.
5
6
  * @example
6
7
  * ```ts
7
8
  * const schema = FloatSchema.parse(1);
8
9
  * // => 1
9
10
  * const schema = FloatSchema.parse(-1);
10
- * // => throws an error
11
+ * // => -1
11
12
  * const schema = FloatSchema.parse('1');
12
13
  * // => 1
14
+ * const schema = FloatSchema.parse("1.5");
15
+ * // => 1.5
16
+ * const schema = FloatSchema.parse("-1.5");
17
+ * // => -1.5
18
+ * const schema = FloatSchema.parse("-1.501");
19
+ * // => -1.501
13
20
  * ```
14
21
  */
15
22
  export declare const FloatSchema: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>;
@@ -2,15 +2,22 @@
2
2
  import { z } from 'zod';
3
3
  /**
4
4
  * A schema for floats.
5
- * It coerces the value to a number.
5
+ * It transforms the value to a number.
6
+ * @throws if the value cannot be coerced to a number.
6
7
  * @example
7
8
  * ```ts
8
9
  * const schema = FloatSchema.parse(1);
9
10
  * // => 1
10
11
  * const schema = FloatSchema.parse(-1);
11
- * // => throws an error
12
+ * // => -1
12
13
  * const schema = FloatSchema.parse('1');
13
14
  * // => 1
15
+ * const schema = FloatSchema.parse("1.5");
16
+ * // => 1.5
17
+ * const schema = FloatSchema.parse("-1.5");
18
+ * // => -1.5
19
+ * const schema = FloatSchema.parse("-1.501");
20
+ * // => -1.501
14
21
  * ```
15
22
  */
16
23
  export const FloatSchema = z
@@ -1,15 +1,25 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
- * A schema for integers.
4
- * It coerces the value to an integer.
3
+ * A schema for integers (positive or negative).
4
+ * It transforms the value to a number and
5
+ * rounds it to the nearest integer using `Math.round`.
6
+ * @throws if the value cannot be coerced to a number.
5
7
  * @example
6
8
  * ```ts
7
9
  * const schema = IntegerSchema.parse(1);
8
10
  * // => 1
9
11
  * const schema = IntegerSchema.parse(-1);
10
- * // => throws an error
12
+ * // => -1
11
13
  * const schema = IntegerSchema.parse('1');
12
14
  * // => 1
15
+ * const schema = IntegerSchema.parse(1.4);
16
+ * // => 1
17
+ * const schema = IntegerSchema.parse("1.5");
18
+ * // => 2
19
+ * const schema = IntegerSchema.parse("-1.5");
20
+ * // => -1
21
+ * const schema = IntegerSchema.parse("-1.501");
22
+ * // => -2
13
23
  * ```
14
24
  */
15
25
  export declare const IntegerSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -1,19 +1,29 @@
1
1
  /* * */
2
2
  import { z } from 'zod';
3
3
  /**
4
- * A schema for integers.
5
- * It coerces the value to an integer.
4
+ * A schema for integers (positive or negative).
5
+ * It transforms the value to a number and
6
+ * rounds it to the nearest integer using `Math.round`.
7
+ * @throws if the value cannot be coerced to a number.
6
8
  * @example
7
9
  * ```ts
8
10
  * const schema = IntegerSchema.parse(1);
9
11
  * // => 1
10
12
  * const schema = IntegerSchema.parse(-1);
11
- * // => throws an error
13
+ * // => -1
12
14
  * const schema = IntegerSchema.parse('1');
13
15
  * // => 1
16
+ * const schema = IntegerSchema.parse(1.4);
17
+ * // => 1
18
+ * const schema = IntegerSchema.parse("1.5");
19
+ * // => 2
20
+ * const schema = IntegerSchema.parse("-1.5");
21
+ * // => -1
22
+ * const schema = IntegerSchema.parse("-1.501");
23
+ * // => -2
14
24
  * ```
15
25
  */
16
26
  export const IntegerSchema = z
17
27
  .union([z.string(), z.number()])
18
- .transform(value => Number(value))
28
+ .transform(value => Math.round(Number(value)))
19
29
  .pipe(z.number().int());
@@ -1,7 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
3
  * A schema for non-negative floats.
4
- * It coerces the value to a number and ensures it is non-negative.
4
+ * It transforms the value to a number and ensures it is non-negative.
5
+ * @throws if the value is negative or if it cannot be coerced to a number.
5
6
  * @example
6
7
  * ```ts
7
8
  * const schema = NonNegativeFloatSchema.parse(1);
@@ -12,6 +13,12 @@ import { z } from 'zod';
12
13
  * // => 1
13
14
  * const schema = NonNegativeFloatSchema.parse(0);
14
15
  * // => 0
16
+ * const schema = NonNegativeFloatSchema.parse(1.5);
17
+ * // => 1.5
18
+ * const schema = NonNegativeFloatSchema.parse("1.567");
19
+ * // => 1.567
20
+ * const schema = NonNegativeFloatSchema.parse("-1.5");
21
+ * // => throws an error
15
22
  * ```
16
23
  */
17
24
  export declare const NonNegativeFloatSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -2,7 +2,8 @@
2
2
  import { z } from 'zod';
3
3
  /**
4
4
  * A schema for non-negative floats.
5
- * It coerces the value to a number and ensures it is non-negative.
5
+ * It transforms the value to a number and ensures it is non-negative.
6
+ * @throws if the value is negative or if it cannot be coerced to a number.
6
7
  * @example
7
8
  * ```ts
8
9
  * const schema = NonNegativeFloatSchema.parse(1);
@@ -13,6 +14,12 @@ import { z } from 'zod';
13
14
  * // => 1
14
15
  * const schema = NonNegativeFloatSchema.parse(0);
15
16
  * // => 0
17
+ * const schema = NonNegativeFloatSchema.parse(1.5);
18
+ * // => 1.5
19
+ * const schema = NonNegativeFloatSchema.parse("1.567");
20
+ * // => 1.567
21
+ * const schema = NonNegativeFloatSchema.parse("-1.5");
22
+ * // => throws an error
16
23
  * ```
17
24
  */
18
25
  export const NonNegativeFloatSchema = z
@@ -1,7 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
3
  * A schema for non-negative integers.
4
- * It coerces the value to an integer and ensures it is non-negative.
4
+ * It transforms the value to a number, rounds it
5
+ * to the nearest integer, and ensures it is non-negative.
6
+ * @throws if the value is negative or if it cannot be coerced to a number.
5
7
  * @example
6
8
  * ```ts
7
9
  * const schema = NonNegativeIntegerSchema.parse(1);
@@ -12,6 +14,10 @@ import { z } from 'zod';
12
14
  * // => 1
13
15
  * const schema = NonNegativeIntegerSchema.parse(0);
14
16
  * // => 0
17
+ * const schema = NonNegativeIntegerSchema.parse(1.4);
18
+ * // => 1
19
+ * const schema = NonNegativeIntegerSchema.parse("1.567");
20
+ * // => 2
15
21
  * ```
16
22
  */
17
23
  export declare const NonNegativeIntegerSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -2,7 +2,9 @@
2
2
  import { z } from 'zod';
3
3
  /**
4
4
  * A schema for non-negative integers.
5
- * It coerces the value to an integer and ensures it is non-negative.
5
+ * It transforms the value to a number, rounds it
6
+ * to the nearest integer, and ensures it is non-negative.
7
+ * @throws if the value is negative or if it cannot be coerced to a number.
6
8
  * @example
7
9
  * ```ts
8
10
  * const schema = NonNegativeIntegerSchema.parse(1);
@@ -13,9 +15,13 @@ import { z } from 'zod';
13
15
  * // => 1
14
16
  * const schema = NonNegativeIntegerSchema.parse(0);
15
17
  * // => 0
18
+ * const schema = NonNegativeIntegerSchema.parse(1.4);
19
+ * // => 1
20
+ * const schema = NonNegativeIntegerSchema.parse("1.567");
21
+ * // => 2
16
22
  * ```
17
23
  */
18
24
  export const NonNegativeIntegerSchema = z
19
25
  .union([z.string(), z.number()])
20
- .transform(value => Number(value))
26
+ .transform(value => Math.round(Number(value)))
21
27
  .pipe(z.number().int().nonnegative());
@@ -1,19 +1,21 @@
1
1
  import { z } from 'zod';
2
2
  /**
3
3
  * A schema for percentages in the range 0-100,
4
- * It coerces the value to an integer.
4
+ * It transforms the value to a number, rounds it
5
+ * to the nearest integer, and ensures it is in the range 0-100.
6
+ * @throws if the value cannot be coerced to a number or if it is not in the range 0-100.
5
7
  * @example
6
8
  * ```ts
7
9
  * const schema = PercentSchema.parse(50);
8
10
  * // => 50
9
- * const schema = PercentSchema.parse('50');
10
- * // => 50
11
- * const schema = PercentSchema.parse(50.1);
12
- * // => 50
11
+ * const schema = PercentSchema.parse("75");
12
+ * // => 75
13
13
  * const schema = PercentSchema.parse(101);
14
14
  * // => throws an error
15
15
  * const schema = PercentSchema.parse(-1);
16
16
  * // => throws an error
17
+ * const schema = PercentSchema.parse("50.1");
18
+ * // => 50
17
19
  * ```
18
20
  */
19
21
  export declare const PercentSchema: z.ZodPipeline<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, number, string | number>, z.ZodNumber>;
@@ -2,22 +2,24 @@
2
2
  import { z } from 'zod';
3
3
  /**
4
4
  * A schema for percentages in the range 0-100,
5
- * It coerces the value to an integer.
5
+ * It transforms the value to a number, rounds it
6
+ * to the nearest integer, and ensures it is in the range 0-100.
7
+ * @throws if the value cannot be coerced to a number or if it is not in the range 0-100.
6
8
  * @example
7
9
  * ```ts
8
10
  * const schema = PercentSchema.parse(50);
9
11
  * // => 50
10
- * const schema = PercentSchema.parse('50');
11
- * // => 50
12
- * const schema = PercentSchema.parse(50.1);
13
- * // => 50
12
+ * const schema = PercentSchema.parse("75");
13
+ * // => 75
14
14
  * const schema = PercentSchema.parse(101);
15
15
  * // => throws an error
16
16
  * const schema = PercentSchema.parse(-1);
17
17
  * // => throws an error
18
+ * const schema = PercentSchema.parse("50.1");
19
+ * // => 50
18
20
  * ```
19
21
  */
20
22
  export const PercentSchema = z
21
23
  .union([z.string(), z.number()])
22
- .transform(value => Number(value))
24
+ .transform(value => Math.round(Number(value)))
23
25
  .pipe(z.number().int().min(0).max(100));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-types-shared",
3
- "version": "20260829.1045.9",
3
+ "version": "20260829.1122.26",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"