You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdfy/lib/parse-amount.coffee

12 lines
281 B
CoffeeScript

9 years ago
errors = require "errors"
amountRegex = /^[0-9]+(?:\.[0-9]+)?$/
module.exports = (amount) ->
parsedAmount = parseFloat(amount)
if amountRegex.exec(amount) == null or isNaN(parsedAmount)
throw new errors.InvalidInput("The specified amount is invalid.")
return parsedAmount