geld
v3.0.0
Published
geld is a minimal currency formatter.
Downloads
61
Readme
geld is a minimal currency formatter.
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
- geld-cli is a CLI for geld.
Number.toLocaleString()
provides native currency formatting.- currency-formatter is a more powerful formatter.
License
MIT © Marc Görtz