# words-to-numbers

> convert textual words to numbers with optional fuzzy text matching

Latest version **1.5.1** (published 2018-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install words-to-numbers
pnpm add words-to-numbers
yarn add words-to-numbers
bun add words-to-numbers
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2018-07-05 |
| First published | 2016-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/words-to-numbers) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 60.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 247 |
| Author | Finn Fitzsimons |
| Maintainers | finnfiddle |

## Links

- npm: https://www.npmjs.com/package/words-to-numbers
- Repository: https://github.com/finnfiddle/words-to-numbers
- Issues: https://github.com/finnfiddle/words-to-numbers/issues
- npm.io page: https://npm.io/package/words-to-numbers

## Dependencies (3)

- [its-set](https://npm.io/package/its-set.md) ^1.1.5
- [clj-fuzzy](https://npm.io/package/clj-fuzzy.md) ^0.3.2
- [babel-runtime](https://npm.io/package/babel-runtime.md) 6.x.x

## Recent versions

- 1.5.1 (latest) — 2018-07-05
- 1.5.0 — 2018-07-05
- 1.4.1 — 2018-04-28
- 1.4.0 — 2018-04-28
- 1.3.2 — 2018-01-09
- 1.3.1 — 2017-08-20
- 1.3.0 — 2017-08-19
- 1.2.2 — 2017-08-19
- 1.2.1 — 2017-02-25
- 1.2.0 — 2017-02-25
- 1.1.3 — 2017-02-25
- 1.1.2 — 2016-08-09
- 1.1.1 — 2016-08-09
- 1.1.0 — 2016-08-09
- 1.0.0 — 2016-08-09

## README

# 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.

## Basic Examples

```javascript
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
```

## Multiple numbers in a string

Returns a string with all instances replaced.

```javascript
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

Uses [Jaro distance](http://yomguithereal.github.io/clj-fuzzy/javascript.html#jaro) to find the best match for the number words. Don't rely on this being completely accurate...

```javascript
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
```

## Decimal Points

```javascript
import wordsToNumbers from 'words-to-numbers';
wordsToNumbers('ten point five'); //10.5
wordsToNumbers('three point one four one five nine two six'); //3.1415926
```

## Ordinal Numbers

```javascript
import wordsToNumbers from 'words-to-numbers';
wordsToNumbers('first'); //1
wordsToNumbers('second'); //2
wordsToNumbers('third'); //3
wordsToNumbers('fourteenth'); //14
wordsToNumbers('twenty fifth'); //25
wordsToNumbers('thirty fourth'); //34
wordsToNumbers('forty seventh'); //47
wordsToNumbers('fifty third'); //53
wordsToNumbers('sixtieth'); //60
wordsToNumbers('seventy second'); //72
wordsToNumbers('eighty ninth'); //89
wordsToNumbers('ninety sixth'); //96
wordsToNumbers('one hundred and eighth'); //108
wordsToNumbers('one hundred and tenth'); //110
wordsToNumbers('one hundred and ninety ninth'); //199
```

## Commonjs

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

## Implied Hundreds

```javascript
wordsToNumbers('nineteen eighty four', { impliedHundreds: true }); //1984
wordsToNumbers('one thirty', { impliedHundreds: true }); //130
wordsToNumbers('six sixty two', { impliedHundreds: true }); //662
wordsToNumbers('ten twelve', { impliedHundreds: true }); //1012
wordsToNumbers('nineteen ten', { impliedHundreds: true }); //1910
wordsToNumbers('twenty ten', { impliedHundreds: true }); //2010
wordsToNumbers('twenty seventeen', { impliedHundreds: true }); //2017
wordsToNumbers('twenty twenty', { impliedHundreds: true }); //2020
wordsToNumbers('twenty twenty one', { impliedHundreds: true }); //2021
wordsToNumbers('fifty sixty three', { impliedHundreds: true }); //5063
wordsToNumbers('fifty sixty', { impliedHundreds: true }); //5060
wordsToNumbers('fifty sixty three thousand', { impliedHundreds: true }); //5063000
wordsToNumbers('one hundred thousand', { impliedHundreds: true }); //100000
```

---
_Source: https://npm.io/package/words-to-numbers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
