@churchapps/helpers 1.2.28 → 1.2.29
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/dist/CurrencyHelper.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare class CurrencyHelper {
|
|
2
|
+
static loadCurrency: () => Promise<any>;
|
|
2
3
|
static formatCurrency(amount: number): string;
|
|
3
|
-
static formatCurrencyWithLocale(amount: number, currency?: string): string;
|
|
4
|
+
static formatCurrencyWithLocale(amount: number, currency?: string, fractionDigits?: number): string;
|
|
4
5
|
static getCurrencySymbol(currency?: string): any;
|
|
5
6
|
private static getLocaleForCurrency;
|
|
6
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyHelper.d.ts","sourceRoot":"","sources":["../src/CurrencyHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CurrencyHelper.d.ts","sourceRoot":"","sources":["../src/CurrencyHelper.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IACzB,MAAM,CAAC,YAAY,qBAIjB;IAEF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM;IAUpC,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAc,EAAE,cAAc,GAAE,MAAU;IAmBpG,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM;IAsB1C,OAAO,CAAC,MAAM,CAAC,oBAAoB;CAqBpC"}
|
package/dist/CurrencyHelper.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { ApiHelper } from "./ApiHelper.js";
|
|
1
2
|
export class CurrencyHelper {
|
|
3
|
+
static loadCurrency = async () => {
|
|
4
|
+
const gateways = await ApiHelper.get("/gateways", "GivingApi");
|
|
5
|
+
if (gateways.length === 0)
|
|
6
|
+
return "usd";
|
|
7
|
+
return gateways[0].currency || "usd";
|
|
8
|
+
};
|
|
2
9
|
static formatCurrency(amount) {
|
|
3
10
|
const formatter = new Intl.NumberFormat("en-US", {
|
|
4
11
|
style: "currency",
|
|
@@ -7,15 +14,20 @@ export class CurrencyHelper {
|
|
|
7
14
|
});
|
|
8
15
|
return formatter.format(amount);
|
|
9
16
|
}
|
|
10
|
-
static formatCurrencyWithLocale(amount, currency = "
|
|
17
|
+
static formatCurrencyWithLocale(amount, currency = "usd", fractionDigits = 2) {
|
|
18
|
+
const symbol = this.getCurrencySymbol(currency);
|
|
11
19
|
const normalizedCurrency = currency.toUpperCase();
|
|
12
20
|
const locale = this.getLocaleForCurrency(normalizedCurrency);
|
|
13
21
|
const formatter = new Intl.NumberFormat(locale, {
|
|
14
22
|
style: "currency",
|
|
15
23
|
currency: normalizedCurrency,
|
|
16
|
-
|
|
24
|
+
currencyDisplay: "code",
|
|
25
|
+
minimumFractionDigits: fractionDigits,
|
|
26
|
+
maximumFractionDigits: fractionDigits,
|
|
17
27
|
});
|
|
18
|
-
|
|
28
|
+
// replace the currency code with the symbol
|
|
29
|
+
const formattedAmount = formatter.format(amount);
|
|
30
|
+
return formattedAmount.replace(normalizedCurrency, symbol);
|
|
19
31
|
}
|
|
20
32
|
static getCurrencySymbol(currency) {
|
|
21
33
|
const normalizedCurrency = currency?.toLowerCase() || "usd";
|
|
@@ -23,8 +35,8 @@ export class CurrencyHelper {
|
|
|
23
35
|
usd: { percent: 2.9, fixed: 0.3, symbol: "$" },
|
|
24
36
|
eur: { percent: 2.9, fixed: 0.25, symbol: "€" },
|
|
25
37
|
gbp: { percent: 2.9, fixed: 0.2, symbol: "£" },
|
|
26
|
-
cad: { percent: 2.9, fixed: 0.3, symbol: "
|
|
27
|
-
aud: { percent: 2.9, fixed: 0.3, symbol: "
|
|
38
|
+
cad: { percent: 2.9, fixed: 0.3, symbol: "C$" },
|
|
39
|
+
aud: { percent: 2.9, fixed: 0.3, symbol: "A$" },
|
|
28
40
|
inr: { percent: 2.9, fixed: 3.0, symbol: "₹" },
|
|
29
41
|
jpy: { percent: 2.9, fixed: 30.0, symbol: "¥" },
|
|
30
42
|
sgd: { percent: 2.9, fixed: 0.5, symbol: "S$" },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyHelper.js","sourceRoot":"","sources":["../src/CurrencyHelper.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,cAAc,CAAC,MAAc;QAClC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YAC/C,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrencyHelper.js","sourceRoot":"","sources":["../src/CurrencyHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,cAAc;IACzB,MAAM,CAAC,YAAY,GAAG,KAAK,IAAI,EAAE;QAC/B,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC/D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC;IACvC,CAAC,CAAC;IAEF,MAAM,CAAC,cAAc,CAAC,MAAc;QAClC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YAC/C,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,KAAK;YACf,qBAAqB,EAAE,CAAC;SACzB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAGD,MAAM,CAAC,w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