react-native-format-currency 0.0.1 → 0.0.2
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/.eslintrc.js +49 -0
- package/README.md +25 -8
- package/dist/index.js +40 -40
- package/package.json +18 -6
- package/react-native-format-currency.d.ts +7 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: "@typescript-eslint/parser",
|
|
3
|
+
parserOptions: {
|
|
4
|
+
ecmaVersion: "latest",
|
|
5
|
+
project: ["./tsconfig.json", "./tsconfig-build.json"],
|
|
6
|
+
},
|
|
7
|
+
plugins: [
|
|
8
|
+
"prettier", // added so we can access the rule to turn on warnings.
|
|
9
|
+
],
|
|
10
|
+
extends: [
|
|
11
|
+
"airbnb", // https://github.com/airbnb/javascript
|
|
12
|
+
"airbnb/hooks", // https://github.com/airbnb/javascript
|
|
13
|
+
"airbnb-typescript", // https://github.com/iamturns/eslint-config-airbnb-typescript
|
|
14
|
+
"plugin:react-native/all", // https://github.com/intellicode/eslint-plugin-react-native
|
|
15
|
+
"prettier",
|
|
16
|
+
],
|
|
17
|
+
rules: {
|
|
18
|
+
"prettier/prettier": "warn", // show what's going to be fixed with prettier.
|
|
19
|
+
"import/prefer-default-export": "off",
|
|
20
|
+
"import/extensions": "off", // https://stackoverflow.com/a/59268871
|
|
21
|
+
"import/no-extraneous-dependencies": [
|
|
22
|
+
"error",
|
|
23
|
+
{ devDependencies: ["**/*test.*"] },
|
|
24
|
+
], // allow devDependency imports in test files. https://stackoverflow.com/a/55863857/25197
|
|
25
|
+
|
|
26
|
+
// ::: TypeScript
|
|
27
|
+
"@typescript-eslint/no-unused-vars": ["off", { ignoreRestSiblings: true }], // allow unused variables when using a rest property. https://stackoverflow.com/q/56151661/25197
|
|
28
|
+
|
|
29
|
+
// ::: ESlint
|
|
30
|
+
// 'arrow-body-style': 'off', // Allow commented out console logs in arrow bodies.
|
|
31
|
+
// camelcase: 'off', // We're forced to use snake_case for graphql and Auth0 response.
|
|
32
|
+
// 'global-require': 'off', // Allow inline requires() for Expo asset imports.
|
|
33
|
+
// 'no-param-reassign': ['error', { props: false }], // Allow param reassignment because we use it for easy-peasy state. https://stackoverflow.com/a/42399879
|
|
34
|
+
// 'no-unreachable': 'warn', // turned off in tsconfig.json and added here so code doesn't get deleted by --autofix command.
|
|
35
|
+
// 'consistent-return': 'off', // we allow multiple returns via "guard statements". https://stackoverflow.com/q/36707/25197
|
|
36
|
+
// 'no-underscore-dangle': ['error', { allow: ['_forTesting'] }], // allow for exporting to unit tests. https://stackoverflow.com/a/65422568/25197
|
|
37
|
+
// 'no-restricted-exports': 'off', // TODO: turn this back on and refactor default exports.
|
|
38
|
+
|
|
39
|
+
// // ::: React
|
|
40
|
+
// 'react/function-component-definition': ['error', { namedComponents: 'arrow-function' }], // use named arrow functions for components. https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
|
|
41
|
+
// 'react/require-default-props': 'off', // Waiting on setting once this is settled. https://github.com/reactjs/rfcs/pull/107
|
|
42
|
+
// 'react/prop-types': 'off', // Let Typescript handle all type issues.
|
|
43
|
+
// 'react/jsx-props-no-spreading': 'off', // Meant to protect against unwanted/unintended props are being passed to the component but we do it all the time.
|
|
44
|
+
|
|
45
|
+
// // ::: React Native
|
|
46
|
+
// 'react-native/no-raw-text': 'off', // NativeBase has components that accept raw text.
|
|
47
|
+
// 'react-native/no-inline-styles': 'off', // NativeBase is only inline styling.
|
|
48
|
+
},
|
|
49
|
+
};
|
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# react-native-format-currency
|
|
2
|
-
> A lightweight international currency formatter for React Native & Expo (iOS and Android). Check out the [example app](example/) for a working demo.
|
|
3
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-format-currency)
|
|
4
|
+
[](https://www.npmjs.com/package/react-native-format-currency)
|
|
5
|
+
[](https://twitter.com/intent/follow?screen_name=AwesomeLabsLLC)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
A lightweight international currency formatter for React Native & Expo (iOS and Android). Check out the [example app](example/) for a working demo.
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
```sh
|
|
@@ -13,7 +18,14 @@ $ npm install react-native-format-currency
|
|
|
13
18
|
|
|
14
19
|
## Usage
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
Import library with
|
|
22
|
+
```js
|
|
23
|
+
import { formatCurrency, getSupportedCurrencies } from "react-native-format-currency";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Methods
|
|
27
|
+
|
|
28
|
+
### `formatCurrency({ amount: _number_, code: _string_})`
|
|
17
29
|
|
|
18
30
|
```sh
|
|
19
31
|
formatCurrency({ amount: 1234.56, code: "ARS" })
|
|
@@ -22,19 +34,24 @@ Formats a currency amount to specified currency code:
|
|
|
22
34
|
```js
|
|
23
35
|
const [valueFormattedWithSymbol, valueFormattedWithoutSymbol, symbol] = formatCurrency({ amount: 1234.56, code: "ARS" })
|
|
24
36
|
```
|
|
25
|
-
Returns:
|
|
26
|
-
```js
|
|
27
|
-
["$ 1.234,56", "1.234,56", "$"]
|
|
28
|
-
```
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
__Props__
|
|
31
39
|
|
|
32
40
|
| Prop | Type | Default | Note |
|
|
33
41
|
|---|---|---|---|
|
|
34
42
|
| `amount` | `Number` | null | currency amount
|
|
35
43
|
| `code` | `String` | null | 3-letter [ISO 4217 Currency Code](https://en.wikipedia.org/wiki/ISO_4217)
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
__Returns:__
|
|
46
|
+
|
|
47
|
+
Array containing formatted currency string, formatted currency (without symbol), and currency symbol
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
["$ 1.234,56", "1.234,56", "$"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### `getSupportedCurrencies()`
|
|
38
55
|
```
|
|
39
56
|
getSupportedCurrencies()
|
|
40
57
|
```
|
package/dist/index.js
CHANGED
|
@@ -9,85 +9,85 @@ var formatCurrency = function (_a) {
|
|
|
9
9
|
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
|
|
10
10
|
var switchOptions = {
|
|
11
11
|
// argentine peso (ex: $ 1.234,56)
|
|
12
|
-
ARS: ["$ "
|
|
12
|
+
ARS: ["$ ".concat(periodFormatted), "".concat(periodFormatted), "$"],
|
|
13
13
|
// australian dollar (ex: $ 1,234.56)
|
|
14
|
-
AUD: ["$ "
|
|
14
|
+
AUD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
15
15
|
// bulgarian lev (ex: лв1,234.56)
|
|
16
|
-
BGN: ["\u043B\u0432"
|
|
16
|
+
BGN: ["\u043B\u0432".concat(commaFormatted), "".concat(commaFormatted), "лв"],
|
|
17
17
|
// brazilian real (ex: R$ 1.234,56)
|
|
18
|
-
BRL: ["R$ "
|
|
18
|
+
BRL: ["R$ ".concat(periodFormatted), "".concat(periodFormatted), "R$"],
|
|
19
19
|
// canadian dollar (ex: $ 1,234.56)
|
|
20
|
-
CAD: ["$ "
|
|
20
|
+
CAD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
21
21
|
// swiss franc (ex: fr. 1.234,56)
|
|
22
|
-
CHF: ["fr. "
|
|
22
|
+
CHF: ["fr. ".concat(periodFormatted), "".concat(periodFormatted), "fr."],
|
|
23
23
|
// chilean peso (ex: $ 1,234.56)
|
|
24
|
-
CLP: ["$ "
|
|
24
|
+
CLP: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
25
25
|
// yuan renminbi (ex: ¥ 1,234.56)
|
|
26
|
-
CNY: ["\u00A5 "
|
|
26
|
+
CNY: ["\u00A5 ".concat(commaFormatted), "".concat(commaFormatted), "¥"],
|
|
27
27
|
// colombian peso (ex: $ 1,234.56)
|
|
28
|
-
COP: ["$ "
|
|
28
|
+
COP: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
29
29
|
// czech koruna (ex: 1.234,56 Kč)
|
|
30
|
-
CZK: [periodFormatted
|
|
30
|
+
CZK: ["".concat(periodFormatted, " K\u010D"), "".concat(periodFormatted), "Kč"],
|
|
31
31
|
// danish krone (ex: kr. 1.234,56)
|
|
32
|
-
DKK: ["kr. "
|
|
32
|
+
DKK: ["kr. ".concat(periodFormatted), "".concat(periodFormatted), "kr."],
|
|
33
33
|
// european union (ex: €1.234,56)
|
|
34
|
-
EUR: ["\u20AC"
|
|
34
|
+
EUR: ["\u20AC".concat(periodFormatted), "".concat(periodFormatted), "€"],
|
|
35
35
|
// uk/great britain pound sterling (ex: £1,234.56)
|
|
36
|
-
GBP: ["\u00A3"
|
|
36
|
+
GBP: ["\u00A3".concat(commaFormatted), "".concat(commaFormatted), "£"],
|
|
37
37
|
// hong kong dollar (ex: HK$ 1,234.56)
|
|
38
|
-
HKD: ["HK$ "
|
|
38
|
+
HKD: ["HK$ ".concat(commaFormatted), "".concat(commaFormatted), "HK$"],
|
|
39
39
|
// croatian kuna (ex: 1,234.56 kn)
|
|
40
|
-
HRK: [commaFormatted
|
|
40
|
+
HRK: ["".concat(commaFormatted, " kn"), "".concat(commaFormatted), "kn"],
|
|
41
41
|
// hungarian forint (ex: 1.234,56 Ft)
|
|
42
|
-
HUF: [periodFormatted
|
|
42
|
+
HUF: ["".concat(periodFormatted, " Ft"), "".concat(periodFormatted), "Ft"],
|
|
43
43
|
// indonesian rupiah (ex: Rp 1,234.56)
|
|
44
|
-
IDR: ["Rp "
|
|
44
|
+
IDR: ["Rp ".concat(commaFormatted), "".concat(commaFormatted), "Rp"],
|
|
45
45
|
// new israeli shekel (ex: ₪ 1.234,56)
|
|
46
|
-
ILS: ["\u20AA "
|
|
46
|
+
ILS: ["\u20AA ".concat(periodFormatted), "".concat(periodFormatted), "₪"],
|
|
47
47
|
// indian rupee (ex: ₹ 1,234.56)
|
|
48
|
-
INR: ["\u20B9 "
|
|
48
|
+
INR: ["\u20B9 ".concat(commaFormatted), "".concat(commaFormatted), "₹"],
|
|
49
49
|
// icelandic krona (ex: kr. 1.234,56)
|
|
50
|
-
ISK: ["kr. "
|
|
50
|
+
ISK: ["kr. ".concat(periodFormatted), "".concat(periodFormatted), "kr."],
|
|
51
51
|
// yen (ex: ¥ 1,234.56)
|
|
52
|
-
JPY: ["\u00A5 "
|
|
52
|
+
JPY: ["\u00A5 ".concat(commaFormatted), "".concat(commaFormatted), "¥"],
|
|
53
53
|
// won (ex: ₩ 1,234.56)
|
|
54
|
-
KRW: ["\u20A9 "
|
|
54
|
+
KRW: ["\u20A9 ".concat(commaFormatted), "".concat(commaFormatted), "₩"],
|
|
55
55
|
// moroccan dirham (ex: 1,234.56 .د.م.)
|
|
56
|
-
MAD: [commaFormatted
|
|
56
|
+
MAD: ["".concat(commaFormatted, " .\u062F.\u0645."), "".concat(commaFormatted), ".د.م."],
|
|
57
57
|
// mexican peso (ex: $ 1,234.56)
|
|
58
|
-
MXN: ["$ "
|
|
58
|
+
MXN: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
59
59
|
// malaysian ringgit (ex: RM 1,234.56)
|
|
60
|
-
MYR: ["RM "
|
|
60
|
+
MYR: ["RM ".concat(commaFormatted), "".concat(commaFormatted), "RM"],
|
|
61
61
|
// norwegian krone (ex: kr 1,234.56)
|
|
62
|
-
NOK: ["kr "
|
|
62
|
+
NOK: ["kr ".concat(commaFormatted), "".concat(commaFormatted), "kr"],
|
|
63
63
|
// new zealand dollar (ex: $ 1,234.56)
|
|
64
|
-
NZD: ["$ "
|
|
64
|
+
NZD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
65
65
|
// philippine peso (ex: ₱ 1,234.56)
|
|
66
|
-
PHP: ["\u20B1 "
|
|
66
|
+
PHP: ["\u20B1 ".concat(commaFormatted), "".concat(commaFormatted), "₱"],
|
|
67
67
|
// polish zloty (ex: 1.234,56 zł)
|
|
68
|
-
PLN: [periodFormatted
|
|
68
|
+
PLN: ["".concat(periodFormatted, " z\u0142"), "".concat(periodFormatted), "zł"],
|
|
69
69
|
// romanian new leu (ex: 1,234.56L)
|
|
70
|
-
RON: [commaFormatted
|
|
70
|
+
RON: ["".concat(commaFormatted, "L"), "".concat(commaFormatted), "L"],
|
|
71
71
|
// russian ruble (ex: 1.234,56 p.)
|
|
72
|
-
RUB: [periodFormatted
|
|
72
|
+
RUB: ["".concat(periodFormatted, " p."), "".concat(periodFormatted), "p."],
|
|
73
73
|
// saudi riyal (ex: 1,234.56 ﷼)
|
|
74
|
-
SAR: [commaFormatted
|
|
74
|
+
SAR: ["".concat(commaFormatted, " \uFDFC"), "".concat(commaFormatted), "﷼"],
|
|
75
75
|
// swedish krona (ex: 1.234,56 kr)
|
|
76
|
-
SEK: [periodFormatted
|
|
76
|
+
SEK: ["".concat(periodFormatted, " kr"), "".concat(periodFormatted), "kr"],
|
|
77
77
|
// singapore dollar (ex: $1,234.56)
|
|
78
|
-
SGD: ["$"
|
|
78
|
+
SGD: ["$".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
79
79
|
// thai baht (ex: 1,234.56 ฿)
|
|
80
|
-
THB: [commaFormatted
|
|
80
|
+
THB: ["".concat(commaFormatted, " \u0E3F"), "".concat(commaFormatted), "฿"],
|
|
81
81
|
// turkish lira (ex: 1,234.56 ₺)
|
|
82
|
-
TRY: [commaFormatted
|
|
82
|
+
TRY: ["".concat(commaFormatted, " \u20BA"), "".concat(commaFormatted), "₺"],
|
|
83
83
|
// new taiwan dollar (ex: 元 1,234.56)
|
|
84
|
-
TWD: ["\u5143 "
|
|
84
|
+
TWD: ["\u5143 ".concat(commaFormatted), "".concat(commaFormatted), "元"],
|
|
85
85
|
// us dollar (ex: $1,234.56)
|
|
86
|
-
USD: ["$"
|
|
86
|
+
USD: ["$".concat(commaFormatted), "".concat(commaFormatted), "$"],
|
|
87
87
|
// vietnamese dong (ex: 1.234,56 ₫)
|
|
88
|
-
VND: [periodFormatted
|
|
88
|
+
VND: ["".concat(periodFormatted, " \u20AB"), "".concat(periodFormatted), "₫"],
|
|
89
89
|
// south african rand (ex: R 1,234.56)
|
|
90
|
-
ZAR: ["R "
|
|
90
|
+
ZAR: ["R ".concat(commaFormatted), "".concat(commaFormatted), "R"],
|
|
91
91
|
// default
|
|
92
92
|
DEFAULT: [amount.toString(), amount.toString(), ""],
|
|
93
93
|
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-format-currency",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A lightweight international currency formatter for React Native & Expo (iOS and Android).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig-build.json",
|
|
9
|
-
"test": "mocha --reporter spec"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/AwesomeLabs/react-native-format-currency.git"
|
|
9
|
+
"test": "mocha --reporter spec",
|
|
10
|
+
"lint": "eslint . --ext .ts --ext .tsx",
|
|
11
|
+
"lint-fix": "eslint . --ext .ts --ext .tsx --fix"
|
|
14
12
|
},
|
|
13
|
+
"repository": "git+https://github.com/AwesomeLabs/react-native-format-currency.git",
|
|
15
14
|
"author": "Awesome Labs (https://isjustawesome.com)",
|
|
16
15
|
"license": "ISC",
|
|
17
16
|
"keywords": [
|
|
@@ -30,8 +29,21 @@
|
|
|
30
29
|
"homepage": "https://github.com/AwesomeLabs/react-native-format-currency#readme",
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@types/node": "^16.9.0",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
33
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
33
34
|
"chai": "^4.3.4",
|
|
35
|
+
"eslint": "^8.20.0",
|
|
36
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
37
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
38
|
+
"eslint-config-prettier": "^8.5.0",
|
|
39
|
+
"eslint-plugin-import": "^2.26.0",
|
|
40
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
41
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
42
|
+
"eslint-plugin-react": "^7.30.1",
|
|
43
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
44
|
+
"eslint-plugin-react-native": "^4.0.0",
|
|
34
45
|
"mocha": "^9.1.1",
|
|
46
|
+
"prettier": "^2.7.1",
|
|
35
47
|
"typescript": "^4.4.2"
|
|
36
48
|
},
|
|
37
49
|
"dependencies": {}
|