Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Converts a number into its name.

License

NotificationsYou must be signed in to change notification settings

TheoryOfNekomata/number-name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Converts a number into its name.

See the demo here.

Why?

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.

Installation

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:

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

Usage

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.

Notes

number-name is powered bybig-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 otherfractionTypes, (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.

Contribution

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).

  • Runnpm install upon initial clone.
  • Runnpm test and make sure all the tests pass and properly written.
  • Runnpm 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. SeeLICENSE file for details.


[8]ページ先頭

©2009-2025 Movatter.jp