-
Notifications
You must be signed in to change notification settings - Fork 0
/
typable.cjs.js
1 lines (1 loc) · 1.67 KB
/
typable.cjs.js
1
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=e(require("prop-types"));const p=(e,a)=>{const p={};for(let t in e)p[t]=a(e[t]);return p},t=["any","array","bool","element","elementType","func","node","number","object","string","symbol"],r=["arrayOf","exact","instanceOf","objectOf","oneOf","oneOfType","shape"],s=(e,p=!1,t=null)=>e.name?p?a.default[e.name](t??e.params).isRequired:a.default[e.name](t??e.params):p?a.default[e].isRequired:a.default[e];function o(e,o){e.propTypes={},e.defaultProps={},e.types=o;for(let n in o){if("string"==typeof n.type&&!t.includes(n.type))throw new Error(`${n.type} is not a valid prop-type. See allowed types at https://github.com/facebook/prop-types`);if(o[n].type.name&&!r.includes(o[n].type.name))throw new Error(`${n.type} is not a valid prop-type. See allowed types at https://github.com/facebook/prop-types`);if(o[n].default,e.defaultProps[n]=o[n].default,"string"!=typeof o[n].type)switch(o[n].type.name){case"arrayOf":e.propTypes[n]=a.default.arrayOf(s(o[n].type.params));break;case"exact":{const t=p(o[n].type.params,(e=>s(e)));e.propTypes[n]=a.default.exact(t);break}case"instanceOf":e.propTypes[n]=a.default.instanceOf(o[n].type.params);break;case"objectOf":e.propTypes[n]=a.default.objectOf(s(o[n].type.params));break;case"oneOf":e.propTypes[n]=a.default.oneOf(o[n].type.params);break;case"oneOfType":{const p=o[n].type.params.map((e=>s(e)));e.propTypes[n]=a.default.oneOfType(p);break}case"shape":{const t=p(o[n].type.params,(e=>s(e)));e.propTypes[n]=a.default.shape(t);break}}else e.propTypes[n]=s(o[n].type,o[n].required)}}t.forEach((e=>{o[e]=e})),r.forEach((e=>{o[e]=a=>({name:e,params:a})})),module.exports=o;