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