* Creates a schema that parses string numbers to integers.
()
| 55 | * Creates a schema that parses string numbers to integers. |
| 56 | */ |
| 57 | function makeIntegerType(): StandardSchemaV1<string | number, number> { |
| 58 | return { |
| 59 | "~standard": { |
| 60 | version: 1, |
| 61 | vendor: "test", |
| 62 | validate: (value) => { |
| 63 | const num = typeof value === "number" ? value : parseInt(String(value), 10); |
| 64 | if (isNaN(num)) { |
| 65 | return { |
| 66 | issues: [{ message: "Expected integer" }], |
| 67 | }; |
| 68 | } |
| 69 | return { value: num }; |
| 70 | }, |
| 71 | }, |
| 72 | }; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Creates a schema that always fails validation. |
no outgoing calls
no test coverage detected