Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Created September 15, 2015 18:11
Show Gist options
  • Save dmcassel/c1103b2b1e9c0490fc84 to your computer and use it in GitHub Desktop.
Save dmcassel/c1103b2b1e9c0490fc84 to your computer and use it in GitHub Desktop.
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