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 CHANGED
@@ -2,13 +2,12 @@
2
2
 
3
3
  > geld is a minimal currency formatter.
4
4
 
5
- ![Update Status](https://img.shields.io/david/dev/dreamseer/geld.svg)
6
- [![Build Status](https://travis-ci.org/Dreamseer/geld.svg?branch=main)](https://travis-ci.org/Dreamseer/geld)
7
- [![Coverage Status](https://coveralls.io/repos/github/Dreamseer/geld/badge.svg?branch=main)](https://coveralls.io/github/Dreamseer/geld?branch=main)
5
+ [![Test](https://github.com/mrcgrtz/geld/actions/workflows/test.yml/badge.svg)](https://github.com/mrcgrtz/geld/actions/workflows/test.yml)
6
+ [![Coverage Status](https://coveralls.io/repos/github/mrcgrtz/geld/badge.svg?branch=main)](https://coveralls.io/github/mrcgrtz/geld?branch=main)
8
7
  [![Install size](https://packagephobia.now.sh/badge?p=geld)](https://packagephobia.now.sh/result?p=geld)
9
8
  [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
10
- [![Flow](https://img.shields.io/npm/types/geld)](https://flow.org/)
11
- [![MIT license](https://img.shields.io/github/license/dreamseer/geld.svg)](https://github.com/Dreamseer/geld/blob/main/LICENSE.md)
9
+ [![Types](https://img.shields.io/npm/types/geld)](https://www.typescriptlang.org/)
10
+ [![MIT license](https://img.shields.io/github/license/mrcgrtz/geld.svg)](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
- const geld = require('geld');
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/dreamseer/geld-cli) is a CLI for geld.
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
- interface Options {
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 curr = '';
24
+ let currency = '';
27
25
  if (config.currency) {
28
- curr = config.currencyPosition === 'before' ?
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.replace(/(?<num>\d)(?=(?:\d{3})+$)/g, '$1' + config.orderSeparator) + dec;
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
- curr + formattedValue :
40
+ ? currency + formattedValue
43
41
  // As in '123 €'
44
- formattedValue + curr;
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": "1.8.1",
3
+ "version": "3.0.0",
4
4
  "description": "geld is a minimal currency formatter.",
5
5
  "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/Dreamseer/geld.git"
9
- },
10
- "funding": {
11
- "type": "kofi",
12
- "url": "https://ko-fi.com/dreamseer"
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": ">=10"
23
+ "node": ">=18"
21
24
  },
22
25
  "main": "index.js",
23
26
  "type": "module",
24
27
  "scripts": {
25
- "format": "xo --fix",
26
- "test": "xo && flow check test/ && tsd && c8 ava",
27
- "coveralls": "c8 report --reporter=text-lcov | coveralls"
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
- "@types/node": "^15.0.2",
40
- "ava": "^3.15.0",
41
- "c8": "^7.7.2",
42
- "coveralls": "^3.1.0",
43
- "flow-bin": "^0.150.0",
44
- "pre-commit": "^1.2.2",
45
- "tsd": "^0.14.0",
46
- "xo": "^0.39.1"
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;