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

spelljs

v1.0.0

Published

A simple JavaScript library which provides the pronunciation of long numbers. Read long number up to 303 digits (10^303)

Downloads

3

Readme

SpellJS

A simple JavaScript library which provides the pronunciation of long numbers. Read long number up to 303 digits (10^303).

Installation

// based on use case
	npm install spelljs
	bower install spelljs

Or you can just include spell.js file if you want.

Usage

There are 3 ways to use it:

1.  Using function call:
		 spell(124);  	//"one hundred twenty four"
		 spell("123");	//"one hundred twenty three"
2.  Using String Object method
		 "12312312321321313123123123123123".spell();   //"twelve nonillion  , three hundred twelve octillion  , three hundred twelve septillion  , three hundred twenty one sextillion  , three hundred twenty one quintillion  , three hundred thirteen quadrillion  , one hundred twenty three trillion  , one hundred twenty three billion  , one hundred twenty three million  , one hundred twenty three thousand  , one hundred twenty three"
3. Using Number Object method
		  123..spell();	//"one hundred twenty three"

Precaution when using spellJS

Be careful while working with numbers in JavaScript:

1.Numbers don't won't allow direct operation like:

	12.toString();  //wrong syntax
	12.spell();     // wrong syntax

This is because JavScript is ambiguous if it is a decimal number or a property (like 12.5 or 13.7 ) So way around numbers is as follow:

	12..toString();  
	12..spell(); 
	12.0.spell();
	(12).spell();

2.Be careful while using function call and Number Object method. By default JavaScript can only safely represent numbers between:

	 -(2^53 - 1) and 2^53 - 1

The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2^53 - 1).

	Number.MAX_SAFE_INTEGER   // 9007199254740991
	Math.pow(2, 53) - 1        // 9007199254740991

So using the spell method on very long numbers will cause trouble. A loss of precision occurs. i.e.

	console.log(21321312312321321312313123123)  //2.1321312312321322e+28
	// So a loss of precision occurs here  

   21321312312321321312313123123..spell();    //"two hundred thirteen Tredecillion  , two hundred thirteen duodecillion  , one hundred twenty three undecillion  , one hundred twenty three decillion  , two hundred thirteen nonillion  , two hundred twenty octillion "
   spell(21321312312321321312313123123);		//"two hundred thirteen Tredecillion  , two hundred thirteen duodecillion  , one hundred twenty three undecillion  , one hundred twenty three decillion  , two hundred thirteen nonillion  , two hundred twenty octillion "

So best approach is to prefer string equivalents of them :

	"21321312312321321312313123123".spell(); 
	spell("21321312312321321312313123123");

	document.querySelector("#input").value.trim().spell();   
	$("#input").val().trim().spell()
	//Because it returns String value not Number value of input
  1. Preceding a number with 0 causes JavScript to interpret it as an Octadecimal number (Base 8, 0-7 digits).
	spell(070)    // outputs "fifty six"
	spell(080)    // outputs "eighty"    
	//because if it were octadecimal 8 should not be there. Hence treated as default i.e. binary

Likewise numbers preceding with 0x are hexadecimal. Hence safest approach as discussed earlier is to use string equivalent!!!

	spell("070")    // outputs "seventy"
	spell("080")    // outputs "eighty" 

How it works

As there is limit on maximum integer size that we can use in JavaScript, spellJS uses Strings to manipulate the numbers. A huge number is broken down into chunks of strings and then recursively spelled out. The current max limit is 303 digits long number. And that too is is not because of memory issues. By increasing the map provided to SpellJS, the range can be further increased.

Contributing

We welcome contributions and improvements!