Words To Numbers
Convert words to numbers. Optionally fuzzy match the words to numbers.
npm install words-to-numbers
If the whole string passed is a number then it will return a Number
type otherwise it will return the original string with all instances of numbers replaced.
TODO: Add functionality for parsing mixed numbers and words. PRs welcome.
Examples
import wordsToNumbers from 'words-to-numbers';
wordsToNumbers('one hundred');
wordsToNumbers('one hundred and five');
wordsToNumbers('one hundred and twenty five');
wordsToNumbers('four thousand and thirty');
wordsToNumbers('six million five thousand and two');
wordsToNumbers('a thousand one hundred and eleven');
wordsToNumbers('twenty thousand five hundred and sixty nine');
wordsToNumbers('five quintillion');
wordsToNumbers('one-hundred');
wordsToNumbers('one-hundred and five');
wordsToNumbers('one-hundred and twenty-five');
wordsToNumbers('four-thousand and thirty');
wordsToNumbers('six-million five-thousand and two');
wordsToNumbers('a thousand, one-hundred and eleven');
wordsToNumbers('twenty-thousand, five-hundred and sixty-nine');
wordsToNumbers('there were twenty-thousand, five-hundred and sixty-nine X in the five quintillion Y'))
With Fuzzy Matching
import wordsToNumbers from 'words-to-numbers';
wordsToNumbers('won huntred', {fuzzy: true});
wordsToNumbers('too thousant and fiev', {fuzzy: true});
wordsToNumbers('tree millyon sefen hunderd and twinty sex', {fuzzy: true});
Commonjs
const { wordsToNumbers } = require('words-to-numbers');
wordsToNumbers('one hundred');