A data guard is a function that checks to see if the given input meets a given spec.
We use them in data guarantees, so that the data guarantees don't have to re-implement the same checks:
function isUuidData(input: string) {
return UuidRegex.test(input);
}
function mustBeUuidData(input: string, { onError = THROW_THE_ERROR}: OnErrorOptions) {
if (!isUuidData(input)) {
throw new InvalidUuidError({public: { input }});
}
}
Data guards are an important part of creating, and working with safe types.