- Notifications
You must be signed in to change notification settings - Fork0
Converts a number into its name.
License
TheoryOfNekomata/number-name
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Converts a number into its name.
Inspired bynumber-to-words. Thinking I could improve on the code to includebig integers, I looked for some info and foundLandon Curt Noll's Web page describingthe reconstructed English naming system of numbers. I decided to porthisPerl script into JavaScript.
number-name
requiresNode.js, tested with at leastv.5. It should work with relativelyearlier versions of Node.js (at least v.4). If you find bugs from v.4, kindly create an issue specifying whatevererror message you are getting, and the code snippet of your code usingnumber-name
(or you may submit PRs of yourfixes, see Contribution below).
The procedures for installingnumber-name
are:
- Install via NPM:
$ npm install --save @theoryofnekomata/number-name
- Run
npm install
- Run
npm run build
varNumberName=require('@theoryofnekomata/number-name'),// see https://github.com/Temoto-kun/number-name/tree/master/src/lang for systemsconverter=newNumberName({system:systemObj,fractionType:'lazy'});varsmallerNumber=-6.9e-42;// Number is OK. Can convert negative numbers just fine.varlargeNumber='5.0e+303';// note this is too large for a normal Number, so it is represented as stringvarname1=converter.toName(smallerNumber);// returns the long fractional name with "...six nine" in the endvarname2=converter.toName(largeNumber);// returns "five centillion"
It also works in the browser via<script>
tags.
number-name
is powered bybig-integer
. With this, it can convert:
Number
s- number-like strings
- Fully localizable number systems (e.g. custom rules for combining fragments of number words)
- Optimizations for fractions.
- Implement other
fractionType
s, (onlylazy
(digits) is supported as of 0.2.0, e.g.0.05
=>zero point zero five
,will implementratio
(zero and five over one hundred
) andpart
(zero and five hundredths
)) - Upon adding more features, update the unit tests as well.
Sure thing! Just clone the repo.
number-name
usesJasmine for unit tests, andESLint to make sure code is written consistently (and implied it willrun 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.
MIT. SeeLICENSE file for details.
About
Converts a number into its name.