fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6k stars 186 forks source link

[bug] Decimal schema is expecting null #665

Closed CestDiego closed 2 months ago

CestDiego commented 3 months ago

Decimal schema is broken on both pre-0.31 and 0.31 versions:

Repro steps in the playground:

import * as v from 'valibot';

const DecimalSchema = v.pipe(
  v.string(),
  v.decimal('The decimal is badly formatted.')
);

const result = v.safeParse(DecimalSchema, "8.0");

console.log(result.issues);
image

I would expect that 8.0 is a decimal. Am I holding this wrong?

CestDiego commented 3 months ago

Oh wait.. i just realized that "decimal" actually means it's just a base ten number. :')

What should I use if I want to make sure that my string '8.0' is indeed a number? and not only that but also a floating number?

fabian-hiller commented 3 months ago

Oh wait.. i just realized that "decimal" actually means it's just a base ten number. :')

👍

What should I use if I want to make sure that my string '8.0' is indeed a number? and not only that but also a floating number?

At the moment I recommend using regex or check, but if you have a great name I am happy to add a new action to validate if a string is a valid number.