english-words-to-numbers

Convert all words in a string into numbers. Unlike other packages, it can optionally return the entire revised string with Arabic numbers instead of words.

Usage no npm install needed!

<script type="module">
  import englishWordsToNumbers from 'https://cdn.skypack.dev/english-words-to-numbers';
</script>

README

English Words to Numbers Converter

This package converts numbers expressed in English words (which can be mixed with Arabic numerals) into Arabic-only numbers.

Convert entire string

const wtn = require('english-words-to-numbers');

wtn('It was somewhere about 3 million, maybe 4 million at most.'); // 'It was somewhere about 3000000, maybe 4000000 at most.'
wtn('six point six million dollars and five cents'); // '6600000 dollars and 5 cents'
wtn('the repairs came up at fourty five hundred point five dollars'); // 'the repairs came up at 4500.5 dollars'
wtn('the total is 2.7 grand', { enableExtras: true }); // 'the total is 2700'

Return an array of converted numbers only

This feature is in development and not available yet.

const { numbers } = require('english-words-to-numbers');
numbers('this will require sixty to ninety days'); // [60, 90]