New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@qit.tools/number-to-words

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qit.tools/number-to-words

This tiny library (🪶 1.4 KB) converts numbers to English words, supporting both general numeric values and monetary values with customizable currency and minor units.

  • 0.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-55.56%
Maintainers
1
Weekly downloads
 
Created
Source

Number to Words Converter

Test status

This tiny library (🪶 1.4 KB) converts numbers to English words, supporting both general numeric values and monetary values with customizable currency and minor units.

👀 DEMO

CDN

  • unpkg

🏗️ Install

🎉 NPM

npm i @qit.tools/number-to-words

🧁 Bun

bun add @qit.tools/number-to-words

🌟 PNPM

pnpm add @qit.tools/number-to-words

🧶 Yarn

yarn add @qit.tools/number-to-words

🎓 How to use

Importing the Function

import { numberToWords } from "@qit.tools/number-to-words";

Basic Usage

const words = numberToWords(123); 
console.log(words); // "one hundred twenty-three"

Handling Decimal Numbers

const words = numberToWords(123.45); 
console.log(words); // "one hundred twenty-three point four five"

Formatting as Currency

const options = {
  money: {
    currency: ["dollar", "dollars"],
    minor: ["cent", "cents"]
  }
};

const words = numberToWords(123.45, options); 
console.log(words); // "one hundred twenty-three dollars and forty-five cents"

📝 Function Signature

numberToWords

Converts a number to its corresponding words representation.

Parameters
  • num (number): The number to be converted.
  • options (Options, optional): An optional object to specify formatting options.
Returns
  • string: The words representation of the number.

Options

MoneyOptions
type MoneyOptions = {
  currency: [string, string];
  minor?: [string, string];
};
  • currency (required): An array of two strings representing the singular and plural forms of the currency.
  • minor (optional): An array of two strings representing the singular and plural forms of the minor currency unit.
Options
type Options = {
  money?: MoneyOptions;
};
  • money (optional): An object specifying the money formatting options.

📄 Example Code

Here is an example of how you can use the library in your project:

import { numberToWords } from "number-to-words";

const number = 1234;
const words = numberToWords(number);
console.log(words); // "one thousand two hundred thirty-four"

const moneyOptions = {
  money: {
    currency: ["euro", "euros"],
    minor: ["cent", "cents"]
  }
};

const moneyWords = numberToWords(1234.56, moneyOptions);
console.log(moneyWords); // "one thousand two hundred thirty-four euros and fifty-six cents"

License

MIT

Contributions

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Author

Developed by Qit.tools.


Feel free to explore the source code and contribute to this library on GitHub.

Keywords

FAQs

Package last updated on 24 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc