UNPKG

1.09 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4exports.errMsg = errMsg;
5exports.createChainableTypeChecker = createChainableTypeChecker;
6
7function errMsg(props, propName, componentName, msgContinuation) {
8 return 'Invalid prop \'' + propName + '\' of value \'' + props[propName] + '\'' + (' supplied to \'' + componentName + '\'' + msgContinuation);
9}
10
11/**
12 * Create chain-able isRequired validator
13 *
14 * Largely copied directly from:
15 * https://github.com/facebook/react/blob/0.11-stable/src/core/ReactPropTypes.js#L94
16 */
17
18function createChainableTypeChecker(validate) {
19 function checkType(isRequired, props, propName, componentName) {
20 componentName = componentName || '<<anonymous>>';
21 if (props[propName] == null) {
22 if (isRequired) {
23 return new Error('Required prop \'' + propName + '\' was not specified in \'' + componentName + '\'.');
24 }
25 } else {
26 return validate(props, propName, componentName);
27 }
28 }
29
30 var chainedCheckType = checkType.bind(null, false);
31 chainedCheckType.isRequired = checkType.bind(null, true);
32
33 return chainedCheckType;
34}
\No newline at end of file