@betterstore/helpers 0.6.13

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.
@@ -0,0 +1,8 @@
1
+ declare function formatCurrency(currency: string): string;
2
+ declare function formatPrice({ priceInCents, currency, exchangeRate, }: {
3
+ priceInCents: number;
4
+ currency: string;
5
+ exchangeRate?: number | null;
6
+ }): string;
7
+
8
+ export { formatCurrency, formatPrice };
@@ -0,0 +1,8 @@
1
+ declare function formatCurrency(currency: string): string;
2
+ declare function formatPrice({ priceInCents, currency, exchangeRate, }: {
3
+ priceInCents: number;
4
+ currency: string;
5
+ exchangeRate?: number | null;
6
+ }): string;
7
+
8
+ export { formatCurrency, formatPrice };
package/dist/index.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ formatCurrency: () => formatCurrency,
24
+ formatPrice: () => formatPrice
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/pricing/index.ts
29
+ var currencyLocales = {
30
+ CZK: "cs-CZ",
31
+ // Czech Koruna
32
+ USD: "en-US",
33
+ // US Dollar
34
+ EUR: "de-DE",
35
+ // Euro (Germany locale)
36
+ GBP: "en-GB",
37
+ // British Pound
38
+ JPY: "ja-JP",
39
+ // Japanese Yen
40
+ AUD: "en-AU",
41
+ // Australian Dollar
42
+ CAD: "en-CA",
43
+ // Canadian Dollar
44
+ NZD: "en-NZ",
45
+ // New Zealand Dollar
46
+ SEK: "sv-SE",
47
+ // Swedish Krona
48
+ NOK: "nb-NO",
49
+ // Norwegian Krone
50
+ DKK: "da-DK",
51
+ // Danish Krone
52
+ CHF: "de-CH",
53
+ // Swiss Franc (German Switzerland)
54
+ HUF: "hu-HU",
55
+ // Hungarian Forint
56
+ PLN: "pl-PL",
57
+ // Polish Zloty
58
+ BGN: "bg-BG",
59
+ // Bulgarian Lev
60
+ RON: "ro-RO",
61
+ // Romanian Leu
62
+ RUB: "ru-RU",
63
+ // Russian Ruble
64
+ CNY: "zh-CN",
65
+ // Chinese Yuan
66
+ INR: "en-IN",
67
+ // Indian Rupee
68
+ BRL: "pt-BR",
69
+ // Brazilian Real
70
+ MXN: "es-MX",
71
+ // Mexican Peso
72
+ ZAR: "en-ZA",
73
+ // South African Rand
74
+ KRW: "ko-KR",
75
+ // South Korean Won
76
+ MYR: "ms-MY",
77
+ // Malaysian Ringgit
78
+ SGD: "en-SG",
79
+ // Singapore Dollar
80
+ TWD: "zh-TW",
81
+ // Taiwanese Dollar
82
+ THB: "th-TH",
83
+ // Thai Baht
84
+ IDR: "id-ID",
85
+ // Indonesian Rupiah
86
+ AED: "ar-AE",
87
+ // UAE Dirham
88
+ SAR: "ar-SA",
89
+ // Saudi Riyal
90
+ TRY: "tr-TR"
91
+ // Turkish Lira
92
+ };
93
+ function formatCurrency(currency) {
94
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
95
+ const formattedCurrency = new Intl.NumberFormat(locale, {
96
+ style: "currency",
97
+ currency,
98
+ currencyDisplay: "symbol"
99
+ });
100
+ return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
101
+ }
102
+ function formatPrice({
103
+ priceInCents,
104
+ currency,
105
+ exchangeRate
106
+ }) {
107
+ const amount = priceInCents / 100 * (exchangeRate ?? 1);
108
+ const isWhole = amount % 1 === 0;
109
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
110
+ const formattedPrice = new Intl.NumberFormat(locale, {
111
+ style: "currency",
112
+ currency,
113
+ currencyDisplay: "symbol",
114
+ minimumFractionDigits: isWhole ? 0 : 2,
115
+ maximumFractionDigits: isWhole ? 0 : 2
116
+ }).format(amount);
117
+ return formattedPrice;
118
+ }
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ formatCurrency,
122
+ formatPrice
123
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,95 @@
1
+ // src/pricing/index.ts
2
+ var currencyLocales = {
3
+ CZK: "cs-CZ",
4
+ // Czech Koruna
5
+ USD: "en-US",
6
+ // US Dollar
7
+ EUR: "de-DE",
8
+ // Euro (Germany locale)
9
+ GBP: "en-GB",
10
+ // British Pound
11
+ JPY: "ja-JP",
12
+ // Japanese Yen
13
+ AUD: "en-AU",
14
+ // Australian Dollar
15
+ CAD: "en-CA",
16
+ // Canadian Dollar
17
+ NZD: "en-NZ",
18
+ // New Zealand Dollar
19
+ SEK: "sv-SE",
20
+ // Swedish Krona
21
+ NOK: "nb-NO",
22
+ // Norwegian Krone
23
+ DKK: "da-DK",
24
+ // Danish Krone
25
+ CHF: "de-CH",
26
+ // Swiss Franc (German Switzerland)
27
+ HUF: "hu-HU",
28
+ // Hungarian Forint
29
+ PLN: "pl-PL",
30
+ // Polish Zloty
31
+ BGN: "bg-BG",
32
+ // Bulgarian Lev
33
+ RON: "ro-RO",
34
+ // Romanian Leu
35
+ RUB: "ru-RU",
36
+ // Russian Ruble
37
+ CNY: "zh-CN",
38
+ // Chinese Yuan
39
+ INR: "en-IN",
40
+ // Indian Rupee
41
+ BRL: "pt-BR",
42
+ // Brazilian Real
43
+ MXN: "es-MX",
44
+ // Mexican Peso
45
+ ZAR: "en-ZA",
46
+ // South African Rand
47
+ KRW: "ko-KR",
48
+ // South Korean Won
49
+ MYR: "ms-MY",
50
+ // Malaysian Ringgit
51
+ SGD: "en-SG",
52
+ // Singapore Dollar
53
+ TWD: "zh-TW",
54
+ // Taiwanese Dollar
55
+ THB: "th-TH",
56
+ // Thai Baht
57
+ IDR: "id-ID",
58
+ // Indonesian Rupiah
59
+ AED: "ar-AE",
60
+ // UAE Dirham
61
+ SAR: "ar-SA",
62
+ // Saudi Riyal
63
+ TRY: "tr-TR"
64
+ // Turkish Lira
65
+ };
66
+ function formatCurrency(currency) {
67
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
68
+ const formattedCurrency = new Intl.NumberFormat(locale, {
69
+ style: "currency",
70
+ currency,
71
+ currencyDisplay: "symbol"
72
+ });
73
+ return formattedCurrency.format(0).replace(/[\d.,\s]/g, "").trim();
74
+ }
75
+ function formatPrice({
76
+ priceInCents,
77
+ currency,
78
+ exchangeRate
79
+ }) {
80
+ const amount = priceInCents / 100 * (exchangeRate ?? 1);
81
+ const isWhole = amount % 1 === 0;
82
+ const locale = currencyLocales[currency.toUpperCase()] ?? void 0;
83
+ const formattedPrice = new Intl.NumberFormat(locale, {
84
+ style: "currency",
85
+ currency,
86
+ currencyDisplay: "symbol",
87
+ minimumFractionDigits: isWhole ? 0 : 2,
88
+ maximumFractionDigits: isWhole ? 0 : 2
89
+ }).format(amount);
90
+ return formattedPrice;
91
+ }
92
+ export {
93
+ formatCurrency,
94
+ formatPrice
95
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@betterstore/helpers",
3
+ "version": "0.6.13",
4
+ "private": false,
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist/**"
11
+ ],
12
+ "devDependencies": {
13
+ "eslint": "^9.29.0",
14
+ "tsup": "^8.4.0",
15
+ "typescript": "5.8.2",
16
+ "@betterstore/eslint-config": "0.0.0",
17
+ "@betterstore/typescript-config": "0.0.0"
18
+ },
19
+ "dependencies": {},
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "tsup src/index.ts --format cjs,esm --dts",
25
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
26
+ "lint": "eslint . --max-warnings 0",
27
+ "check-types": "tsc --noEmit"
28
+ }
29
+ }