@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 CHANGED
@@ -54,8 +54,12 @@ const en: LocalizeConfig<DateTimes> = {
54
54
  currency: {
55
55
  thousandsSeparator: ",",
56
56
  decimalSeparator: ".",
57
- pattern: "!#",
58
- negativePattern: "-!#",
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
- pattern: "#\xa0!",
83
- negativePattern: "-#\xa0!",
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
- pattern: "#\xa0!",
12
- negativePattern: "-#\xa0!",
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
@@ -8,8 +8,6 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: ".",
10
10
  decimalSeparator: ",",
11
- pattern: "! #",
12
- negativePattern: "-! #",
13
11
  },
14
12
  dateTime: {
15
13
  timeShort: "H:mm",
package/locale/en.js CHANGED
@@ -8,8 +8,6 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: ",",
10
10
  decimalSeparator: ".",
11
- pattern: "!#",
12
- negativePattern: "-!#",
13
11
  },
14
12
  dateTime: {
15
13
  timeShort: "H:mm A",
package/locale/es.js CHANGED
@@ -8,8 +8,6 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: ".",
10
10
  decimalSeparator: ",",
11
- pattern: "! #",
12
- negativePattern: "-! #",
13
11
  },
14
12
  dateTime: {
15
13
  timeShort: "H:mm",
package/locale/fr.js CHANGED
@@ -8,8 +8,12 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: " ",
10
10
  decimalSeparator: ",",
11
- pattern: "! #",
12
- negativePattern: "-! #",
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
@@ -8,8 +8,6 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: " ",
10
10
  decimalSeparator: ",",
11
- pattern: "# !",
12
- negativePattern: "-# !",
13
11
  },
14
12
  dateTime: {
15
13
  timeShort: "HH:mm",
package/locale/sk.js CHANGED
@@ -8,8 +8,12 @@ const locale = {
8
8
  currency: {
9
9
  thousandsSeparator: "\xa0",
10
10
  decimalSeparator: ",",
11
- pattern: "#\xa0!",
12
- negativePattern: "-#\xa0!",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/localize",
3
- "version": "11.11.3",
3
+ "version": "11.13.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 data_1 = require("../utils/data");
12
- const map_options_1 = require("../utils/map-options");
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 = (options === null || options === void 0 ? void 0 : options.preferIsoCode) ? money.currency : data_1.CURRENCIES[money.currency].symbol;
18
- const formatOptions = { ...(0, map_options_1._mapOptions)(localizeConfigs[locale].currency), precision, symbol };
19
- if (options === null || options === void 0 ? void 0 : options.hideSymbol) {
20
- formatOptions.pattern = (_b = formatOptions.pattern) === null || _b === void 0 ? void 0 : _b.replace("!", "").trim();
21
- formatOptions.negativePattern = (_c = formatOptions.negativePattern) === null || _c === void 0 ? void 0 : _c.replace("!", "").trim();
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("2,001");
23
- expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1 })).toBe("2,000.8");
24
- expect(formatMoneyWithLocales("en", { amount: "2000.78", currency: "CZK" }, { precision: 1, preferIsoCode: true })).toBe("CZK2,000.8");
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("USD2,000.8");
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"] | LocalizeConfig<DateTimes>["currency"]) => currencyjs.Options;
3
+ export declare const _mapOptions: (options: LocalizeConfig<DateTimes>["number"]) => currencyjs.Options;
@@ -5,8 +5,8 @@ const _mapOptions = (options) => {
5
5
  return {
6
6
  separator: options.thousandsSeparator,
7
7
  decimal: options.decimalSeparator,
8
- pattern: "pattern" in options ? options.pattern : "#",
9
- negativePattern: "negativePattern" in options ? options.negativePattern : "-#",
8
+ pattern: "#",
9
+ negativePattern: "-#",
10
10
  };
11
11
  };
12
12
  exports._mapOptions = _mapOptions;
@@ -0,0 +1,2 @@
1
+ import { Currency, FormatMoneyPattern } from "../types";
2
+ export declare const MoneyDefaults: Partial<Record<Currency, FormatMoneyPattern>>;
@@ -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
+ };