lib/pixrem.js
function toPx (value, decl, result) {
  value = (typeof value === 'string' && value.indexOf('calc(') !== -1) ? calc(value) : value;
  var parts = /^(\d*\.?\d+)([a-zA-Z%]*)$/.exec(value);
  if (parts !== null) {
    var number = parts[1];
    var unit   = parts[2];

    if (unit === 'px' || unit === '') {
      return parseFloat(number);
    }
    else if (unit === 'em' || unit === 'rem') {
      return parseFloat(number) * BASE_FONT_SIZE;
    }
    else if (unit === '%') {
      return (parseFloat(number) / 100) * BASE_FONT_SIZE;
    } else {
      // other units: vw, ex, ch, etc...
      result.warn('Unit cannot be used for conversion, so 16px is used.');
      return BASE_FONT_SIZE;
    }
  } else {
    throw decl.error('Root font-size is invalid', {plugin: 'pixrem'});
  }
}
function toPx (value, decl, result) {
  value = (typeof value === 'string' && value.indexOf('calc(') !== -1) ? calc(value) : value;
  var parts = /^(\d*\.?\d+)([a-zA-Z%]*)$/.exec(value);
  if (parts !== null) {
    var number = parts[1];
    var unit   = parts[2];

    if (unit === 'px' || unit === '') {
      return parseFloat(number);
    }
    else if (unit === 'em' || unit === 'rem') {
      return parseFloat(number) * BASE_FONT_SIZE;
    }
    else if (unit === '%') {
      return (parseFloat(number) / 100) * BASE_FONT_SIZE;
    } else {
      // other units: vw, ex, ch, etc...
      result.warn('Unit cannot be used for conversion, so 16px is used.');
      return BASE_FONT_SIZE;
    }
  } else {
    throw decl.error('Root font-size is invalid', {plugin: 'pixrem'});
  }
}
function toPx ( value , decl , result ) { value = ( typeof value === 'string' && value . indexOf ( 'calc(' ) !== - 1 ) ? calc ( value ) : value ; var parts = / ^(\d*\.?\d+)([a-zA-Z%]*)$ / . exec ( value ) ; if ( parts !== null ) { var number = parts [ 1 ] ; var unit = parts [ 2 ] ; if ( unit === 'px' || unit === '' ) { return parseFloat ( number ) ; } else if ( unit === 'em' || unit === 'rem' ) { return parseFloat ( number ) * BASE_FONT_SIZE ; } else if ( unit === '%' ) { return ( parseFloat ( number ) / 100 ) * BASE_FONT_SIZE ; } else { // other units: vw, ex, ch, etc... result . warn ( 'Unit cannot be used for conversion, so 16px is used.' ) ; return BASE_FONT_SIZE ; } } else { throw decl . error ( 'Root font-size is invalid' , { plugin : 'pixrem' } ) ; } }
Return a unitless pixel value from any root font-size value.
Return a unitless pixel value from any root font - size value .