forzagreen / n2words

Convert numerical numbers to written numbers, in 25+ languages.
MIT License
87 stars 22 forks source link
convert-numbers language natural-language nlp

n2words

Test Coverage Status npm npm jsDelivr

n2words converts numerical numbers into written ones, supports 27 languages, and has zero dependencies.

Example

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 for examples and advanced usage like importing only specific languages.

Install

npm install n2words

Usage

ESM

import n2words from 'n2words'

CommonJS (dynamic import)

import('n2words').then(({default: n2words}) => {
    n2words(100)
})

Browser

<script src="https://github.com/forzagreen/n2words/raw/master/n2words.js"></script>
<script>
    n2words(100)
</script>

n2words is also available on jsDelivr.

Supported Languages

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