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

write-int

v0.0.2

Published

Convert integer numbers to their written form.

Downloads

49

Readme

write-int

npm version

Convert integer numbers to their written form.

Inspired by js-written-number

Usage

Install with npm

npm install --save write-int

And require it where needed:

var writeInt = require('write-int');

Reference as script

It also works to simply reference in a script tag:

<script src="path/to/writeInt.min.js"></script>

English

English is the default language. Numbers supported between -1e66 and 1e66 exclusive (1 followed by 66 zeros or 1 * 10^66).

writeInt(123);// => 'one hundred and twenty-three'

writeInt(123, {lang: 'en'});// => 'one hundred and twenty-three'

Spanish

Numbers supported between -1e24 and 1e24 (exclusive).

writeInt(2030, {lang: 'es'});// => 'dos mil treinta'

German

Numbers supported between -1e18 and 1e18 (exclusive).

writeInt(2000, {lang: 'de'});// => 'zweitausend'

Esperanto

Numbers supported from 0 up through 1e15 - 1.

writeInt(1234, {lang: 'eo'});// => 'mil ducent tridek kvar'

Lojban

Numbers supported between -1.8e308 and 1.8e308 (exclusive).

writeInt(11, {lang: 'jb'});// => 'papa'

Specification

writeInt(number[, options])

  • @param {number|string} number
  • @param {object} [options]
  • @property {string} [options.lang='en']
  • @property {boolean} [options.einhundert=false]
    • whether to include 'ein' for 100 in German
    • 100 is 'einhundert' if true, 'hundert' if false
  • @property {boolean} [options.eintausend=false]
    • whether to include 'ein' for 1000 in German
    • 1000 is 'eintausend' if true, 'tausend' if false
  • @returns {string|null}

Returns number written out if it is representable (within supported range of valid language), else returns null. If number is type string, it should be a base 10 number.

Example:

writeInt(11);// => 'eleven'
writeInt("11");// => 'eleven'

writeInt(1e2);// => 'one hundred'
writeInt("1e2");// => 'one hundred'

writeInt(11, {lang: 'es'});// => 'once'

writeInt(100, {lang: 'de'});// => 'hundert'
writeInt(100, {lang: 'de', einhundert: true});// => 'einhundert'

writeInt();// => null
writeInt({});// => null
writeInt("a");// => null
writeInt('foo');// => null

writeInt.supported(lang)

  • @param {string} lang
  • @returns {boolean}

Returns whether lang is a supported language.

Example:

writeInt.supported('en');// => true

writeInt.supported('xy');// => false

writeInt.representable(number, lang)

  • @param {number|string} number
  • @param {string} lang
  • @returns {boolean}

Returns whether number is representable (within the supported range) in lang. Returns false if lang is not supported. If writeInt() is called for an unrepresentable number, then null is returned.

Example:

writeInt.representable(12, 'en');// => true

writeInt.representable(12, 'xy');// => false

writeInt.representable('a', 'en');// => false

Supported languages

  • English lang: 'en'
  • Spanish lang: 'es'
  • German lang: 'de'
  • Esperanto lang: 'eo'
  • Lojban lang: 'jb'

Contributing

  1. Fork the repo
  2. Make a new branch
  3. Make the changes
  4. Run npm run build to build to dist/writeInt.js and dist/writeInt.min.js
  5. Run npm run test to check that all tests pass
  6. Submit a pull request
  7. Thanks!

Adding a language

  1. Create a copy of src/languages/interface.js and rename it to the ISO 639-1 code of the language.
  2. Implement the functions and properties for the language. Any helper functions and properties can be made as well.
  3. Create a test file in test with the same file name.

Note: Lojban does not have a ISO 639-1 code. "jb", which is unspecified in ISO 639-1, is used for Lojban. (The Lojban code in ISO 639-2 and ISO 639-3 is "jbo").