Created
September 15, 2015 18:11
-
-
Save dmcassel/c1103b2b1e9c0490fc84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
// Export the "private" function with a public name | |
parseCurrency: dollarToObject | |
}; | |
// "Private" function local to the module | |
function dollarToObject(str) { | |
if (str && str.match(/^\s*\$/)) { | |
return { | |
"value": parseFloat(str.replace(/[$,]/g, "")), | |
"unit": "USD" | |
} | |
} else { | |
throw new Error("Can't parse '" + str + "'"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment