-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Open
Copy link
Labels
Description
Describe the feature
Basic regex support and built-in string functions should be relatively easy to integrate into validate, parsing and serialization function.
Using the email validation example from your video, adding regex support would only require one additional line:
const $$User = {
validate(input: unknown): input is User {
return (
typeof input === 'object' &&
input !== null &&
'id' in input &&
typeof input.id === 'string' &&
'name' in input &&
typeof input.name === 'string' &&
'email' in input &&
typeof input.email === 'string' &&
// add regex test
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(input.email)
);
},
parse,
serialize,
};I haven’t gone through the entire ts-schema/src/compiler/, but it seems feasible to do so. Maybe some refactoring on a.string() (or just setter proxy for a.object?) and add some templates for regex and built-in string functions.
Additional context
Would you be willing to implement this feature?
Yes, but I may need some time to familiarize myself with the codebase.