@uxf/localize 11.29.0 → 11.45.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/package.json +28 -28
- package/src/components/format-datetime.js +1 -2
- package/src/components/format-money.js +1 -2
- package/src/components/format-number.js +1 -2
- package/src/components/format-percentage.js +1 -2
- package/src/context/context.d.ts +0 -1
- package/src/context/context.js +1 -0
- package/src/format-datetime/format-datetime.js +2 -3
- package/src/format-money/format-money.js +4 -4
- package/src/format-number/format-number.js +2 -3
- package/src/format-percentage/format-percentage.js +2 -3
- package/src/index.js +1 -2
- package/src/types.d.ts +36 -36
- package/src/utils/curry.d.ts +1 -1
- package/src/utils/curry.js +1 -2
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
2
|
+
"name": "@uxf/localize",
|
|
3
|
+
"version": "11.45.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -P tsconfig.json",
|
|
8
|
+
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"currency.js": "2.0.4",
|
|
20
|
+
"dayjs": "1.11.13"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=18.2.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "18.3.5",
|
|
27
|
+
"react": "18.3.1"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFormatDatetimeComponent =
|
|
6
|
+
exports.createFormatDatetimeComponent = createFormatDatetimeComponent;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_datetime_1 = require("../format-datetime/format-datetime");
|
|
@@ -14,4 +14,3 @@ function createFormatDatetimeComponent(localizeConfigs) {
|
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
17
|
-
exports.createFormatDatetimeComponent = createFormatDatetimeComponent;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFormatMoneyComponent =
|
|
6
|
+
exports.createFormatMoneyComponent = createFormatMoneyComponent;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_money_1 = require("../format-money/format-money");
|
|
@@ -14,4 +14,3 @@ function createFormatMoneyComponent(localizeConfigs) {
|
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
17
|
-
exports.createFormatMoneyComponent = createFormatMoneyComponent;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFormatNumberComponent =
|
|
6
|
+
exports.createFormatNumberComponent = createFormatNumberComponent;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_number_1 = require("../format-number/format-number");
|
|
@@ -14,4 +14,3 @@ function createFormatNumberComponent(localizeConfigs) {
|
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
17
|
-
exports.createFormatNumberComponent = createFormatNumberComponent;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFormatPercentageComponent =
|
|
6
|
+
exports.createFormatPercentageComponent = createFormatPercentageComponent;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const context_1 = require("../context/context");
|
|
9
9
|
const format_percentage_1 = require("../format-percentage/format-percentage");
|
|
@@ -14,4 +14,3 @@ function createFormatPercentageComponent(localizeConfigs) {
|
|
|
14
14
|
};
|
|
15
15
|
return Component;
|
|
16
16
|
}
|
|
17
|
-
exports.createFormatPercentageComponent = createFormatPercentageComponent;
|
package/src/context/context.d.ts
CHANGED
package/src/context/context.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLocaleConfigHook = exports._LocalizeProvider = exports._useLocalizeContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const localizeContext = (0, react_1.createContext)("");
|
|
6
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
6
7
|
const _useLocalizeContext = () => (0, react_1.useContext)(localizeContext);
|
|
7
8
|
exports._useLocalizeContext = _useLocalizeContext;
|
|
8
9
|
exports._LocalizeProvider = localizeContext.Provider;
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createFormatDatetime = createFormatDatetime;
|
|
7
|
+
exports.createUseFormatDatetime = createUseFormatDatetime;
|
|
7
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
9
|
const react_1 = require("react");
|
|
9
10
|
const context_1 = require("../context/context");
|
|
@@ -14,11 +15,9 @@ function createFormatDatetime(localizeConfigs) {
|
|
|
14
15
|
return (0, dayjs_1.default)(value).format(localeDateTimes[format]);
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
|
-
exports.createFormatDatetime = createFormatDatetime;
|
|
18
18
|
function createUseFormatDatetime(localizeConfigs) {
|
|
19
19
|
return () => {
|
|
20
20
|
const locale = (0, context_1._useLocalizeContext)();
|
|
21
21
|
return (0, react_1.useMemo)(() => (0, curry_1._curry)(createFormatDatetime(localizeConfigs))(locale), [locale]);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
exports.createUseFormatDatetime = createUseFormatDatetime;
|
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createFormatMoney = createFormatMoney;
|
|
7
|
+
exports.createUseFormatMoney = createUseFormatMoney;
|
|
8
|
+
const empty_object_1 = require("@uxf/core/constants/empty-object");
|
|
7
9
|
const currency_js_1 = __importDefault(require("currency.js"));
|
|
8
10
|
const react_1 = require("react");
|
|
9
11
|
const context_1 = require("../context/context");
|
|
@@ -24,7 +26,7 @@ function createFormatMoney(localizeConfigs) {
|
|
|
24
26
|
const symbol = money.currency;
|
|
25
27
|
const config = localizeConfigs[locale].currency;
|
|
26
28
|
const specialCasesConfig = config.specialCases;
|
|
27
|
-
const currentPatterns = (_c = (_b = (specialCasesConfig !== null && specialCasesConfig !== void 0 ? specialCasesConfig :
|
|
29
|
+
const currentPatterns = (_c = (_b = (specialCasesConfig !== null && specialCasesConfig !== void 0 ? specialCasesConfig : empty_object_1.EMPTY_OBJECT)[money.currency]) !== null && _b !== void 0 ? _b : money_defaults_1.MoneyDefaults[money.currency]) !== null && _c !== void 0 ? _c : defaultPatterns;
|
|
28
30
|
const patterns = (options === null || options === void 0 ? void 0 : options.hideSymbol)
|
|
29
31
|
? noSymbolPatterns
|
|
30
32
|
: !(options === null || options === void 0 ? void 0 : options.preferIsoCode)
|
|
@@ -40,11 +42,9 @@ function createFormatMoney(localizeConfigs) {
|
|
|
40
42
|
return (0, currency_js_1.default)(money.amount, { precision }).format(formatOptions);
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
|
-
exports.createFormatMoney = createFormatMoney;
|
|
44
45
|
function createUseFormatMoney(localizeConfigs) {
|
|
45
46
|
return () => {
|
|
46
47
|
const locale = (0, context_1._useLocalizeContext)();
|
|
47
48
|
return (0, react_1.useMemo)(() => (0, curry_1._curry)(createFormatMoney(localizeConfigs))(locale), [locale]);
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
|
-
exports.createUseFormatMoney = createUseFormatMoney;
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createFormatNumber = createFormatNumber;
|
|
7
|
+
exports.createUseFormatNumber = createUseFormatNumber;
|
|
7
8
|
const currency_js_1 = __importDefault(require("currency.js"));
|
|
8
9
|
const react_1 = require("react");
|
|
9
10
|
const context_1 = require("../context/context");
|
|
@@ -17,11 +18,9 @@ function createFormatNumber(localizeConfigs) {
|
|
|
17
18
|
return (0, currency_js_1.default)(value, { precision }).format(formatOptions);
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
exports.createFormatNumber = createFormatNumber;
|
|
21
21
|
function createUseFormatNumber(localizeConfigs) {
|
|
22
22
|
return () => {
|
|
23
23
|
const locale = (0, context_1._useLocalizeContext)();
|
|
24
24
|
return (0, react_1.useMemo)(() => (0, curry_1._curry)(createFormatNumber(localizeConfigs))(locale), [locale]);
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
exports.createUseFormatNumber = createUseFormatNumber;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createFormatPercentage = createFormatPercentage;
|
|
4
|
+
exports.createUseFormatPercentage = createUseFormatPercentage;
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const context_1 = require("../context/context");
|
|
6
7
|
const format_number_1 = require("../format-number/format-number");
|
|
@@ -18,11 +19,9 @@ function createFormatPercentage(localizeConfigs) {
|
|
|
18
19
|
return `${(0, format_number_1.createFormatNumber)(localizeConfigs)(locale, percentageValue, options)}\xa0%`;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
exports.createFormatPercentage = createFormatPercentage;
|
|
22
22
|
function createUseFormatPercentage(localizeConfigs) {
|
|
23
23
|
return () => {
|
|
24
24
|
const locale = (0, context_1._useLocalizeContext)();
|
|
25
25
|
return (0, react_1.useMemo)(() => (0, curry_1._curry)(createFormatPercentage(localizeConfigs))(locale), [locale]);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
exports.createUseFormatPercentage = createUseFormatPercentage;
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createLocalize =
|
|
17
|
+
exports.createLocalize = createLocalize;
|
|
18
18
|
const format_datetime_1 = require("./components/format-datetime");
|
|
19
19
|
const format_money_1 = require("./components/format-money");
|
|
20
20
|
const format_number_1 = require("./components/format-number");
|
|
@@ -43,4 +43,3 @@ function createLocalize(config) {
|
|
|
43
43
|
useLocaleConfig: (0, context_1.getLocaleConfigHook)(config),
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
exports.createLocalize = createLocalize;
|
package/src/types.d.ts
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
import { DateValue } from "@uxf/core/date";
|
|
2
2
|
import { FC, Provider } from "react";
|
|
3
3
|
import { CURRENCIES } from "./utils/data";
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
number: {
|
|
7
|
-
thousandsSeparator: string;
|
|
8
|
-
decimalSeparator: string;
|
|
9
|
-
};
|
|
10
|
-
currency: {
|
|
11
|
-
specialCases?: Partial<Record<Currency, FormatMoneyPattern>>;
|
|
12
|
-
thousandsSeparator: string;
|
|
13
|
-
decimalSeparator: string;
|
|
14
|
-
};
|
|
15
|
-
dateTime: Record<DT, string>;
|
|
16
|
-
};
|
|
17
|
-
export type LocalizeConfigMap<DT extends string = DateTimes, Locales extends string = string> = Record<Locales, LocalizeConfig<DT>>;
|
|
18
|
-
export type LocalizeProviderType = Provider<string>;
|
|
19
|
-
export type UseLocaleConfigType<DT extends string> = () => LocalizeConfig<DT>;
|
|
20
|
-
export type Money = {
|
|
21
|
-
amount: string;
|
|
22
|
-
currency: Currency;
|
|
4
|
+
export type FormatNumberOptions = {
|
|
5
|
+
precision?: number;
|
|
23
6
|
};
|
|
24
7
|
export type FormatNumberFunction<Locales extends string> = (locale: Locales, value: number, options?: FormatNumberOptions) => string;
|
|
25
8
|
export type UseFormatNumberFunction = () => (value: number, options?: FormatNumberOptions) => string;
|
|
@@ -27,12 +10,30 @@ export type FormatNumberComponent = FC<{
|
|
|
27
10
|
value: number;
|
|
28
11
|
options?: FormatNumberOptions;
|
|
29
12
|
}>;
|
|
13
|
+
export type Currency = keyof typeof CURRENCIES;
|
|
14
|
+
export type FormatMoneyPattern = {
|
|
15
|
+
pattern: string;
|
|
16
|
+
negativePattern: string;
|
|
17
|
+
};
|
|
18
|
+
export type FormatMoneyOptions = {
|
|
19
|
+
hideSymbol?: boolean;
|
|
20
|
+
precision?: number;
|
|
21
|
+
preferIsoCode?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type Money = {
|
|
24
|
+
amount: string;
|
|
25
|
+
currency: Currency;
|
|
26
|
+
};
|
|
30
27
|
export type FormatMoneyFunction<Locales extends string> = (locale: Locales, money: Money, options?: FormatMoneyOptions) => string;
|
|
31
28
|
export type UseFormatMoneyFunction = () => (money: Money, options?: FormatMoneyOptions) => string;
|
|
32
29
|
export type FormatMoneyComponent = FC<{
|
|
33
30
|
money: Money;
|
|
34
31
|
options?: FormatMoneyOptions;
|
|
35
32
|
}>;
|
|
33
|
+
export type RoundingType = "nearest" | "up" | "down";
|
|
34
|
+
export type FormatPercentageOptions = {
|
|
35
|
+
precision?: number;
|
|
36
|
+
};
|
|
36
37
|
export type FormatPercentageFunction<Locales extends string> = (locale: Locales, value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
37
38
|
export type UseFormatPercentageFunction = () => (value: number, roundingType?: RoundingType | null, options?: FormatPercentageOptions) => string;
|
|
38
39
|
export type FormatPercentageComponent = FC<{
|
|
@@ -40,12 +41,28 @@ export type FormatPercentageComponent = FC<{
|
|
|
40
41
|
roundingType?: RoundingType | null;
|
|
41
42
|
options?: FormatPercentageOptions;
|
|
42
43
|
}>;
|
|
44
|
+
export type DateTimes = "timeShort" | "timeFull" | "dateShort" | "dateMedium" | "dateLong" | "dateShortNoYear" | "dateLongNoYear" | "dateTimeShort" | "dateTimeMedium" | "dateTimeLong";
|
|
43
45
|
export type FormatDatetimeFunction<DT extends string, Locales extends string> = (locale: Locales, value: DateValue, format: DT) => string;
|
|
44
46
|
export type UseFormatDatetimeFunction<DT extends string> = () => (value: DateValue, format: DT) => string;
|
|
45
47
|
export type FormatDatetimeComponent<DT extends string> = FC<{
|
|
46
48
|
value: DateValue;
|
|
47
49
|
format: DT;
|
|
48
50
|
}>;
|
|
51
|
+
export type LocalizeConfig<DT extends string> = {
|
|
52
|
+
number: {
|
|
53
|
+
thousandsSeparator: string;
|
|
54
|
+
decimalSeparator: string;
|
|
55
|
+
};
|
|
56
|
+
currency: {
|
|
57
|
+
specialCases?: Partial<Record<Currency, FormatMoneyPattern>>;
|
|
58
|
+
thousandsSeparator: string;
|
|
59
|
+
decimalSeparator: string;
|
|
60
|
+
};
|
|
61
|
+
dateTime: Record<DT, string>;
|
|
62
|
+
};
|
|
63
|
+
export type LocalizeConfigMap<DT extends string = DateTimes, Locales extends string = string> = Record<Locales, LocalizeConfig<DT>>;
|
|
64
|
+
export type LocalizeProviderType = Provider<string>;
|
|
65
|
+
export type UseLocaleConfigType<DT extends string> = () => LocalizeConfig<DT>;
|
|
49
66
|
export type CreateLocalizeReturn<DT extends string, Locales extends string> = {
|
|
50
67
|
LocalizeProvider: LocalizeProviderType;
|
|
51
68
|
useLocaleConfig: UseLocaleConfigType<DT>;
|
|
@@ -62,20 +79,3 @@ export type CreateLocalizeReturn<DT extends string, Locales extends string> = {
|
|
|
62
79
|
useFormatDateTime: UseFormatDatetimeFunction<DT>;
|
|
63
80
|
FormatDateTime: FormatDatetimeComponent<DT>;
|
|
64
81
|
};
|
|
65
|
-
export type Currency = keyof typeof CURRENCIES;
|
|
66
|
-
export type FormatMoneyOptions = {
|
|
67
|
-
hideSymbol?: boolean;
|
|
68
|
-
precision?: number;
|
|
69
|
-
preferIsoCode?: boolean;
|
|
70
|
-
};
|
|
71
|
-
export type FormatMoneyPattern = {
|
|
72
|
-
pattern: string;
|
|
73
|
-
negativePattern: string;
|
|
74
|
-
};
|
|
75
|
-
export type FormatNumberOptions = {
|
|
76
|
-
precision?: number;
|
|
77
|
-
};
|
|
78
|
-
export type RoundingType = "nearest" | "up" | "down";
|
|
79
|
-
export type FormatPercentageOptions = {
|
|
80
|
-
precision?: number;
|
|
81
|
-
};
|
package/src/utils/curry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type CurryFunction<T extends any[], R> = (arg1: T[0]) => (...rest: Tail<T>) => R;
|
|
2
1
|
type Tail<T extends any[]> = T extends [any, ...infer U] ? U : never;
|
|
2
|
+
type CurryFunction<T extends any[], R> = (arg1: T[0]) => (...rest: Tail<T>) => R;
|
|
3
3
|
export declare function _curry<T extends any[], R>(fn: (...args: T) => R): CurryFunction<T, R>;
|
|
4
4
|
export {};
|
package/src/utils/curry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._curry =
|
|
3
|
+
exports._curry = _curry;
|
|
4
4
|
function _curry(fn) {
|
|
5
5
|
return (arg1) => {
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -8,4 +8,3 @@ function _curry(fn) {
|
|
|
8
8
|
return (...rest) => fn(arg1, ...rest);
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
exports._curry = _curry;
|