UNPKG

plotly-icons

Version:
57 lines (43 loc) 2.06 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports['default'] = forbidExtraProps; var _object = require('object.assign'); var _object2 = _interopRequireDefault(_object); var _has = require('has'); var _has2 = _interopRequireDefault(_has); var _isPlainObject = require('./helpers/isPlainObject'); var _isPlainObject2 = _interopRequireDefault(_isPlainObject); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var zeroWidthSpace = '\u200B'; var specialProperty = 'prop-types-exact: ' + zeroWidthSpace; var semaphore = {}; function brand(fn) { return (0, _object2['default'])(fn, _defineProperty({}, specialProperty, semaphore)); } function isBranded(value) { return value && value[specialProperty] === semaphore; } function forbidExtraProps(propTypes) { if (!(0, _isPlainObject2['default'])(propTypes)) { throw new TypeError('given propTypes must be an object'); } if ((0, _has2['default'])(propTypes, specialProperty) && !isBranded(propTypes[specialProperty])) { throw new TypeError('Against all odds, you created a propType for a prop that uses both the zero-width space and our custom string - which, sadly, conflicts with `prop-types-exact`'); } return (0, _object2['default'])({}, propTypes, _defineProperty({}, specialProperty, brand(function () { function forbidUnknownProps(props, _, componentName) { var unknownProps = Object.keys(props).filter(function (prop) { return !(0, _has2['default'])(propTypes, prop); }); if (unknownProps.length > 0) { return new TypeError(String(componentName) + ': unknown props found: ' + String(unknownProps.join(', '))); } return null; } return forbidUnknownProps; }()))); } module.exports = exports['default']; //# sourceMappingURL=index.js.map