Skip to content

Latest commit

 

History

History
77 lines (71 loc) · 2.73 KB

data-guard.md

File metadata and controls

77 lines (71 loc) · 2.73 KB

Data Guard

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.