n2words
Version:
n2words converts a numerical number into a written one, supports 28 languages and has zero dependencies.
95 lines (72 loc) • 2.53 kB
Markdown
# n2words
[](https://github.com/forzagreen/n2words/actions)
[](https://coveralls.io/github/forzagreen/n2words?branch=master)
[](https://npmjs.com/package/n2words)
[](https://npmjs.com/package/n2words)
[](https://www.jsdelivr.com/package/npm/n2words)
__n2words__ converts numerical numbers into written ones, supports [28 languages](https://github.com/forzagreen/n2words#supported-languages), and has zero dependencies.
## Example
```js
n2words(123) // 'one hundred and twenty-three'
n2words(-1.5) // 'minus one point five'
n2words(123, {lang: 'fr'}) // 'cent vingt-trois'
n2words(123, {lang: 'es'}) // 'ciento veintitrés'
n2words(123, {lang: 'ar'}) // 'مائة وثلاثة وعشرون'
```
See the [Wiki](https://github.com/forzagreen/n2words/wiki) for examples and advanced usage like [importing only specific languages](https://github.com/forzagreen/n2words/wiki/Importing-only-specific-languages).
## Install
```sh
npm install n2words
```
## Usage
### ESM
```js
import n2words from 'n2words'
```
### CommonJS ([dynamic import](https://nodejs.org/api/esm.html#import-expressions))
```js
import('n2words').then(({default: n2words}) => {
n2words(100)
})
```
### Browser
```html
<script src="./n2words.js"></script>
<script>
n2words(100)
</script>
```
n2words is also available on [jsDelivr](https://www.jsdelivr.com/package/npm/n2words).
## Supported Languages
- `en` (English, default)
- `ar` (Arabic)
- `az` (Azerbaijani)
- `cz` (Czech)
- `dk` (Danish)
- `de` (German)
- `es` (Spanish)
- `fr` (French)
- `fr-BE` (French (Belgium))
- `fa` (Farsi)
- `he` (Hebrew)
- `hr` (Croatian)
- `hu` (Hungarian)
- `id` (Indonesian)
- `it` (Italian)
- `ko` (Korean)
- `lt` (Lithuanian)
- `lv` (Latvian)
- `nl` (Dutch)
- `no` (Norwegian)
- `pl` (Polish)
- `pt` (Portuguese)
- `ru` (Russian)
- `sr` (Serbian)
- `tr` (Turkish)
- `uk` (Ukrainian)
- `vi` (Vietnamese)
- `zh` (Chinese)
## Contributing
__This library is in active development.__ We want to improve the design and process for language contributors and add more languages. Bug reports and feature requests are also beneficial!
## License
[MIT](https://github.com/forzagreen/n2words/blob/master/LICENSE)