@humanwhocodes/number-to-words
v1.0.0
Published
Converts a number into English words.
Downloads
230
Readme
Number to Words
If you find this useful, please consider supporting my work with a donation.
Description
A function that accepts a positive integer (or zero) and returns the English-language description of the number.
Usage
Node.js
npm install @humanwhocodes/number-to-words --save
# or
yarn add @humanwhocodes/number-to-words
Import into your Node.js project:
// CommonJS
const { numberToWords } = require("@humanwhocodes/number-to-words");
// ESM
import { numberToWords } from "@humanwhocodes/number-to-words";
Deno
Import into your Deno project:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words?dts";
Browser
It's recommended to import the minified version to save bandwidth:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words?min";
However, you can also import the unminified version for debugging purposes:
import { numberToWords } from "https://cdn.skypack.dev/@humanwhocodes/number-to-words";
API
After importing, pass any positive integer or zero to numberToWords()
:
console.log(numberToWords(0)); // "zero"
console.log(numberToWords(10)); // "ten"
console.log(numberToWords(524)); // "five hundred twenty-four"
The numberToWords()
function works up to 999 trillion. If you need larger numbers then that, I envy you.
Developer Setup
- Fork the repository
- Clone your fork
- Run
npm install
to setup dependencies - Run
npm test
to run tests
License
Apache 2.0