index.js
function parse(val) {
  if (typeof val === 'number' && !isNaN(val)) {
    return val;
  }

  if (typeof val !== 'string') {
    return null;
  }

  // Test if the string passed is valid
  var results = parseRegExp.exec(val);
  var floatValue;
  var unit = 'b';

  if (!results) {
    // Nothing could be extracted from the given string
    floatValue = parseInt(val, 10);
    unit = 'b'
  } else {
    // Retrieve the value and the unit
    floatValue = parseFloat(results[1]);
    unit = results[4].toLowerCase();
  }

  return Math.floor(map[unit] * floatValue);
}
function parse(val) {
  if (typeof val === 'number' && !isNaN(val)) {
    return val;
  }

  if (typeof val !== 'string') {
    return null;
  }

  // Test if the string passed is valid
  var results = parseRegExp.exec(val);
  var floatValue;
  var unit = 'b';

  if (!results) {
    // Nothing could be extracted from the given string
    floatValue = parseInt(val, 10);
    unit = 'b'
  } else {
    // Retrieve the value and the unit
    floatValue = parseFloat(results[1]);
    unit = results[4].toLowerCase();
  }

  return Math.floor(map[unit] * floatValue);
}
function parse ( val ) { if ( typeof val === 'number' && ! isNaN ( val ) ) { return val ; } if ( typeof val !== 'string' ) { return null ; } // Test if the string passed is valid var results = parseRegExp . exec ( val ) ; var floatValue ; var unit = 'b' ; if ( ! results ) { // Nothing could be extracted from the given string floatValue = parseInt ( val , 10 ) ; unit = 'b' } else { // Retrieve the value and the unit floatValue = parseFloat ( results [ 1 ] ) ; unit = results [ 4 ] . toLowerCase ( ) ; } return Math . floor ( map [ unit ] * floatValue ) ; }
Parse the string value into an integer in bytes.

If no unit is given, it is assumed the value is in bytes.

@param {number|string} val

@returns {number|null}
@public
Parse the string value into an integer in bytes .