background image
James DiGioia

my little web home

yuptypes

export const yuptypes = (schema) => {
  const propTypes = {};
  for (const key in schema.fields) {
    propTypes[key] = function checkYupSchema(
      props,
      propName,
      componentName,
      location,
      propFullName,
      secret
    ) {
      try {
        schema.validateSyncAt(key, props, { strict: true });
        return null;
      } catch (err) {
        return new Error(
          `Invalid ${location} `${propName}` supplied to ${componentName};${err.message.replace(
            key,
            ""
          )}`
        );
      }
    };
  }
  return propTypes;
};