Replies: 1 comment 2 replies
-
Both work. It makes no difference. To be consistent as a library, we choose to always use the function format. It is also more flexible, for example if you want to be able to overwrite the default error message. I would go with this: // Pipeline functions
const toPhone = () =>
toCustom((value: string) => formatIncompletePhoneNumber(value));
const phone = () =>
custom((value: string) => isValidPhoneNumber(value), 'Invalid phone number');
// Valibot schemas
const PhoneSchema = stringAsync([minLength(1, 'Enter phone number'), toPhone(), phone()]);
const ShippingAddressSchema = objectAsync({
shippingLastName: stringAsync([minLength(1, 'Enter last name')]),
shippingFirstName: stringAsync([minLength(1, 'Enter first name')]),
shippingPhone: PhoneSchema,
shippingAddressLevel4: stringAsync('Must be string'),
shippingAddressLevel2: stringAsync([minLength(1, 'Enter city')]),
shippingStreetAddress: stringAsync([minLength(1, 'Enter address')]),
shippingAddressLevel3: stringAsync([minLength(1, 'Enter state / province')]),
shippingPostalCode: stringAsync([
minLength(1, 'Enter postal code'),
regex(/\d+/, 'Postal code must be numeric'),
]),
}); Also, I recommend using the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just wonder which one is the correct way to use them. Should I wrap them in a function to use like
stringAsync()
vs
Beta Was this translation helpful? Give feedback.
All reactions