geld 3.0.0 → 4.1.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 +1 -1
- package/index.js +16 -11
- package/package.json +20 -15
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export default function geld(value, options = {}) {
|
|
2
|
+
if (!value || Number.isNaN(value) || Number.isNaN(Number(value))) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
|
|
2
6
|
const config = {
|
|
3
7
|
currency: '€',
|
|
4
8
|
currencyPosition: 'after',
|
|
@@ -10,10 +14,6 @@ const geld = (value, options) => {
|
|
|
10
14
|
...options,
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
if (!value || Number.isNaN(value) || Number.isNaN(Number(value))) {
|
|
14
|
-
return '';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
17
|
value = Number(value);
|
|
18
18
|
value = value.toFixed(Math.trunc(config.decimals));
|
|
19
19
|
|
|
@@ -29,17 +29,22 @@ const geld = (value, options) => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Do something with zero-valued decimals
|
|
32
|
-
if (
|
|
32
|
+
if (Math.trunc(Number(parts[1])) === 0 && config.zeroDecimals !== undefined) {
|
|
33
33
|
dec = config.zeroDecimals === '' || config.zeroDecimals === null ? '' : config.decimalSeparator + config.zeroDecimals;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const formattedValue
|
|
37
|
-
|
|
36
|
+
const formattedValue = (() => {
|
|
37
|
+
const groups = [];
|
|
38
|
+
for (let i = fnums.length; i > 0; i -= 3) {
|
|
39
|
+
groups.unshift(fnums.slice(Math.max(0, i - 3), i));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return groups.join(config.orderSeparator) + dec;
|
|
43
|
+
})();
|
|
44
|
+
|
|
38
45
|
return config.currencyPosition === 'before'
|
|
39
46
|
// As in '$ 123'
|
|
40
47
|
? currency + formattedValue
|
|
41
48
|
// As in '123 €'
|
|
42
49
|
: formattedValue + currency;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default geld;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geld",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "geld is a minimal currency formatter.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:mrcgrtz/geld",
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
"url": "https://liberapay.com/mrcgrtz"
|
|
15
15
|
}
|
|
16
16
|
],
|
|
17
|
-
"author":
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
17
|
+
"author": "Marc Görtz <git@marcgoertz.de> (https://marcgoertz.de/)",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
21
22
|
},
|
|
23
|
+
"sideEffects": false,
|
|
22
24
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
25
|
+
"node": ">=22"
|
|
24
26
|
},
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"type": "module",
|
|
27
27
|
"scripts": {
|
|
28
28
|
"coverage": "c8 report --reporter=lcov",
|
|
29
29
|
"prepare": "husky",
|
|
30
|
-
"test": "xo && tsd && c8
|
|
30
|
+
"test": "xo && tsd && c8 node --test"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"index.js",
|
|
@@ -38,17 +38,22 @@
|
|
|
38
38
|
"format"
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"xo": "^0.57.0"
|
|
41
|
+
"c8": "^12.0.0",
|
|
42
|
+
"husky": "^9.1.7",
|
|
43
|
+
"lint-staged": "^17.0.7",
|
|
44
|
+
"tsd": "^0.33.0",
|
|
45
|
+
"xo": "^5.0.1"
|
|
47
46
|
},
|
|
48
47
|
"lint-staged": {
|
|
49
48
|
"*.js": "xo --fix"
|
|
50
49
|
},
|
|
51
50
|
"tsd": {
|
|
52
51
|
"directory": "test"
|
|
52
|
+
},
|
|
53
|
+
"xo": {
|
|
54
|
+
"ignores": [
|
|
55
|
+
"**/*.d.ts",
|
|
56
|
+
"**/*.test-d.ts"
|
|
57
|
+
]
|
|
53
58
|
}
|
|
54
59
|
}
|