npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

number-in-letters

v0.5.0

Published

Convert numbers to words - their written form.

Downloads

1,052

Readme

js-written-number

Gitter Build Status Code Climate Coverage Status Dependency Status devDependency Status Analytics npm downloads per month npm version


Convert numbers to words - their written form.

Install with npm

npm i --save number-in-letters

Install with bower

bower install number-in-letters

Usage

var writtenNumber = require('written-number');
writtenNumber(1234); // => 'one thousand two hundred and thirty-four'

Options

  • noAnd - Defaults to false. Determines whether to use a separator. The separator is internationalized.
  • lang - Could be string or object. Defaults to 'en'. Determines which language to use. An i18n configuration object may be passed to support external language definitions.

Internationalization

Currently supported languages are:

  • English lang = "en"
  • Portuguese lang = "pt"
  • Spanish lang = "es"
  • French lang = "fr"
  • Esperanto lang = "eo"
  • Vietnamese lang = "vi"
  • Belgium lang = "bl"

Spanish Example

var writtenNumber = require('written-number');
writtenNumber(1234, { lang: 'es' }); // => 'mil doscientos treinta y cuatro'
var writtenNumber = require('written-number');
writtennumber.defaults.lang = 'es';
writtenNumber(4758); // => 'cuatro mil setecientos cincuenta y ocho'

Portuguese Example

var writtenNumber = require('written-number');
writtenNumber(1234, { lang: 'pt' }); // => 'mil duzentos e trinta e quatro'

French Example

var writtenNumber = require('written-number');
writtenNumber(1234, { lang: 'fr' }); // => 'mille deux cent trente-quatre'

Esperanto Example

var writtenNumber = require('written-number');
writtenNumber(1234, { lang: 'eo' }); // => 'mil ducent tridek kvar'

Vietnamese Example

var writtenNumber = require('written-number');
writtenNumber(1234, { lang: 'vi' }); // => 'một ngàn hai trăm và ba mươi bốn'

Belgium Example

var writtenNumber = require('written-number');
writtenNumber(90, { lang: 'bl' }); // => 'nonante'

Options

Property | Value -------------- | ------------- noAnd | false lang | 'en'

Configure your own language

Each language has it's own unique grammar exceptions. You can create your own language.json file in the folder "i18n" and give writtenNumber support for it. I don't think the current scheme and logic cover all the cases, but may be cover some.

useLongScale:

'Boolean' that indicates if it use long or short scale. This differs the meaning of the words billion, trillion and so on.

baseSeparator:

'String' that separates the base cardinal numbers. Example: 29 -> twenty-eight. Spanish uses the conector " y ".

unitSeparator:

'String' that separates the units from the last base cardinal numbers. Example: 1234 -> one thousand two hundred and thirty-four

base:

Base cardinals numbers. Numbers that have unique names and are used to build others.

units:

Number units. It can be:

  • String

  • Object normal flow. Give support to singular and plural units. English does not need this, but spanish does.

{
  "singular": "millón",
  "plural": "millones"
}
  • Object with useBaseInstead exception. In some languages like spanish, specific units like "ciento", use the base cardinal number instead.

With useBaseException you can also specify with which unit (1 to 9) you don't want use the base cardinal instead and use the regular behaviour.

{
  "singular": "ciento",
  "useBaseInstead": true,
  "useBaseException": [1]
}
  • Object with avoidPrefixException exception.

In some languages like spanish, specific units like "mil" does not use the base cardinal number prefix for unit 1.

{
  "singular": "mil",
  "avoidPrefixException": [1]
}
  • Object with avoidInNumberPlural exception.

In some languages like french, specific units like "cent" does not use the plural form inside of numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".

{
  "singular": "cent",
  "plural": "cents",
  "avoidInNumberPlural": true
}
unitExceptions:

Sometimes grammar exceptions affect the base cardinal joined to the unit. You can set specific exceptions to any base cardinal number.

Spanish example:

Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil

English configuration example

{
  "useLongScale": false,
  "baseSeparator": "-",
  "unitSeparator": "and ",
  "base": {
    "0": "zero",
    "1": "one",
    "2": "two",
    "3": "three",
    ...
    "90": "ninety"
  },
  "units" : [
    "hundred",
    "thousand",
    "million",
    "billion",
    "trillion",
    ...
    "quindecillion"
  ],
  "unitExceptions": []
}

Spanish configuration example

{
  "useLongScale": true,
  "baseSeparator": " y ",
  "unitSeparator": "",
  "base": {
    "0": "cero",
    "1": "uno",
    "2": "dos",
    "3": "tres",
    ...
    "1000": "mil"
  },
  "unitExceptions": {
    "1": "un"
  },
  "units" : [
    {
      "singular": "ciento",
      "useBaseInstead": true,
      "useBaseException": [1]
    },
    {
      "singular": "mil",
      "avoidPrefixException": [1]
    },
    {
      "singular": "millón",
      "plural": "millones"
    },
    ...
  ]
}

Contributing

Do your changes and submit a PR. If you've write access and want to bump the version, run mversion [major|minor|patch] -m. That'll bump both bower.json and package.json.

License

This code is licensed under the MIT license for Pedro Tacla Yamada. For more information, please refer to the LICENSE file.