UNPKG

751 BJavaScriptView Raw
1const isSet = obj => obj instanceof Set;
2
3function optionalSet(props, propName, componentName) {
4 const prop = props[propName];
5 const type = typeof prop;
6
7 if (prop != null && !isSet(prop)) {
8 return new Error(
9 `Invalid prop \`${propName}\` of type \`${type}\` supplied to \`${componentName}\`, expected \`Set\`.`
10 );
11 }
12}
13
14function requiredSet(props, propName, componentName) {
15 const prop = props[propName];
16 const type = typeof prop;
17
18 if (prop == null || !isSet(prop)) {
19 return new Error(
20 `Invalid prop \`${propName}\` of type \`${type}\` supplied to \`${componentName}\`, expected \`Set\`.`
21 );
22 }
23}
24
25optionalSet.isRequired = requiredSet;
26
27export default optionalSet;