Skip to content

Commit

Permalink
Added import using wildcard to docs (#391)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
  • Loading branch information
thesunny and ianstormtaylor authored Jun 20, 2020
1 parent 9870956 commit 4cdb8ad
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ And then you can import it into your code base:
import { assert } from 'superstruct'
```

Superstruct has many importable methods. To reduce the friction of importing many methods you can use a wildcard. The methods are then accessed from one object.

```ts
import * as s from 'superstruct'

const User = s.object({
id: s.number(),
name: s.string(),
})
```

If you would rather import Superstruct with a `<script>` tag, you can use the bundled build:

```html
Expand Down Expand Up @@ -190,7 +201,7 @@ To define custom data types, we can use the [`struct`](https://superstructjs.org
import { struct } from 'superstruct'
import isEmail from 'is-email'

const Email = struct('Email', value => isEmail(value))
const Email = struct('Email', (value) => isEmail(value))
```

Now we can define structs know about the `'email'` type:
Expand Down Expand Up @@ -355,7 +366,7 @@ For example, maybe you want to ensure that any string is trimmed before passing
```ts
import { coercion } from 'superstruct'

const TrimmedString = coercion(string, value => {
const TrimmedString = coercion(string, (value) => {
return typeof value === 'string' ? value.trim() : value
})
```
Expand Down

0 comments on commit 4cdb8ad

Please sign in to comment.