# number-translator

> Translate numbers into words!

Latest version **2.0.1** (published 2022-02-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install number-translator
pnpm add number-translator
yarn add number-translator
bun add number-translator
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-02-09 |
| First published | 2020-07-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | wind-of |
| Maintainers | wind-of |
| Keywords | number, translator, number-translator |

## Links

- npm: https://www.npmjs.com/package/number-translator
- Repository: https://github.com/wind-of/number-translator
- Homepage: https://github.com/wind-of/number-translator#readme
- Issues: https://github.com/wind-of/number-translator/issues
- npm.io page: https://npm.io/package/number-translator

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-02-09
- 2.0.0 — 2022-02-09
- 1.4.8 — 2021-09-05
- 1.4.7 — 2021-09-05
- 1.4.6 — 2021-07-30
- 1.4.5 — 2021-07-30
- 1.4.4 — 2021-07-30
- 1.4.3 — 2020-09-01
- 1.4.2 — 2020-08-11
- 1.4.1 — 2020-08-07
- 1.4.0 — 2020-08-04
- 1.3.3 — 2020-08-04
- 1.3.2 — 2020-08-03
- 1.3.1 — 2020-08-03
- 1.3.0 — 2020-08-03
- … 13 more at https://npm.io/package/number-translator/versions

## README

# Number-translator

## How to use:
```javascript
    const { translateNumber } = require("number-translator");
    
    translateNumber(x)        // where x is number OR string of numbers.
    translateNumber(123)      // —> "сто двадцать три"
    translateNumber("123")    // —> "сто двадцать три"
    translateNumber(-1.23)    // —> "минус одна целая двадцать три сотых"
    translateNumber(2231.1)   // —> "две тысяча двести тридцать одна целая одна десятая"
```
## Breaking change in 2.0.0
`translateNumber` returns an object with two properties — `type` and `message`. This was done in order to distinguish if input was valid or not.
```javascript
    const { translateNumber } = require("number-translator");
    
    translateNumber(x)        // where x is number OR string of numbers.
    translateNumber(123)      // —> {message: "сто двадцать три", type: "valid"}
    translateNumber("123")    // —> {message: "сто двадцать три", type: "valid"}
    translateNumber(-1.23)    // —> {message: "минус одна целая двадцать три сотых", type: "valid"}
    translateNumber(2231.1)   // —> {message: "две тысяча двести тридцать одна целая одна десятая", type: "valid"}
    translateNumber("22.31.1")   // —> {message: /* EXTRA_SYMBOLS_ERROR */, type: "error"}
```

## Limits
#### Integer
Range: [-10<sup>306</sup> + 1, 10<sup>306</sup> - 1]

#### Non-integer
Range: [-10<sup>306</sup> + 10<sup>-305</sup>, 10<sup>306</sup> - 10<sup>-305</sup>]


## Errors
Every input passes the next tests in the same order before translating.
#### Not a number
Next values cause a return of [NOT_A_NUMBER]-error: empty value (nothing is passed), empty string (""), [], {}, null, NaN, undefined 
Also, if input is a string where the first symbol is not a number, function will return a [NOT_A_NUMBER]-error.

```javascript
translateNumber(); // —> "Passed value is not a number."
```

#### Not safe number
Then, if the passed value is a number (not a string of numbers) that is not from the range [-9007199254740991; 9007199254740991], it causes a return of the [NOT_SAFE_NUMBER]-error.

```javascript
translateNumber(13151521521513839838443821214); // —> "Passed number is not safe. Safe numbers are numbers in range [-9007199254740991; 9007199254740991]. You can pass the number wrapped in quotes to avoid this limitation."
```
#### Non-numeric symbols
Any character except of digits, "-" and "." causes a return of a [NON_NUMERIC_SYMBOLS]-error.

```javascript
translateNumber("21412f212412412"); // —> "There are non-numeric symbols in the passed string."
```
#### Extra symbols
If there are more than one of "-" or ".", then it returns an [EXTRA_SYMBOLS]-error.

```javascript
translateNumber("-2222222-222222"); // —> "Passed number is not a valid number."
```
#### Too big number
If the number is out of the limits, then it returns a [TOO_BIG_NUMBER]-error.

```javascript
translateNumber("1".repeat(307)); // —> "Passed number is not a valid number."
```
---
### Live demo: 
https://hstff.csb.app/

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