/**
 * A regular expression describing the aspect ratio format expected by media
 * components and scripts in this library e.g '16:9'
 * @type {RegExp} aspect ratio regexp
 */
export const ASPECT_RATIO_FORMAT = /^(?:\d+\.\d+:1|[1-9]\d*:[1-9]\d*)$/;

/**
 * Validator to check aspect ratio passed to prop is in valid format
 * @param {String} props - All props passed to the component.
 * @param {*} propName - The name given to the prop in the component.
 * @param {*} componentName - The name of the component using the validator.
 * @returns {void}
 */
const aspectRatio = (props, propName, componentName) => {
  if (
    typeof props.aspectRatio !== 'undefined'
    && !ASPECT_RATIO_FORMAT.test(props.aspectRatio)
  ) {
    return new Error(
      `Invalid prop format ${propName} supplied to ${componentName}`
    );
  }
};

export default {
  aspectRatio,
};
