Skip to content

Commit

Permalink
docs: added section on runtime validation definition while using stat…
Browse files Browse the repository at this point in the history
…ic Infer at compiletime
  • Loading branch information
mhweiner committed Jul 10, 2024
1 parent 7a9836b commit bdbd2e6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ npm i typura
- [Nested objects](#nested-objects)
- [Type API](#type-api)
- [Predicate API](#predicate-api)
- [Advanced Usage](#advanced-usage)
- [Contribution](#contribution)
- [Sponsorship](#get-better-observability-with-aeroview)

Expand Down Expand Up @@ -346,14 +347,35 @@ Options:

- `allowLocalhost` - allows localhost URLs, default is `false`

## Support, Feedback, and Contributions
# Advanced Usage

## Defining validation at runtime while using static `Infer` type at compile-time

You can use the `custom()` predicate to define a predicate at runtime, while still using the `Infer` type at compile-time. This is useful when you need to define a predicate based on user input or configuration.

```typescript
import {predicates as p, Infer} from 'typura';

const validator = p.custom((input: string) => {

const regEx = getRegExFromSomewhere();

return p.regex(regEx, 'invalid regex')(input);

});

type Input = Infer<typeof validator>; // string

```

# Support, Feedback, and Contributions

- Star this repo if you like it!
- Submit an [issue](https://github.com/mhweiner/jsout/issues) with your problem, feature request or bug report
- Issue a PR against `main` and request review. Make sure all tests pass and coverage is good.
- Write about `typura` in your blog, tweet about it, or share it with your friends!

## Sponsors
# Sponsors

<picture>
<source srcset="docs/aeroview-logo-lockup.svg" media="(prefers-color-scheme: dark)">
Expand Down

0 comments on commit bdbd2e6

Please sign in to comment.