@uxf/localize 11.11.3 → 11.13.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 +12 -4
- package/locale/cs.js +10 -2
- package/locale/de.js +0 -2
- package/locale/en.js +0 -2
- package/locale/es.js +0 -2
- package/locale/fr.js +6 -2
- package/locale/pl.js +0 -2
- package/locale/sk.js +6 -2
- package/package.json +1 -1
- package/src/format-money/format-money.js +25 -8
- package/src/format-money/format-money.test.js +4 -4
- package/src/types.d.ts +5 -2
- package/src/utils/map-options.d.ts +1 -1
- package/src/utils/map-options.js +2 -2
- package/src/utils/money-defaults.d.ts +2 -0
- package/src/utils/money-defaults.js +13 -0
package/README.md
CHANGED
|
@@ -54,8 +54,12 @@ const en: LocalizeConfig<DateTimes> = {
|
|
|
54
54
|
currency: {
|
|
55
55
|
thousandsSeparator: ",",
|
|
56
56
|
decimalSeparator: ".",
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
specialCases: {
|
|
58
|
+
USD: {
|
|
59
|
+
pattern: "#\xa0$",
|
|
60
|
+
negativePattern: "-$\xa0$",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
59
63
|
},
|
|
60
64
|
dateTime: {
|
|
61
65
|
timeShort: "H:mm A",
|
|
@@ -79,8 +83,12 @@ const cs: LocalizeConfig<DateTimes> = {
|
|
|
79
83
|
currency: {
|
|
80
84
|
thousandsSeparator: "\xa0",
|
|
81
85
|
decimalSeparator: ",",
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
specialCases: {
|
|
87
|
+
CZK: {
|
|
88
|
+
pattern: "#\xa0Kč",
|
|
89
|
+
negativePattern: "-#\xa0Kč",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
84
92
|
},
|
|
85
93
|
dateTime: {
|
|
86
94
|
timeShort: "H:mm",
|
package/locale/cs.js
CHANGED
|
@@ -8,8 +8,16 @@ const locale = {
|
|
|
8
8
|
currency: {
|
|
9
9
|
thousandsSeparator: "\xa0",
|
|
10
10
|
decimalSeparator: ",",
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
specialCases: {
|
|
12
|
+
CZK: {
|
|
13
|
+
pattern: "#\xa0Kč",
|
|
14
|
+
negativePattern: "-#\xa0Kč",
|
|
15
|
+
},
|
|
16
|
+
USD: {
|
|
17
|
+
pattern: "#\xa0$",
|
|
18
|
+
negativePattern: "-$\xa0$",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
13
21
|
},
|
|
14
22
|
dateTime: {
|
|
15
23
|
timeShort: "H:mm",
|
package/locale/de.js
CHANGED
package/locale/en.js
CHANGED
package/locale/es.js
CHANGED
package/locale/fr.js
CHANGED
|
@@ -8,8 +8,12 @@ const locale = {
|
|
|
8
8
|
currency: {
|
|
9
9
|
thousandsSeparator: " ",
|
|
10
10
|
decimalSeparator: ",",
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
specialCases: {
|
|
12
|
+
EUR: {
|
|
13
|
+
pattern: "€#",
|
|
14
|
+
negativePattern: "-€#",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
13
17
|
},
|
|
14
18
|
dateTime: {
|
|
15
19
|
timeShort: "HH:mm",
|
package/locale/pl.js
CHANGED
package/locale/sk.js
CHANGED
|
@@ -8,8 +8,12 @@ const locale = {
|
|
|
8
8
|
currency: {
|
|
9
9
|
thousandsSeparator: "\xa0",
|
|
10
10
|
decimalSeparator: ",",
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
specialCases: {
|
|
12
|
+
CZK: {
|
|
13
|
+
pattern: "#\xa0Kč",
|
|
14
|
+
negativePattern: "-#\xa0Kč",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
13
17
|
},
|
|
14
18
|
dateTime: {
|
|
15
19
|
timeShort: "H:mm",
|
package/package.json
CHANGED
|
@@ -8,18 +8,35 @@ const currency_js_1 = __importDefault(require("currency.js"));
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const context_1 = require("../context/context");
|
|
10
10
|
const curry_1 = require("../utils/curry");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const money_defaults_1 = require("../utils/money-defaults");
|
|
12
|
+
const defaultPatterns = {
|
|
13
|
+
pattern: "#\xa0!",
|
|
14
|
+
negativePattern: "-#\xa0!",
|
|
15
|
+
};
|
|
16
|
+
const noSymbolPatterns = {
|
|
17
|
+
pattern: "#",
|
|
18
|
+
negativePattern: "-#",
|
|
19
|
+
};
|
|
13
20
|
function createFormatMoney(localizeConfigs) {
|
|
14
21
|
return (locale, money, options) => {
|
|
15
22
|
var _a, _b, _c;
|
|
16
23
|
const precision = (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 0;
|
|
17
|
-
const symbol =
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const symbol = money.currency;
|
|
25
|
+
const config = localizeConfigs[locale].currency;
|
|
26
|
+
const specialCasesConfig = config.specialCases;
|
|
27
|
+
const currentPatterns = (_c = (_b = (specialCasesConfig !== null && specialCasesConfig !== void 0 ? specialCasesConfig : {})[money.currency]) !== null && _b !== void 0 ? _b : money_defaults_1.MoneyDefaults[money.currency]) !== null && _c !== void 0 ? _c : defaultPatterns;
|
|
28
|
+
const patterns = (options === null || options === void 0 ? void 0 : options.hideSymbol)
|
|
29
|
+
? noSymbolPatterns
|
|
30
|
+
: !(options === null || options === void 0 ? void 0 : options.preferIsoCode)
|
|
31
|
+
? currentPatterns
|
|
32
|
+
: defaultPatterns;
|
|
33
|
+
const formatOptions = {
|
|
34
|
+
...patterns,
|
|
35
|
+
decimal: config.decimalSeparator,
|
|
36
|
+
separator: config.thousandsSeparator,
|
|
37
|
+
precision,
|
|
38
|
+
symbol,
|
|
39
|
+
};
|
|
23
40
|
return (0, currency_js_1.default)(money.amount, { precision }).format(formatOptions);
|
|
24
41
|
};
|
|
25
42
|
}
|
|
@@ -19,13 +19,13 @@ describe("money formatter", function () {
|
|
|
19
19
|
expect(formatMoneyWithLocales("cs", { amount: "2000.78", currency: "USD" }, { precision: 1, hideSymbol: true })).toBe("2\xa0000,8");
|
|
20
20
|
});
|
|
21
21
|
it("format money with 'en' locale", function () {
|
|
22
|
-
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" })).toBe("
|
|
23
|
-
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1 })).toBe("
|
|
24
|
-
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1, preferIsoCode: true })).toBe("
|
|
22
|
+
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" })).toBe("2,001\xa0CZK");
|
|
23
|
+
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1 })).toBe("2,000.8\xa0CZK");
|
|
24
|
+
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1, preferIsoCode: true })).toBe("2,000.8\xa0CZK");
|
|
25
25
|
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1, hideSymbol: true })).toBe("2,000.8");
|
|
26
26
|
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "USD" })).toBe("$2,001");
|
|
27
27
|
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "USD" }, { precision: 1 })).toBe("$2,000.8");
|
|
28
|
-
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "USD" }, { precision: 1, preferIsoCode: true })).toBe("
|
|
28
|
+
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "USD" }, { precision: 1, preferIsoCode: true })).toBe("2,000.8\xa0USD");
|
|
29
29
|
expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "USD" }, { precision: 1, hideSymbol: true })).toBe("2,000.8");
|
|
30
30
|
});
|
|
31
31
|
});
|
package/src/types.d.ts
CHANGED
|
@@ -7,10 +7,9 @@ export type LocalizeConfig<DT extends string> = {
|
|
|
7
7
|
decimalSeparator: string;
|
|
8
8
|
};
|
|
9
9
|
currency: {
|
|
10
|
+
specialCases?: Partial<Record<Currency, FormatMoneyPattern>>;
|
|
10
11
|
thousandsSeparator: string;
|
|
11
12
|
decimalSeparator: string;
|
|
12
|
-
pattern: string;
|
|
13
|
-
negativePattern: string;
|
|
14
13
|
};
|
|
15
14
|
dateTime: Record<DT, string>;
|
|
16
15
|
};
|
|
@@ -71,6 +70,10 @@ export type FormatMoneyOptions = {
|
|
|
71
70
|
precision?: number;
|
|
72
71
|
preferIsoCode?: boolean;
|
|
73
72
|
};
|
|
73
|
+
export type FormatMoneyPattern = {
|
|
74
|
+
pattern: string;
|
|
75
|
+
negativePattern: string;
|
|
76
|
+
};
|
|
74
77
|
export type FormatNumberOptions = {
|
|
75
78
|
precision?: number;
|
|
76
79
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import currencyjs from "currency.js";
|
|
2
2
|
import { DateTimes, LocalizeConfig } from "../types";
|
|
3
|
-
export declare const _mapOptions: (options: LocalizeConfig<DateTimes>["number"]
|
|
3
|
+
export declare const _mapOptions: (options: LocalizeConfig<DateTimes>["number"]) => currencyjs.Options;
|
package/src/utils/map-options.js
CHANGED
|
@@ -5,8 +5,8 @@ const _mapOptions = (options) => {
|
|
|
5
5
|
return {
|
|
6
6
|
separator: options.thousandsSeparator,
|
|
7
7
|
decimal: options.decimalSeparator,
|
|
8
|
-
pattern: "
|
|
9
|
-
negativePattern: "
|
|
8
|
+
pattern: "#",
|
|
9
|
+
negativePattern: "-#",
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
exports._mapOptions = _mapOptions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MoneyDefaults = void 0;
|
|
4
|
+
exports.MoneyDefaults = {
|
|
5
|
+
EUR: {
|
|
6
|
+
pattern: "#\xa0€",
|
|
7
|
+
negativePattern: "-#\xa0€",
|
|
8
|
+
},
|
|
9
|
+
USD: {
|
|
10
|
+
pattern: "$#",
|
|
11
|
+
negativePattern: "-$#",
|
|
12
|
+
},
|
|
13
|
+
};
|