-
Notifications
You must be signed in to change notification settings - Fork 906
/
index.js
36 lines (28 loc) · 1021 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var mixed = require('./mixed')
, bool = require('./boolean')
, Ref = require('./util/reference')
, Lazy = require('./util/lazy');
var isSchema = schema => schema && !!schema.__isYupSchema__;
module.exports = {
mixed: mixed,
string: require('./string'),
number: require('./number'),
boolean: bool,
bool: bool,
date: require('./date'),
object: require('./object'),
array: require('./array'),
reach: require('./util/reach'),
ValidationError: require('./util/validation-error'),
ref: (key, options) => new Ref(key, options),
lazy: (fn) => new Lazy(fn),
isSchema,
addMethod(schemaType, name, fn) {
if ( !schemaType || !isSchema(schemaType.prototype))
throw new TypeError('You must provide a yup schema constructor function')
if ( typeof name !== 'string') throw new TypeError('A Method name must be provided')
if ( typeof fn !== 'function') throw new TypeError('Method function must be provided')
schemaType.prototype[name] = fn
}
}