Skip to content

Commit

Permalink
docs(readme): add todo notice for reshape and function validations (
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Mar 19, 2022
1 parent 6087677 commit d5f16f6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ schema.parse(new User('Sapphire')); // => User { name: 'Sapphire' }
schema.parse('oops' as any); // => throws ValidatorError
```

---

_**Function validation is not yet implemented and will be made available starting v2.1.0**_

#### Functions // TODO

You can define function schemas. This checks for whether or not an input is a function:
Expand All @@ -417,6 +421,8 @@ s.function([s.string, s.number], s.string); // (arg0: string, arg1: number) => s

> **Note**: ShapeShift will transform the given function into one with validation on arguments and output. You can access the `.raw` property of the function to get the unchecked function.
---

### BaseValidator: methods and properties

All schemas in ShapeShift contain certain methods.
Expand All @@ -434,6 +440,10 @@ const getLength = s.string.transform((value) => value.length);
getLength.parse('Hello There'); // => 11
```

---

_**Reshape is not yet implemented and will be made available starting v2.1.0**_

> :warning: `.transform`'s functions **must not throw**. If a validation error is desired to be thrown, `.reshape` instead.
`.reshape<R>((value: T) => Result<R, Error> | IConstraint): NopValidator<R>`: adds a constraint able to both validate and modify the input:
Expand All @@ -447,6 +457,8 @@ getLength.parse('Hello There'); // => 11

> :warning: `.reshape`'s functions **must not throw**. If a validation error is desired to be thrown, use `Result.err(error)` instead.
---

`.default(value: T | (() => T))`: transform `undefined` into the given value or the callback's returned value:

```typescript
Expand Down

0 comments on commit d5f16f6

Please sign in to comment.