geld 2.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -7
- package/index.d.ts +2 -2
- package/index.js +5 -5
- package/package.json +28 -10
package/README.md
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
> geld is a minimal currency formatter.
|
|
4
4
|
|
|
5
|
-
](https://coveralls.io/github/Dreamseer/geld?branch=main)
|
|
5
|
+
[](https://github.com/mrcgrtz/geld/actions/workflows/test.yml)
|
|
6
|
+
[](https://coveralls.io/github/mrcgrtz/geld?branch=main)
|
|
8
7
|
[](https://packagephobia.now.sh/result?p=geld)
|
|
9
8
|
[](https://github.com/sindresorhus/xo)
|
|
10
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](https://github.com/mrcgrtz/geld/blob/main/LICENSE.md)
|
|
12
11
|
|
|
13
12
|
## Install
|
|
14
13
|
|
|
@@ -27,7 +26,7 @@ yarn add geld
|
|
|
27
26
|
## Usage
|
|
28
27
|
|
|
29
28
|
```js
|
|
30
|
-
|
|
29
|
+
import geld from 'geld';
|
|
31
30
|
|
|
32
31
|
const price1 = geld(42.23);
|
|
33
32
|
console.log(price1); // => '42,23 €'
|
|
@@ -108,7 +107,7 @@ geld, not GELD or Geld. Pronounced [/ɡɛlt/](https://en.wiktionary.org/wiki/Gel
|
|
|
108
107
|
|
|
109
108
|
## Related
|
|
110
109
|
|
|
111
|
-
* [geld-cli](https://github.com/
|
|
110
|
+
* [geld-cli](https://github.com/mrcgrtz/geld-cli) is a CLI for geld.
|
|
112
111
|
* [`Number.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) provides native currency formatting.
|
|
113
112
|
* [currency-formatter](https://github.com/smirzaei/currency-formatter) is a more powerful formatter.
|
|
114
113
|
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare namespace Geld {
|
|
2
|
-
|
|
2
|
+
type Options = {
|
|
3
3
|
currency?: string;
|
|
4
4
|
currencyPosition?: 'before' | 'after';
|
|
5
5
|
decimals?: number;
|
|
@@ -7,7 +7,7 @@ declare namespace Geld {
|
|
|
7
7
|
orderSeparator?: string;
|
|
8
8
|
zeroDecimals?: string;
|
|
9
9
|
space?: string;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare function geld(
|
package/index.js
CHANGED
|
@@ -21,9 +21,9 @@ const geld = (value, options) => {
|
|
|
21
21
|
const fnums = parts[0];
|
|
22
22
|
let dec = parts[1] ? config.decimalSeparator + parts[1] : '';
|
|
23
23
|
|
|
24
|
-
let
|
|
24
|
+
let currency = '';
|
|
25
25
|
if (config.currency) {
|
|
26
|
-
|
|
26
|
+
currency = config.currencyPosition === 'before'
|
|
27
27
|
? config.currency + config.space
|
|
28
28
|
: config.space + config.currency;
|
|
29
29
|
}
|
|
@@ -34,12 +34,12 @@ const geld = (value, options) => {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const formattedValue
|
|
37
|
-
= fnums.
|
|
37
|
+
= fnums.replaceAll(/(?<num>\d)(?=(?:\d{3})+$)/g, '$1' + config.orderSeparator) + dec;
|
|
38
38
|
return config.currencyPosition === 'before'
|
|
39
39
|
// As in '$ 123'
|
|
40
|
-
?
|
|
40
|
+
? currency + formattedValue
|
|
41
41
|
// As in '123 €'
|
|
42
|
-
: formattedValue +
|
|
42
|
+
: formattedValue + currency;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export default geld;
|
package/package.json
CHANGED
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geld",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "geld is a minimal currency formatter.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"repository":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
"repository": "github:mrcgrtz/geld",
|
|
7
|
+
"funding": [
|
|
8
|
+
{
|
|
9
|
+
"type": "kofi",
|
|
10
|
+
"url": "https://ko-fi.com/mrcgrtz"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "liberapay",
|
|
14
|
+
"url": "https://liberapay.com/mrcgrtz"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
14
17
|
"author": {
|
|
15
18
|
"name": "Marc Görtz",
|
|
16
19
|
"email": "git@marcgoertz.de",
|
|
17
20
|
"url": "https://marcgoertz.de/"
|
|
18
21
|
},
|
|
19
22
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
23
|
+
"node": ">=22"
|
|
21
24
|
},
|
|
22
25
|
"main": "index.js",
|
|
23
26
|
"type": "module",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"coverage": "c8 report --reporter=lcov",
|
|
29
|
+
"prepare": "husky",
|
|
30
|
+
"test": "xo && tsd && c8 node --test"
|
|
31
|
+
},
|
|
24
32
|
"files": [
|
|
25
33
|
"index.js",
|
|
26
34
|
"index.d.ts"
|
|
@@ -29,6 +37,16 @@
|
|
|
29
37
|
"currency",
|
|
30
38
|
"format"
|
|
31
39
|
],
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"c8": "^10.1.3",
|
|
42
|
+
"husky": "^9.1.7",
|
|
43
|
+
"lint-staged": "^16.0.0",
|
|
44
|
+
"tsd": "^0.32.0",
|
|
45
|
+
"xo": "^0.60.0"
|
|
46
|
+
},
|
|
47
|
+
"lint-staged": {
|
|
48
|
+
"*.js": "xo --fix"
|
|
49
|
+
},
|
|
32
50
|
"tsd": {
|
|
33
51
|
"directory": "test"
|
|
34
52
|
}
|