-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 996 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
37
38
39
40
41
42
43
44
45
46
'use strict'
let ow, propType
function devPropType (predicateOrCallback) {
return typeof predicateOrCallback === 'function'
? (props, propName, ...args) => {
const predicate = predicateOrCallback(props, propName, ...args)
const value = props[propName]
try {
ow(value, predicate)
} catch (err) {
return err
}
}
: (props, propName) => {
const value = props[propName]
try {
ow(value, predicateOrCallback)
} catch (err) {
return err
}
}
}
function productionPropType () {}
// copy+paste ow/dev-only.js because it does not seem to be published
if (process.env.NODE_ENV === 'production') {
const shim = new Proxy(() => {}, {
get: () => shim,
apply: () => shim
})
ow = shim
propType = productionPropType
} else {
ow = require('ow')
propType = devPropType
}
// exporting ow since it might be the shim
propType.ow = ow
propType.propType = propType
module.exports = propType