src/utils/grid.js
function percentage(target, context) {
  if (target.slice(-1) === "%" || context.slice(-1) === "%") {
    throw new Error(`Cannot calculate percentage; one or more units appear to
      be %. Units must be rem or px.`);
  }

  if (target.slice(-1) !== context.slice(-1)) {
    throw new Error("Cannot calculate percentage; units do not appear to match.");
  }

  const unit = target.slice(-1) === "x" ? "px" : "rem";
  const numbers = _getNumbers([target, context], "static", unit);
  const result = numbers.reduce((a, b) => a / b) * 100;
  return _affixValue(result, "fluid");
}
function percentage(target, context) {
  if (target.slice(-1) === "%" || context.slice(-1) === "%") {
    throw new Error(`Cannot calculate percentage; one or more units appear to
      be %. Units must be rem or px.`);
  }

  if (target.slice(-1) !== context.slice(-1)) {
    throw new Error("Cannot calculate percentage; units do not appear to match.");
  }

  const unit = target.slice(-1) === "x" ? "px" : "rem";
  const numbers = _getNumbers([target, context], "static", unit);
  const result = numbers.reduce((a, b) => a / b) * 100;
  return _affixValue(result, "fluid");
}
function percentage ( target , context ) { if ( target . slice ( - 1 ) === "%" || context . slice ( - 1 ) === "%" ) { throw new Error ( ` ` ) ; } if ( target . slice ( - 1 ) !== context . slice ( - 1 ) ) { throw new Error ( "Cannot calculate percentage; units do not appear to match." ) ; } const unit = target . slice ( - 1 ) === "x" ? "px" : "rem" ; const numbers = _getNumbers ( [ target , context ] , "static" , unit ) ; const result = numbers . reduce ( ( a , b ) => a / b ) * 100 ; return _affixValue ( result , "fluid" ) ; }
Calculate a percent value from two static values
@todo   Add better regex matching to validate rem or px only
@param  {String} target  The width of the element that will be converted to a percent
@param  {String} context The width of the element's container
@return {String}         Converted value
@usage
percentage("12rem", "120rem");
Calculate a percent value from two static values