src/simple-duration.js
/**
 * Parses a string using the Simple Duration Format and returns the number of seconds
 * corresponding to it.
 * @param {string} str The string to parse
 * @return {number} The number of seconds
 */
Parses a string using the Simple Duration Format and returns the number of seconds
corresponding to it.
@param {string} str The string to parse
@return {number} The number of seconds
Parses a string using the Simple Duration Format and returns the number of seconds corresponding to it . @param { string } str The string to parse @return { number } The number of seconds
function parse (str) {
  if (!_.isString(str)) {
    throw new Error('Must pass a string')
  }
  const match = str.match(whole)
  if (!match) {
    throw new Error(`${str} is not valid Simple Duration Format`)
  }
  const negative = match[1] === '-'
  const elements = match[2]
  const re = new RegExp(element.source, 'g')
  let nmatch
  let counter = 0
  while ((nmatch = re.exec(elements)) !== null) {
    const nbr = parseFloat(nmatch[1])
    const unit = nmatch[2]
    counter += nbr * timeUnits[unit].amount
  }
  return (negative ? -1 : 1) * counter
}
function parse ( str ) { if ( ! _ . isString ( str ) ) { throw new Error ( 'Must pass a string' ) } const match = str . match ( whole ) if ( ! match ) { throw new Error ( ` ${ str } ` ) } const negative = match [ 1 ] === '-' const elements = match [ 2 ] const re = new RegExp ( element . source , 'g' ) let nmatch let counter = 0 while ( ( nmatch = re . exec ( elements ) ) !== null ) { const nbr = parseFloat ( nmatch [ 1 ] ) const unit = nmatch [ 2 ] counter += nbr * timeUnits [ unit ] . amount } return ( negative ? - 1 : 1 ) * counter }
Parses a string using the Simple Duration Format and returns the number of seconds
 corresponding to it.
Parses a string using the Simple Duration Format and returns the number of seconds corresponding to it .