Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

words-to-numbers

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

words-to-numbers

convert textual words to numbers with optional fuzzy text matching

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.9K
decreased by-14.66%
Maintainers
1
Weekly downloads
 
Created
Source

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'); //100;
wordsToNumbers('one hundred and five'); //105;
wordsToNumbers('one hundred and twenty five'); //125;
wordsToNumbers('four thousand and thirty'); //4030;
wordsToNumbers('six million five thousand and two'); //6005002;
wordsToNumbers('a thousand one hundred and eleven'); //1111;
wordsToNumbers('twenty thousand five hundred and sixty nine'); //20569;
wordsToNumbers('five quintillion'); //5000000000000000000;
wordsToNumbers('one-hundred'); //100;
wordsToNumbers('one-hundred and five'); //105;
wordsToNumbers('one-hundred and twenty-five'); //125;
wordsToNumbers('four-thousand and thirty'); //4030;
wordsToNumbers('six-million five-thousand and two'); //6005002;
wordsToNumbers('a thousand, one-hundred and eleven'); //1111;
wordsToNumbers('twenty-thousand, five-hundred and sixty-nine'); //20569;
wordsToNumbers('there were twenty-thousand, five-hundred and sixty-nine X in the five quintillion Y')) // 'there were 20569 X in the 5000000000000000000 Y'

With Fuzzy Matching

import wordsToNumbers from 'words-to-numbers';
wordsToNumbers('won huntred', {fuzzy: true}); //100
wordsToNumbers('too thousant and fiev', {fuzzy: true}); //2005
wordsToNumbers('tree millyon sefen hunderd and twinty sex', {fuzzy: true}); //3000726

Commonjs

const { wordsToNumbers } = require('words-to-numbers');
wordsToNumbers('one hundred'); //100;

FAQs

Package last updated on 09 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc