geld 1.8.1 → 3.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 -4
- package/index.js +10 -12
- package/package.json +25 -26
- package/index.js.flow +0 -16
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,7 +1,5 @@
|
|
|
1
|
-
/// <reference types="node"/>
|
|
2
|
-
|
|
3
1
|
declare namespace Geld {
|
|
4
|
-
|
|
2
|
+
type Options = {
|
|
5
3
|
currency?: string;
|
|
6
4
|
currencyPosition?: 'before' | 'after';
|
|
7
5
|
decimals?: number;
|
|
@@ -9,7 +7,7 @@ declare namespace Geld {
|
|
|
9
7
|
orderSeparator?: string;
|
|
10
8
|
zeroDecimals?: string;
|
|
11
9
|
space?: string;
|
|
12
|
-
}
|
|
10
|
+
};
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
declare function geld(
|
package/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const geld = (value, options) => {
|
|
4
2
|
const config = {
|
|
5
3
|
currency: '€',
|
|
@@ -9,7 +7,7 @@ const geld = (value, options) => {
|
|
|
9
7
|
orderSeparator: '.',
|
|
10
8
|
zeroDecimals: '',
|
|
11
9
|
space: ' ',
|
|
12
|
-
...options
|
|
10
|
+
...options,
|
|
13
11
|
};
|
|
14
12
|
|
|
15
13
|
if (!value || Number.isNaN(value) || Number.isNaN(Number(value))) {
|
|
@@ -23,11 +21,11 @@ const geld = (value, options) => {
|
|
|
23
21
|
const fnums = parts[0];
|
|
24
22
|
let dec = parts[1] ? config.decimalSeparator + parts[1] : '';
|
|
25
23
|
|
|
26
|
-
let
|
|
24
|
+
let currency = '';
|
|
27
25
|
if (config.currency) {
|
|
28
|
-
|
|
29
|
-
config.currency + config.space
|
|
30
|
-
config.space + config.currency;
|
|
26
|
+
currency = config.currencyPosition === 'before'
|
|
27
|
+
? config.currency + config.space
|
|
28
|
+
: config.space + config.currency;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
// Do something with zero-valued decimals
|
|
@@ -35,13 +33,13 @@ const geld = (value, options) => {
|
|
|
35
33
|
dec = config.zeroDecimals === '' || config.zeroDecimals === null ? '' : config.decimalSeparator + config.zeroDecimals;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
const formattedValue
|
|
39
|
-
fnums.
|
|
40
|
-
return config.currencyPosition === 'before'
|
|
36
|
+
const formattedValue
|
|
37
|
+
= fnums.replaceAll(/(?<num>\d)(?=(?:\d{3})+$)/g, '$1' + config.orderSeparator) + dec;
|
|
38
|
+
return config.currencyPosition === 'before'
|
|
41
39
|
// As in '$ 123'
|
|
42
|
-
|
|
40
|
+
? currency + formattedValue
|
|
43
41
|
// As in '123 €'
|
|
44
|
-
formattedValue +
|
|
42
|
+
: formattedValue + currency;
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
export default geld;
|
package/package.json
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geld",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.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": ">=18"
|
|
21
24
|
},
|
|
22
25
|
"main": "index.js",
|
|
23
26
|
"type": "module",
|
|
24
27
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
+
"coverage": "c8 report --reporter=lcov",
|
|
29
|
+
"prepare": "husky",
|
|
30
|
+
"test": "xo && tsd && c8 ava"
|
|
28
31
|
},
|
|
29
32
|
"files": [
|
|
30
33
|
"index.js",
|
|
31
|
-
"index.js.flow",
|
|
32
34
|
"index.d.ts"
|
|
33
35
|
],
|
|
34
36
|
"keywords": [
|
|
@@ -36,19 +38,16 @@
|
|
|
36
38
|
"format"
|
|
37
39
|
],
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
"ava": "^6.0.1",
|
|
42
|
+
"c8": "^9.1.0",
|
|
43
|
+
"husky": "^9.0.9",
|
|
44
|
+
"lint-staged": "^15.0.2",
|
|
45
|
+
"tsd": "^0.30.1",
|
|
46
|
+
"xo": "^0.57.0"
|
|
47
|
+
},
|
|
48
|
+
"lint-staged": {
|
|
49
|
+
"*.js": "xo --fix"
|
|
47
50
|
},
|
|
48
|
-
"pre-commit": [
|
|
49
|
-
"format",
|
|
50
|
-
"test"
|
|
51
|
-
],
|
|
52
51
|
"tsd": {
|
|
53
52
|
"directory": "test"
|
|
54
53
|
}
|
package/index.js.flow
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
interface GeldOptions {
|
|
4
|
-
currency?: string;
|
|
5
|
-
currencyPosition?: 'before' | 'after';
|
|
6
|
-
decimals?: number;
|
|
7
|
-
decimalSeparator?: string;
|
|
8
|
-
orderSeparator?: string;
|
|
9
|
-
zeroDecimals?: string;
|
|
10
|
-
space?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
declare export default function geld(
|
|
14
|
-
value: number | string,
|
|
15
|
-
options?: GeldOptions
|
|
16
|
-
): string;
|