UNPKG

@danilandreev/material-docs

Version:

material-docs - react framework for easy creating documentation site in material design style.

41 lines (35 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = createChainableTypeChecker; /* * Author: Andrieiev Danil | danssg08@gmail.com | https://github.com/DanilAndreev * Copyright (C) 2020. */ //import {ReactPropTypeLocationNames} from "prop-types"; var ANONYMOUS = ""; /** * createChainableTypeChecker - function, designed to create chainable PropTypes validators. * @function * @param {function} validate * @return {object} * @throws Error */ function createChainableTypeChecker(validate) { function checkType(isRequired, props, propName, componentName, location) { componentName = componentName || ANONYMOUS; if (props[propName] == null) { // let locationName = ReactPropTypeLocationNames[location]; if (isRequired) { return new Error("Required ".concat(location, " \"").concat(propName, "\" was not specified in \"").concat(componentName, "\".")); } return null; } else { return validate(props, propName, componentName, location); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; }