geld
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

geld

geld is a minimal currency formatter.

Test Coverage Status Install size XO code style Types MIT license

Install

Using npm:

npm install geld --save

Using yarn:

yarn add geld

Usage

import geld from 'geld';

const price1 = geld(42.23);
console.log(price1); // => '42,23 €'

const price2 = geld(42, { zeroDecimals: '–' });
console.log(price2); // => '42,– €'

API

geld(value, [options])

value

Type: number or string

Required value to format.

options.currency

Type: string

Currency symbol to use. Default: '€'

options.currencyPosition

Type: string

Position of the currency symbol, either 'before' or 'after' the formatted value. Default: 'after'

options.decimals

Type: number

Amount of decimals. Default: 2

options.decimalSeparator

Type: string

Character for decimal separation, e.g. in 1,23. Default: ','

options.orderSeparator

Type: string

Character for order separation, e.g. in 1.000.000. Default: '.'

options.zeroDecimals

Type: string

Character to use as a replacement for zero decimals, e.g. 1,–. Default: ''

options.space

Type: string

Character to use as a spacer between formatted value and currency symbol. Default: ' ' (i.e. U+00A0 NO-BREAK SPACE)

FAQ

“Why did you set these silly defaults? I prefer X.”

Of course geld’s defaults are opinionated: I’m from Germany, thus I set German Euro defaults.

“How is the name written and pronounced?”

geld, not GELD or Geld. Pronounced /ɡɛlt/.

Related

License

MIT © Marc Görtz

Readme

Keywords

Package Sidebar

Install

npm i geld

Weekly Downloads

9

Version

3.0.0

License

MIT

Unpacked Size

6.39 kB

Total Files

5

Last publish

Collaborators

  • dreamseer