geld is a minimal currency formatter.
Using npm:
npm install geld --save
Using yarn:
yarn add geld
import geld from 'geld';
const price1 = geld(42.23);
console.log(price1); // => '42,23 €'
const price2 = geld(42, { zeroDecimals: '–' });
console.log(price2); // => '42,– €'
Type: number
or string
Required value to format.
Type: string
Currency symbol to use.
Default: '€'
Type: string
Position of the currency symbol, either 'before'
or 'after'
the formatted value.
Default: 'after'
Type: number
Amount of decimals.
Default: 2
Type: string
Character for decimal separation, e.g. in 1,23
.
Default: ','
Type: string
Character for order separation, e.g. in 1.000.000
.
Default: '.'
Type: string
Character to use as a replacement for zero decimals, e.g. 1,–
.
Default: ''
Type: string
Character to use as a spacer between formatted value and currency symbol.
Default: ' '
(i.e. U+00A0 NO-BREAK SPACE
)
Of course geld’s defaults are opinionated: I’m from Germany, thus I set German Euro defaults.
geld, not GELD or Geld. Pronounced /ɡɛlt/.
- geld-cli is a CLI for geld.
Number.toLocaleString()
provides native currency formatting.- currency-formatter is a more powerful formatter.
MIT © Marc Görtz