Skip to content

Commit

Permalink
Prettier appeasement
Browse files Browse the repository at this point in the history
  • Loading branch information
unleashy committed Oct 6, 2020
1 parent fc1a9ef commit a2b7d96
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ tree-shakeable and fully typed.

## Usage

First, you’ll want to create a *validator* by using the `schema` function:
First, you’ll want to create a _validator_ by using the `schema` function:

```ts
import { schema, and, required, length, matches, email, minLength } from 'vahv';
import { schema, and, required, length, matches, email, minLength } from "vahv";

const validator = schema(
{
Expand All @@ -19,7 +19,8 @@ const validator = schema(
{
username: {
required: "Enter an username",
length: (_, min, max) => `Username must be between ${min} and ${max} characters`,
length: (_, min, max) =>
`Username must be between ${min} and ${max} characters`,
matches: "Username must be in the correct format"
},
email: {
Expand All @@ -28,7 +29,8 @@ const validator = schema(
},
password: {
required: "Enter a password",
minLength: (_, length) => `Password must have at least ${length} characters`
minLength: (_, length) =>
`Password must have at least ${length} characters`
}
}
);
Expand All @@ -48,8 +50,12 @@ validator({ username: "ab", email: "[email protected]", password: "short" });
// => { username: "Username must be between 3 and 32 characters",
// password: "Password must have at least 8 characters" }

validator({ username: "spa ces", email: "[email protected]", password: "longenoughsurely" });
// => {}
validator({
username: "spa ces",
email: "[email protected]",
password: "longenoughsurely"
});
// => {}
```

When a key has been successfully validated, it doesn’t exist in the errors
Expand All @@ -59,7 +65,7 @@ Each key in a schema has one validator. A validator is a function that takes in
a string, and returns a `ValidatorResult`, which can either be a success, with
the `ok` function or a failure with the `err` function. Many validators—like
Vahv’s built-in `length` validator—take arguments; they just return a validator
bound to those arguments.
bound to those arguments.

### Composing

Expand All @@ -79,7 +85,7 @@ do this:
export const username = and(length(3, 32), matches(/^[A-Z0-9_-]$/i));

// ... wherever else ...
import { username } from 'custom-validators.ts';
import { username } from 'custom-validators.ts';

...

Expand Down

0 comments on commit a2b7d96

Please sign in to comment.