@danilandreev/material-docs
Version:
material-docs - react framework for easy creating documentation site in material design style.
43 lines (34 loc) • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.langValidate = langValidate;
exports.default = void 0;
var _createChainableTypeChecker = _interopRequireDefault(require("../utils/createChainableTypeChecker"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* langValidate - type validator for Lang interface.
* @function
* @param {object} props
* @param {string} propName
* @param {string} componentName
* @returns Error
*/
function langValidate(prop, propName, componentName) {
if (typeof prop.name !== "string") return Error("Incorrect field 'name' type on prop ".concat(propName, " in component ").concat(componentName, ", expected \"string\", got \"").concat(_typeof(prop.name), "\""));
if (typeof prop.label !== "string") return Error("Incorrect field 'label' type on prop ".concat(propName, " in component ").concat(componentName, ", expected \"string\", got \"").concat(_typeof(prop.label), "\""));
if (!prop.locale && !prop.loadLang) return Error("You must specify one of this fields: locale or loadLang in prop ".concat(propName, " in component ").concat(componentName, "!"));
if (prop.locale && _typeof(prop.locale) !== "object") return Error("Incorrect field 'label' type on prop ".concat(propName, " in component ").concat(componentName, ", expected \"object\", got \"").concat(_typeof(prop.locale), "\""));
if (prop.loadLang && typeof prop.loadLang !== "function") return Error("Incorrect field 'loadLang' type on prop ".concat(propName, " in component ").concat(componentName, ", expected \"function(): object\", got \"").concat(_typeof(prop.loadLang), "\""));
}
function LangValidator(props, propName, componentName) {
var prop = props[propName];
if (!prop) return null;
return langValidate(prop, propName, componentName);
}
/**
* LangValidator - PropTypes validator for Lang interface.
*/
var _default = (0, _createChainableTypeChecker.default)(LangValidator);
exports.default = _default;