data_aspect-ratio-to-padding.js
/**
* @module aspectRatioToPadding
* @description Returns padding top percentage value when passed an aspect ratio string seperated by a colon,
* eg 4:3 returns 75.
*
* @since 1.3.1
*
* @param {string} ratio The ratio in form `w:h`.
*
* @return {number} Returns the percentage as number without any symbol.
*
* @example
* import { aspectRatioToPadding } from "@gravityforms/utils";
*
* function Example() {
* const div = document.createElement( 'div' );
* const ratio = '16:10';
* div.style.paddingTop = `${ aspectRatioToPadding( ratio ) }%`;
* }
*
*/
export default function aspectRatioToPadding( ratio = '' ) {
const ratioParts = ratio.split( ':' );
return parseFloat( ( ratioParts[ 1 ] / ratioParts[ 0 ] * 100 ).toFixed( 5 ) );
}