1.0.5 • Published 1 year ago

amount2words v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

amount2words

Tests npm npm bundle size\ \ A simple library for parsing numeric values into words, written in TypeScript.

Description

This library exposes two methods for parsing numeric values into strings of text. You can either use parseValueToWords to parse a single non-decimal value into words, or use the parseDecimalValueToWords function to parse decimal values, along with the supported currencies and locales.

Currently supported currencies:

  • USD - US Dollars
  • PLN - Polish Zloty

Currently supported parsing locales:

  • enUS - American English
  • plPL - Polish

How to use

// CommonJS module
const a2w = require("amount2words");

// ECMAScript Module
import a2w from "amount2words";

// parsing a single numeric value for given locale
const parsedValue = a2w.parseValueToWords("6794", "enUS");
// returns Six Thousand Seven Hundred Ninety-Four

// parsing decimal amount, with currency, for given locale
const parsedDecimalValue = const parsedValue = a2w.parseDecimalValueToWords("334877.99", "USD", "enUS");
// returns Three Hundred Thirty-Four Thousand Eight Hundred Seventy-Seven Dollars and Ninety-Nine Cents

Accepted function parameters

type parseValueToWordsParams = {
  value?: string; // defaults to "0"
  parsingLocale?: string; // defaults to "enUS"
};

type parseDecimalValueToWordsParams = {
  amountToParse: string;
  currencySymbol: string;
  locale: string;
  toLowerCase?: boolean; // defaults to false
};

Acknowledgments

Inspired by Mohsen Alyafei's proposed StackOverflow solution.

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago