WordToNumber lets you parse any string for all of its word-numbers into an array of their digit representations. Covers all possibilities up to millinillion
"five" => [ "5" ] "Four score and seven years ago..." => [ "4", "7" ]
WordToNumber in on npm, so its as simple as
npm install word-to-number-node
The main function you'll be using with WordToNumber is the parse function.
It takes a string, and will return an array of all the numbers it finds in their digit form, as a string
var WordToNumber = ;var w2n = ;w2n; // [ "15" ]w2n; // [ "69003" ]w2n; // [ "1", "2" ]
WordToNumber comes with US English by default, with several convenience functions to manipulate that data.
// return an array of the available languages// set the current language// return the data for the specified/current language// replace the specified language data with your ownNote: While it may possible to drop in and have themthe algorithm is tuned for US English and as such other languages would have to follow the same pattern to work correctly
WordToNumber allows you to set custom white/blacklists to validate against
// Takes a single, or array of regexes to test numbers against before parsing.// Only matching values will be included.// Blacklist takes precedence over Whitelist// Passing a falsey value will clear this list.// Takes a single, or array of regexes to test numbers against before parsing.// Matching values will be excluded.// Blacklist takes precedence over Whitelist// Passing a falsey value will clear this list.// takes a regex of allowed characters surrounding the word-number// this MUST include *at least* /a-z/i, so that you aren't matching words// like "attend", or "tone", that would otherwise match as 10, and 1
Optionally output scientific notation at the specified exponent level
// takes a number that signifies the exponent at which scientific notation starts