Skip to content

TheoryOfNekomata/number-name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

number-name

Converts a number into its name.

See the demo here.

Why?

Inspired by number-to-words. Thinking I could improve on the code to include big integers, I looked for some info and found Landon Curt Noll's Web page describing the reconstructed English naming system of numbers. I decided to port his Perl script into JavaScript.

Installation

number-name requires Node.js, tested with at least v.5. It should work with relatively earlier versions of Node.js (at least v.4). If you find bugs from v.4, kindly create an issue specifying whatever error message you are getting, and the code snippet of your code using number-name (or you may submit PRs of your fixes, see Contribution below).

The procedures for installing number-name are:

  1. Install via NPM:
$ npm install --save @theoryofnekomata/number-name
  1. Run npm install
  2. Run npm run build

Usage

var NumberName = require('@theoryofnekomata/number-name'),

// see https://github.com/Temoto-kun/number-name/tree/master/src/lang for systems
converter = new NumberName({ system: systemObj, fractionType: 'lazy' });

var smallerNumber = -6.9e-42; // Number is OK. Can convert negative numbers just fine.
var largeNumber = '5.0e+303'; // note this is too large for a normal Number, so it is represented as string
var name1 = converter.toName(smallerNumber); // returns the long fractional name with "...six nine" in the end
var name2 = converter.toName(largeNumber); // returns "five centillion"

It also works in the browser via <script> tags.

Notes

number-name is powered by big-integer. With this, it can convert:

  • Numbers
  • number-like strings

TODO

  • Fully localizable number systems (e.g. custom rules for combining fragments of number words)
  • Optimizations for fractions.
  • Implement other fractionTypes, (only lazy (digits) is supported as of 0.2.0, e.g. 0.05 => zero point zero five, will implement ratio (zero and five over one hundred) and part (zero and five hundredths))
  • Upon adding more features, update the unit tests as well.

Contribution

Sure thing! Just clone the repo.

number-name uses Jasmine for unit tests, and ESLint to make sure code is written consistently (and implied it will run consistently as well).

  • Run npm install upon initial clone.
  • Run npm test and make sure all the tests pass and properly written.
  • Run npm run lint to ensure consistency of your code (make sure to install ESLint first).
  • Create PRs so that I can confirm and merge your contributions.

Please star the repo if you find it useful in your projects.

License

MIT. See LICENSE file for details.