UNPKG

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