npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mtkcs/written-number-currency

v0.5.1

Published

Convert money amounts to words using a chosen currency

Downloads

47

Readme

WrittenNumberCurrency

Installation

npm i @mtkcs/written-number-currency

Usage

Under the hood written-number-currency uses the written-number library to convert number to words.

const wnc = require('@mtkcs/written-number-currency');

// There are only 2 presets for the moment. You can create your own and submit them
// if you want.
// Import a preset that corresponds to your language-currency combination.
const frDinarPresets = require('@mtkcs/written-number-currency/lib/presets/fr-dinar');

// locales for your language. Check the written-number library for all available locales:
const fr = require('written-number/lib/i18n/fr.json');

// create an instance
const instance = wnc({lang: fr, ...frDinarPresets});

// If we want to get the string representation of 1234 Dinar and 23 millimes (1234.023)
// amount = 1234: amount in dollars (euros, dinars, ...)
// precision = 23: amount in cents (centimes, millimes, ...)
const result = instance({amount: 1234, precision: 23});

console.log(result);
// => mille deux cent trente-quatre dinars et vingt-trois millimes

WrittenNumberCurrency

The arguments are:

  • lang: Object|required. A written-number valid language object.
  • linker: String|optional. The word that links between the amount and the precision
  • amountFormatter: Function|required if amount is provided. Function that accepts an amount an returns the correct grammatical form of the base currency.
  • precisionFormatter: Function|required if precision is provided. Function that accepts an amount an returns the correct grammatical form of the small currency.

Presets

Presets are objects that should contain 3 keys: linker amountFormatter precisionFormatter

Example:
// presets/en-dollar.js
const preset = {
  linker: 'and',
  amountFormatter(amount) {
    if (amount === 1) return 'dollar';
    return 'dollars';
  },
  precisionFormatter(amount) {
    if (amount === 1) return 'cent';
    return 'cents';
  },
}

Instance returned by WrittenNumberCurrency

The arguments are:

  • amount: Positive Integer|required if precision was not provided. The base currency of your choice, ex: dollar, euro, dinar...
  • precision: Positive Integer|required if amount was not provided. The small currency of your choice, ex: cent, millime, centime...

Licence

MIT