react-schema
Version:
Use react like PropTypes for generic object validation.
38 lines (34 loc) • 982 B
JavaScript
;
/**
* Decorates a **CHAINABLE** type checker's output to include the argument it
* was instantiated with. For example:
*
* shape({ something: string })
* ^^^^^^^^^^^^^^^^^^^^^
*
* oneOf([ 'foo', 'bar' ])
* ^^^^^^^^^^^^^^^^
*
* The decorated checker will contain this information in a $meta property:
*
* {
* type: String,
* args: Any
* }
*
* @param {String} type
* @param {Function} sourceChecker
*/
module.exports = function createIntrospectableChecker(type, sourceChecker) {
return function applyCheckerAndAddTypeInfo(args) {
var checker = sourceChecker(args);
var $meta = { type: type, args: args };
if (!(checker instanceof Function)) {
throw new Error('You may only decorate chainable, non-primitive type checkers!');
}
checker.$meta = $meta;
checker.isRequired.$meta = $meta;
return checker;
};
};
//# sourceMappingURL=createIntrospectableChecker.js.map