UNPKG

2.86 kBMarkdownView Raw
1# ![geld](media/logo.png)
2
3> geld is a minimal currency formatter.
4
5![Update Status](https://img.shields.io/david/dev/dreamseer/geld.svg) [![Build Status](https://travis-ci.org/Dreamseer/geld.svg?branch=master)](https://travis-ci.org/Dreamseer/geld) [![Coverage Status](https://coveralls.io/repos/github/Dreamseer/geld/badge.svg?branch=master)](https://coveralls.io/github/Dreamseer/geld?branch=master) [![Install size](https://packagephobia.now.sh/badge?p=geld)](https://packagephobia.now.sh/result?p=geld) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) [![MIT license](https://img.shields.io/github/license/dreamseer/geld.svg)](https://github.com/Dreamseer/geld/blob/master/LICENSE.md) [![Greenkeeper badge](https://badges.greenkeeper.io/Dreamseer/geld.svg)](https://greenkeeper.io/)
6
7## Install
8
9Using [npm](https://www.npmjs.com/get-npm):
10
11```bash
12npm install geld --save
13```
14
15Using [yarn](https://yarnpkg.com/):
16
17```bash
18yarn add geld
19```
20
21## Usage
22
23```js
24const geld = require('geld');
25
26const price1 = geld(42.23);
27console.log(price1); // => '42,23 €'
28
29const price2 = geld(42, { zeroDecimals: '–' });
30console.log(price2); // => '42,– €'
31```
32
33## API
34
35### geld(value, [options])
36
37#### value
38
39Type: `number` or `string`
40
41Required value to format.
42
43#### options.currency
44
45Type: `string`
46
47Currency symbol to use.
48Default: `'€'`
49
50#### options.currencyPosition
51
52Type: `string`
53
54Position of the currency symbol, either `'before'` or `'after'` the formatted value.
55Default: `'after'`
56
57#### options.decimals
58
59Type: `number`
60
61Amount of decimals.
62Default: `2`
63
64#### options.decimalSeparator
65
66Type: `string`
67
68Character for decimal separation, e.g. in `1,23`.
69Default: `','`
70
71#### options.orderSeparator
72
73Type: `string`
74
75Character for order separation, e.g. in `1.000.000`.
76Default: `'.'`
77
78#### options.zeroDecimals
79
80Type: `string`
81
82Character to use as a replacement for zero decimals, e.g. `1,–`.
83Default: `''`
84
85#### options.space
86
87Type: `string`
88
89Character to use as a spacer between formatted value and currency symbol.
90Default: `' '` (i.e. `U+00A0 NO-BREAK SPACE`)
91
92## FAQ
93
94### “Why did you set these silly defaults? I prefer X.”
95
96Of course geld’s defaults are opinionated:
97I’m from Germany, thus I set German Euro defaults.
98
99### “How is the name written and pronounced?”
100
101geld, not GELD or Geld. Pronounced [/ɡɛlt/](https://en.wiktionary.org/wiki/Geld).
102
103## Related
104
105* [geld-cli](https://github.com/dreamseer/geld-cli) is a CLI for geld.
106* [`Number.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) provides native currency formatting.
107* [currency-formatter](https://github.com/smirzaei/currency-formatter) is a more powerful formatter.
108
109## License
110
111MIT © [Marc Görtz](https://marcgoertz.de/)