Skip to content

Commit 9c589b0

Browse files
committedJan 12, 2021
fix custom types example, closes ianstormtaylor#598
1 parent 8b9639e commit 9c589b0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
 

‎examples/custom-types.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { object, string, optional, struct, assert } from 'superstruct'
1+
import { object, string, optional, define, assert } from 'superstruct'
22
import isEmail from 'is-email'
33
import isUuid from 'is-uuid'
44
import isUrl from 'is-url'
55

66
// Define custom structs with validation functions.
7-
const Uuid = struct('Uuid', isUuid.v4)
7+
const Uuid = define('Uuid', isUuid.v4)
88

9-
const Url = struct('Url', (value) => {
9+
const Url = define('Url', (value) => {
1010
return isUrl(value) && value.length < 2048
1111
})
1212

13-
const Email = struct('Email', (value, context) => {
13+
const Email = define('Email', (value) => {
1414
if (!isEmail(value)) {
15-
return [context.fail({ code: 'not_email' })]
15+
return { code: 'not_email' }
1616
} else if (value.length >= 256) {
17-
return [context.fail({ code: 'too_long' })]
17+
return { code: 'too_long' }
1818
} else {
19-
return []
19+
return true
2020
}
2121
})
2222

‎examples/testing-values.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { object, number, string, validate } from 'superstruct'
1+
import { object, number, string, is } from 'superstruct'
22

33
// Define a struct to validate with.
44
const User = object({

0 commit comments

Comments
 (0)