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

full-numbers

v1.2.0

Published

A nice JS package to convert numbers to words.

Downloads

9

Readme

full-numbers

A nice JS package to convert numbers to words. :zero: :arrow_right: :abc:

:tada: Multilanguage and currency support :tada:

codecov Release

:closed_book: Usage

First things first - install the package using npm or yarn:

# using npm
npm i full-numbers

# using yarn
yarn add full-numbers

After that, import the helper wherever you want to use it:

// es-modules
import fullNumbers from 'full-numbers';

// commonjs
const fullNumbers = require('full-numbers');

Then, you'll be able to use it:

const words = fullNumbers(1234); // "one thousand, two hundred thirty-four"

// or

const words = fullNumbers({
  value: 1234,
  lang: 'pt-BR',
}); // "um mil, duzentos e trinta e quatro"

To use with currency support:

// "simple" values
const words = fullNumbers({
  value: 1234,
  lang: 'pt-BR',
  currency: {
    name: {
      singular: 'real',
      plural: 'reais'
    },
    decimals: {
      singular: 'centavo',
      plural: 'centavos'
    }
  }
}); // "um mil, duzentos e trinta e quatro reais"

// with decimals
const words = fullNumbers({
  value: 1234.5,
  lang: 'pt-BR',
  currency: {
    name: {
      singular: 'real',
      plural: 'reais'
    },
    decimals: {
      singular: 'centavo',
      plural: 'centavos'
    }
  }
}); // "um mil, duzentos e trinta e quatro reais e cinquenta centavos"

Avaliable Options

| Name | Type | Description | Example | | ------------------ | -------------- | ------------------- | ------------ | | value | number | The value | 123 | | lang | string | The output language | pt-BR | | currency | object | The output currency | See below |

The currency object should look like this:

{
  name: {
    singular: 'real',
    plural: 'reais'
  },
  decimals: {
    singular: 'centavo',
    plural: 'centavos'
  }
}

The singular/plural keys are important to avoid mismatch of grammar rules.

:computer: Developing

First, fork the project. After it, install the dependencies (preferably using npm - since the project is using it) and do the work.

Also, take a look at the contributing guide!

:books: Adding a new language

To add a new language, follow the steps below:

  • Create a new .json file within src/languages directory. The name of this file should be a valid language code (i.e. en, pt-BR...)
  • The file must have the following keys:
    • PUNCTUATION: an object of punctuations used between dozens, hundreds and decimals - if the language doesn't use them, leave the values blank;
    • LESS_THAN_TWENTY: an array of numbers' names between 0 and 19.
    • DOZENS: an array of dozens' names bewteen 0 and 90;
    • HUNDREDS: an object with the singular/plural names of hundreds between 100 and 900 - if the names are equal, leave the two keys with the same value;
    • SHORT_SCALE_NAME: an object with the short scale name from 100 (hundred) to 1000000000000000 (quadrillion).

You can follow the en.json file as an example to follow, and see the supported languages here.

:closed_lock_with_key: License

Licensed under the MIT.