words-to-numbers | JS library to convert textual words | Runtime Evironment library
kandi X-RAY | words-to-numbers Summary
kandi X-RAY | words-to-numbers Summary
Convert words to numbers. Optionally fuzzy match the 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.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse text
words-to-numbers Key Features
words-to-numbers Examples and Code Snippets
Community Discussions
Trending Discussions on words-to-numbers
QUESTION
var T2W = require("numbers2words");
var translator = new T2W("EN_US");
const { wordsToNumbers } = require('words-to-numbers');
let numbr = wordsToNumbers(message.content.toLowerCase());
message.channel.send(translator.toWords(numbr + 1));
...ANSWER
Answered 2018-Jul-23 at 08:05You can use these two libraries to convert numbers into words vice-versa:
words-to-numbers: https://www.npmjs.com/package/words-to-numbers
numbers-to-words: https://www.npmjs.com/package/number-to-words
The links contain more information on how to use the libraries.
Harder/Longer methodYou can make your own function that takes in a number or a worded number and then returns both the number and the worded number. For that, you can (as far as I know) create a couple arrays e.g. ["one", "two", "three"]
, ["hundred", thousand", "million"]
and use RegEx.
I found a similar-asked-post on StackOverflow where you can view the code on how to code your own: Convert digits into words with JavaScript.
By the way, you will get a syntax error because you forgot a parentheses.
You wrote:
bot.on("message", async message) => {});
Should be:
bot.on("message", async (message) => {});
or bot.on("message, async message => {});
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install words-to-numbers
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page