UNPKG

@xo-union/tk-component-header-nav

Version:
22 lines (21 loc) 1.2 kB
import _Array$isArray from "@babel/runtime-corejs3/core-js/array/is-array"; import _Set from "@babel/runtime-corejs3/core-js/set"; import _JSON$stringify from "@babel/runtime-corejs3/core-js/json/stringify"; const isRequiredAndOneOfOrNull = expectedValues => { if (!_Array$isArray(expectedValues)) { return () => new Error(`Invalid argument supplied to oneOfOrNull, expected an instance of array.`); } return (props, propName, componentName) => { if (!(propName in props)) { return new Error(`Invalid prop \`${propName}\` supplied to \`${componentName}\`.` + ` \`${propName}\` must be defined. If you do not want to set ` + `\`${propName}\` it can be set to \`null\` to disable this warning.`); } const validValues = new _Set([...expectedValues, null]); const propValue = props[propName]; // eslint-disable-line react/destructuring-assignment if (!validValues.has(propValue)) { const valuesString = _JSON$stringify([...validValues]); return new Error(`Invalid prop \`${propName}\` of value \`${propValue}\` ` + `supplied to \`${componentName}\`, expected one of ${valuesString}.`); } return null; }; }; export default isRequiredAndOneOfOrNull;