@synerise/ds-core 1.11.0 → 1.11.1
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/CHANGELOG.md +4 -0
- package/dist/i18n/{en.json → en.json.d.ts} +4 -2
- package/dist/i18n/en.json.js +8 -0
- package/dist/i18n/{es.json → es.json.d.ts} +4 -2
- package/dist/i18n/es.json.js +8 -0
- package/dist/i18n/index.js +14 -11
- package/dist/i18n/{pl.json → pl.json.d.ts} +4 -2
- package/dist/i18n/pl.json.js +8 -0
- package/dist/i18n/{pt.json → pt.json.d.ts} +4 -2
- package/dist/i18n/pt.json.js +8 -0
- package/dist/js/DSProvider/DSProvider.d.ts +5 -6
- package/dist/js/DSProvider/DSProvider.js +36 -31
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.d.ts +2 -2
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.js +29 -38
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.types.d.ts +3 -3
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.types.js +1 -1
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.d.ts +1 -1
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.js +22 -19
- package/dist/js/DSProvider/LocaleProvider/antLocales.d.ts +6 -6
- package/dist/js/DSProvider/LocaleProvider/antLocales.js +16 -13
- package/dist/js/DSProvider/LocaleProvider/index.js +4 -1
- package/dist/js/DSProvider/ThemeProvider/ThemeProvider.d.ts +2 -2
- package/dist/js/DSProvider/ThemeProvider/ThemeProvider.js +14 -12
- package/dist/js/DSProvider/ThemeProvider/breakpoints.js +5 -2
- package/dist/js/DSProvider/ThemeProvider/index.js +4 -1
- package/dist/js/DSProvider/ThemeProvider/theme.d.ts +1 -1
- package/dist/js/DSProvider/ThemeProvider/theme.js +17 -17
- package/dist/js/DSProvider/ThemeProvider/variables.d.ts +8 -0
- package/dist/js/DSProvider/ThemeProvider/variables.js +531 -530
- package/dist/js/DSProvider/index.js +4 -1
- package/dist/js/DropdownContext/DropdownContext/DropdownContextProvider.d.ts +2 -2
- package/dist/js/DropdownContext/DropdownContext/DropdownContextProvider.js +11 -11
- package/dist/js/DropdownContext/DropdownContext.d.ts +1 -1
- package/dist/js/DropdownContext/DropdownContext.js +5 -2
- package/dist/js/DropdownContext/DropdownContextProvider.d.ts +2 -2
- package/dist/js/DropdownContext/DropdownContextProvider.js +11 -11
- package/dist/js/DropdownContext/index.js +8 -3
- package/dist/js/DropdownContext/useDropdown.d.ts +1 -1
- package/dist/js/DropdownContext/useDropdown.js +7 -4
- package/dist/js/data-format/components/FormattedDate.d.ts +4 -4
- package/dist/js/data-format/components/FormattedDate.js +23 -9
- package/dist/js/data-format/components/FormattedDateTime.d.ts +4 -4
- package/dist/js/data-format/components/FormattedDateTime.js +26 -12
- package/dist/js/data-format/components/FormattedNumber.d.ts +2 -2
- package/dist/js/data-format/components/FormattedNumber.js +23 -9
- package/dist/js/data-format/components/FormattedRelativeDateTime.d.ts +3 -3
- package/dist/js/data-format/components/FormattedRelativeDateTime.js +40 -21
- package/dist/js/data-format/components/FormattedTime.d.ts +4 -4
- package/dist/js/data-format/components/FormattedTime.js +26 -12
- package/dist/js/data-format/components/index.js +13 -5
- package/dist/js/data-format/constants/dataFormat.constants.d.ts +2 -2
- package/dist/js/data-format/constants/dataFormat.constants.js +85 -49
- package/dist/js/data-format/constants/dataFormatConfig.constants.d.ts +2 -2
- package/dist/js/data-format/constants/dataFormatConfig.constants.js +15 -8
- package/dist/js/data-format/constants/dateTimeParts.constants.d.ts +1 -1
- package/dist/js/data-format/constants/dateTimeParts.constants.js +10 -4
- package/dist/js/data-format/constants/index.js +48 -3
- package/dist/js/data-format/contexts/DataFormatConfigContext.d.ts +2 -2
- package/dist/js/data-format/contexts/DataFormatConfigContext.js +6 -3
- package/dist/js/data-format/contexts/DataFormatIntlsContext.d.ts +2 -2
- package/dist/js/data-format/contexts/DataFormatIntlsContext.js +7 -4
- package/dist/js/data-format/contexts/index.js +6 -2
- package/dist/js/data-format/hocs/withDataFormat.d.ts +2 -2
- package/dist/js/data-format/hocs/withDataFormat.js +23 -9
- package/dist/js/data-format/hooks/index.js +14 -6
- package/dist/js/data-format/hooks/useDataFormat.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormat.js +93 -90
- package/dist/js/data-format/hooks/useDataFormatConfig.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormatConfig.js +8 -4
- package/dist/js/data-format/hooks/useDataFormatIntls.d.ts +1 -1
- package/dist/js/data-format/hooks/useDataFormatIntls.js +8 -4
- package/dist/js/data-format/hooks/useDataFormatUtils.d.ts +4 -4
- package/dist/js/data-format/hooks/useDataFormatUtils.js +62 -63
- package/dist/js/data-format/hooks/useRelativeDateTimeUpdate.d.ts +2 -2
- package/dist/js/data-format/hooks/useRelativeDateTimeUpdate.js +19 -23
- package/dist/js/data-format/hooks/useSingleIntl.d.ts +1 -1
- package/dist/js/data-format/hooks/useSingleIntl.js +11 -8
- package/dist/js/data-format/index.js +83 -7
- package/dist/js/data-format/providers/DataFormatConfigProvider.d.ts +2 -2
- package/dist/js/data-format/providers/DataFormatConfigProvider.js +37 -26
- package/dist/js/data-format/types/dataFormat.types.d.ts +3 -3
- package/dist/js/data-format/types/dataFormat.types.js +1 -5
- package/dist/js/data-format/types/dataFormatConfig.types.d.ts +1 -1
- package/dist/js/data-format/types/dataFormatConfig.types.js +1 -2
- package/dist/js/data-format/types/dateTimeParts.types.js +1 -2
- package/dist/js/data-format/types/index.js +1 -1
- package/dist/js/data-format/utils/dataFormat.utils.d.ts +2 -2
- package/dist/js/data-format/utils/dataFormat.utils.js +82 -67
- package/dist/js/data-format/utils/dataFormatConfig.utils.d.ts +1 -1
- package/dist/js/data-format/utils/dataFormatConfig.utils.js +9 -8
- package/dist/js/data-format/utils/date.utils.d.ts +2 -2
- package/dist/js/data-format/utils/date.utils.js +25 -21
- package/dist/js/data-format/utils/dateTimeParts.utils.d.ts +2 -2
- package/dist/js/data-format/utils/dateTimeParts.utils.js +68 -52
- package/dist/js/data-format/utils/index.js +41 -5
- package/dist/js/data-format/utils/timeZone.utils.d.ts +1 -1
- package/dist/js/data-format/utils/timeZone.utils.js +59 -51
- package/dist/js/index.js +112 -7
- package/dist/js/mediaQuery/mediaQuery.d.ts +2 -2
- package/dist/js/mediaQuery/mediaQuery.js +15 -25
- package/dist/js/style.d.ts +0 -2
- package/dist/js/style.js +1 -2
- package/dist/js/testing/index.js +6 -2
- package/dist/js/testing/renderWithProvider/renderWithProvider.d.ts +4 -4
- package/dist/js/testing/renderWithProvider/renderWithProvider.js +35 -27
- package/dist/js/testing/sleep.js +6 -8
- package/dist/js/toaster/Toaster.d.ts +1 -1
- package/dist/js/toaster/Toaster.js +12 -8
- package/dist/js/toaster/Toaster.types.js +1 -1
- package/dist/js/toaster/constants.d.ts +1 -1
- package/dist/js/toaster/constants.js +7 -4
- package/dist/js/toaster/contexts/ToasterContext.d.ts +2 -2
- package/dist/js/toaster/contexts/ToasterContext.js +9 -5
- package/dist/js/toaster/hooks/useToaster.d.ts +1 -1
- package/dist/js/toaster/hooks/useToaster.js +7 -4
- package/dist/js/toaster/index.js +12 -5
- package/dist/js/toaster/providers/ToasterProvider.d.ts +2 -2
- package/dist/js/toaster/providers/ToasterProvider.js +17 -17
- package/package.json +4 -4
- package/dist/js/testing/renderWithProvider/renderWithProvider.spec.d.ts +0 -1
- package/dist/style/colors.less +0 -137
- package/dist/style/config.less +0 -521
- package/dist/style/core.less +0 -55
- package/dist/style/variables.less +0 -2
- /package/dist/{style/variables.css → assets/style/core-tn0RQdqM.css} +0 -0
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var UNDER_22_HOURS = 22 * 60 * 60 * 1000;
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
const getIntervalForTimeDifference = (timeDiffMs) => {
|
|
3
|
+
const UNDER_45_MINUTES = 45 * 60 * 1e3;
|
|
4
|
+
const UNDER_22_HOURS = 22 * 60 * 60 * 1e3;
|
|
6
5
|
if (timeDiffMs < UNDER_45_MINUTES) {
|
|
7
|
-
return 60 *
|
|
6
|
+
return 60 * 1e3;
|
|
8
7
|
}
|
|
9
8
|
if (timeDiffMs < UNDER_22_HOURS) {
|
|
10
|
-
return 60 * 60 *
|
|
9
|
+
return 60 * 60 * 1e3;
|
|
11
10
|
}
|
|
12
|
-
return null;
|
|
11
|
+
return null;
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
setUpdateTrigger = _useState[1];
|
|
18
|
-
useEffect(function () {
|
|
13
|
+
const useRelativeDateTimeUpdate = (value) => {
|
|
14
|
+
const [updateTrigger, setUpdateTrigger] = useState(0);
|
|
15
|
+
useEffect(() => {
|
|
19
16
|
if (!(value instanceof Date)) {
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const timeDiffMs = Math.abs(value.getTime() - Date.now());
|
|
20
|
+
const interval = getIntervalForTimeDifference(timeDiffMs);
|
|
24
21
|
if (interval === null) {
|
|
25
22
|
return;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
setUpdateTrigger(
|
|
29
|
-
return prev + 1;
|
|
30
|
-
});
|
|
24
|
+
const timeoutId = setTimeout(() => {
|
|
25
|
+
setUpdateTrigger((prev) => prev + 1);
|
|
31
26
|
}, interval);
|
|
32
|
-
return
|
|
33
|
-
return clearTimeout(timeoutId);
|
|
34
|
-
};
|
|
27
|
+
return () => clearTimeout(timeoutId);
|
|
35
28
|
}, [value, updateTrigger]);
|
|
36
29
|
return updateTrigger;
|
|
37
|
-
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
useRelativeDateTimeUpdate
|
|
33
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
locale
|
|
1
|
+
import { createIntlCache, useIntl, createIntl } from "react-intl";
|
|
2
|
+
const useSingleIntl = (locale) => {
|
|
3
|
+
const cache = createIntlCache();
|
|
4
|
+
const globalIntl = useIntl();
|
|
5
|
+
const intl = createIntl({
|
|
6
|
+
locale,
|
|
7
7
|
timeZone: globalIntl.timeZone
|
|
8
8
|
}, cache);
|
|
9
9
|
return {
|
|
10
|
-
intl
|
|
10
|
+
intl
|
|
11
11
|
};
|
|
12
|
-
};
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
useSingleIntl
|
|
15
|
+
};
|
|
@@ -1,7 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { DataFormatConfigProvider } from "./providers/DataFormatConfigProvider.js";
|
|
2
|
+
import { FormattedDate } from "./components/FormattedDate.js";
|
|
3
|
+
import { FormattedDateTime } from "./components/FormattedDateTime.js";
|
|
4
|
+
import { FormattedNumber } from "./components/FormattedNumber.js";
|
|
5
|
+
import { FormattedTime } from "./components/FormattedTime.js";
|
|
6
|
+
import { FormattedRelativeDateTimeFrom, FormattedRelativeDateTimeTo } from "./components/FormattedRelativeDateTime.js";
|
|
7
|
+
import { useDataFormatConfig } from "./hooks/useDataFormatConfig.js";
|
|
8
|
+
import { useDataFormat } from "./hooks/useDataFormat.js";
|
|
9
|
+
import { useDataFormatUtils } from "./hooks/useDataFormatUtils.js";
|
|
10
|
+
import "react-intl";
|
|
11
|
+
import { useDataFormatIntls } from "./hooks/useDataFormatIntls.js";
|
|
12
|
+
import "react";
|
|
13
|
+
import { withDataFormat } from "./hocs/withDataFormat.js";
|
|
14
|
+
import { getDataFormatConfigFromNotation } from "./utils/dataFormatConfig.utils.js";
|
|
15
|
+
import { DEFAULT_DATA_FORMAT_CONFIG, DEFAULT_DATA_FORMAT_INTL, DEFAULT_DATA_FORMAT_NOTATION, EU_NOTATION, US_NOTATION } from "./constants/dataFormatConfig.constants.js";
|
|
16
|
+
import { COMPACT_DECIMAL_LARGER_NUMBER, COMPACT_LARGER_NUMBER, DATE, DATETIME, DATE_CONSTANTS_TARGET_FORMATS, DEFAULT_FORMAT_DATE_OPTIONS, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DEFAULT_FORMAT_NUMBER_OPTIONS, DEFAULT_FORMAT_TIME_OPTIONS, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, EU_DECIMAL_DELIMITER, EU_THOUSAND_DELIMITER, LARGER_NUMBER_LIMIT, LOWER_CASE, LOWER_FIRST, MONTHS_LONG, MONTHS_SHORT, MONTH_LONG, MONTH_SHORT, RELATIVE_FROM, RELATIVE_FROM_WITHOUT_SUFFIX, RELATIVE_TO, RELATIVE_TO_WITHOUT_SUFFIX, TIME, UPPER_CASE, UPPER_FIRST, US_DECIMAL_DELIMITER, US_THOUSAND_DELIMITER, WEEKDAYS_LONG, WEEKDAYS_SHORT, WEEKDAY_LONG, WEEKDAY_SHORT } from "./constants/dataFormat.constants.js";
|
|
17
|
+
import { LONG, MONTH, SHORT, WEEKDAY } from "./constants/dateTimeParts.constants.js";
|
|
18
|
+
import "./utils/timeZone.utils.js";
|
|
19
|
+
import { getDefaultDataTimeOptions } from "./utils/dataFormat.utils.js";
|
|
20
|
+
import "dayjs";
|
|
21
|
+
import { DataFormatConfigContext } from "./contexts/DataFormatConfigContext.js";
|
|
22
|
+
import { DataFormatIntlsContext } from "./contexts/DataFormatIntlsContext.js";
|
|
23
|
+
export {
|
|
24
|
+
COMPACT_DECIMAL_LARGER_NUMBER,
|
|
25
|
+
COMPACT_LARGER_NUMBER,
|
|
26
|
+
DATE,
|
|
27
|
+
DATETIME,
|
|
28
|
+
DATE_CONSTANTS_TARGET_FORMATS,
|
|
29
|
+
DEFAULT_DATA_FORMAT_CONFIG,
|
|
30
|
+
DEFAULT_DATA_FORMAT_INTL,
|
|
31
|
+
DEFAULT_DATA_FORMAT_NOTATION,
|
|
32
|
+
DEFAULT_FORMAT_DATE_OPTIONS,
|
|
33
|
+
DEFAULT_FORMAT_MONTH_LONG_OPTIONS,
|
|
34
|
+
DEFAULT_FORMAT_MONTH_SHORT_OPTIONS,
|
|
35
|
+
DEFAULT_FORMAT_NUMBER_OPTIONS,
|
|
36
|
+
DEFAULT_FORMAT_TIME_OPTIONS,
|
|
37
|
+
DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS,
|
|
38
|
+
DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS,
|
|
39
|
+
DataFormatConfigContext,
|
|
40
|
+
DataFormatConfigProvider,
|
|
41
|
+
DataFormatIntlsContext,
|
|
42
|
+
EU_DECIMAL_DELIMITER,
|
|
43
|
+
EU_NOTATION,
|
|
44
|
+
EU_THOUSAND_DELIMITER,
|
|
45
|
+
FormattedDate,
|
|
46
|
+
FormattedDateTime,
|
|
47
|
+
FormattedNumber,
|
|
48
|
+
FormattedRelativeDateTimeFrom,
|
|
49
|
+
FormattedRelativeDateTimeTo,
|
|
50
|
+
FormattedTime,
|
|
51
|
+
LARGER_NUMBER_LIMIT,
|
|
52
|
+
LONG,
|
|
53
|
+
LOWER_CASE,
|
|
54
|
+
LOWER_FIRST,
|
|
55
|
+
MONTH,
|
|
56
|
+
MONTHS_LONG,
|
|
57
|
+
MONTHS_SHORT,
|
|
58
|
+
MONTH_LONG,
|
|
59
|
+
MONTH_SHORT,
|
|
60
|
+
RELATIVE_FROM,
|
|
61
|
+
RELATIVE_FROM_WITHOUT_SUFFIX,
|
|
62
|
+
RELATIVE_TO,
|
|
63
|
+
RELATIVE_TO_WITHOUT_SUFFIX,
|
|
64
|
+
SHORT,
|
|
65
|
+
TIME,
|
|
66
|
+
UPPER_CASE,
|
|
67
|
+
UPPER_FIRST,
|
|
68
|
+
US_DECIMAL_DELIMITER,
|
|
69
|
+
US_NOTATION,
|
|
70
|
+
US_THOUSAND_DELIMITER,
|
|
71
|
+
WEEKDAY,
|
|
72
|
+
WEEKDAYS_LONG,
|
|
73
|
+
WEEKDAYS_SHORT,
|
|
74
|
+
WEEKDAY_LONG,
|
|
75
|
+
WEEKDAY_SHORT,
|
|
76
|
+
getDataFormatConfigFromNotation,
|
|
77
|
+
getDefaultDataTimeOptions,
|
|
78
|
+
useDataFormat,
|
|
79
|
+
useDataFormatConfig,
|
|
80
|
+
useDataFormatIntls,
|
|
81
|
+
useDataFormatUtils,
|
|
82
|
+
withDataFormat
|
|
83
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React,
|
|
2
|
-
import {
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { DataFormatConfig } from '../types';
|
|
3
3
|
export type DataFormatConfigProviderProps = {
|
|
4
4
|
dataFormatConfig?: DataFormatConfig;
|
|
5
5
|
children?: ReactNode;
|
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DEFAULT_DATA_FORMAT_CONFIG } from
|
|
3
|
-
import { DataFormatConfigContext
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DEFAULT_DATA_FORMAT_CONFIG } from "../constants/dataFormatConfig.constants.js";
|
|
3
|
+
import { DataFormatConfigContext } from "../contexts/DataFormatConfigContext.js";
|
|
4
|
+
import { DataFormatIntlsContext } from "../contexts/DataFormatIntlsContext.js";
|
|
5
|
+
import "react";
|
|
6
|
+
import "dayjs";
|
|
7
|
+
import "moment";
|
|
8
|
+
import "../utils/timeZone.utils.js";
|
|
9
|
+
import "../utils/dataFormat.utils.js";
|
|
10
|
+
import { useDataFormatUtils } from "../hooks/useDataFormatUtils.js";
|
|
11
|
+
import { useSingleIntl } from "../hooks/useSingleIntl.js";
|
|
12
|
+
const DataFormatConfigProvider = ({
|
|
13
|
+
dataFormatConfig: dataFormatConfigFromProps,
|
|
14
|
+
children
|
|
15
|
+
}) => {
|
|
16
|
+
const dataFormatConfig = dataFormatConfigFromProps ?? DEFAULT_DATA_FORMAT_CONFIG;
|
|
17
|
+
const {
|
|
18
|
+
getLocaleFromNotation
|
|
19
|
+
} = useDataFormatUtils();
|
|
20
|
+
const {
|
|
21
|
+
intl: numberFormatIntl
|
|
22
|
+
} = useSingleIntl(getLocaleFromNotation(dataFormatConfig?.numberFormatNotation));
|
|
23
|
+
const {
|
|
24
|
+
intl: dateFormatIntl
|
|
25
|
+
} = useSingleIntl(getLocaleFromNotation(dataFormatConfig?.dateFormatNotation));
|
|
26
|
+
const {
|
|
27
|
+
intl: timeFormatIntl
|
|
28
|
+
} = useSingleIntl(getLocaleFromNotation(dataFormatConfig?.timeFormatNotation));
|
|
29
|
+
return /* @__PURE__ */ jsx(DataFormatIntlsContext.Provider, { value: {
|
|
30
|
+
numberFormatIntl,
|
|
31
|
+
dateFormatIntl,
|
|
32
|
+
timeFormatIntl
|
|
33
|
+
}, children: /* @__PURE__ */ jsx(DataFormatConfigContext.Provider, { value: dataFormatConfig, children }) });
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
DataFormatConfigProvider
|
|
37
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Dayjs, default as dayjs } from 'dayjs';
|
|
2
|
+
import { Moment } from 'moment';
|
|
3
|
+
import { FormatDateOptions, FormatNumberOptions, FormatPluralOptions } from 'react-intl';
|
|
4
4
|
declare const _DATE_TARGET_FORMATS: readonly ["date", "datetime", "relative-from", "relative-to", "relative-from-without-suffix", "relative-to-without-suffix", "time", "weekday-long", "weekday-short", "month-long", "month-short"];
|
|
5
5
|
export type DateTargetFormat = (typeof _DATE_TARGET_FORMATS)[number];
|
|
6
6
|
declare const _NUMBER_TARGET_FORMATS: readonly ["compact-larger-number", "compact-decimal-larger-number"];
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var _NUMBER_TARGET_FORMATS = ['compact-larger-number', 'compact-decimal-larger-number'];
|
|
3
|
-
var _NAMING_CONVENTIONS = ['upperCase', 'upperFirst', 'lowerCase', 'lowerFirst'];
|
|
4
|
-
var _DELIMITERS = [',', '.', ' '];
|
|
5
|
-
export {};
|
|
1
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IntlShape } from 'react-intl';
|
|
2
2
|
declare const _DATA_FORMAT_NOTATION_TYPES: readonly ["US", "EU"];
|
|
3
3
|
export type DataFormatNotationType = (typeof _DATA_FORMAT_NOTATION_TYPES)[number];
|
|
4
4
|
export type DataFormatConfig = {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export {};
|
|
1
|
+
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export {};
|
|
1
|
+
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IntlShape } from 'react-intl';
|
|
2
|
+
import { CommonFormatOptions, DateToFormatOptions, Delimiter, NumberToFormatOptions } from '../types';
|
|
3
3
|
export declare const convertNumberString: (value: number, numberFormatIntl: IntlShape, languageIntl: IntlShape, thousandDelimiter: Delimiter, decimalDelimiter: Delimiter, numberOptions?: NumberToFormatOptions) => string;
|
|
4
4
|
export declare const convertDateToDateTimeString: (value: Date, dateFormatIntl: IntlShape, timeFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
5
5
|
export declare const convertDateToRelativeToString: (value: Date, withoutSuffix?: boolean) => string;
|
|
@@ -1,98 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import relativeTimePlugin from "dayjs/plugin/relativeTime";
|
|
3
|
+
import "../constants/dataFormatConfig.constants.js";
|
|
4
|
+
import { UPPER_FIRST, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DATETIME, DATE, LOWER_FIRST, LOWER_CASE, UPPER_CASE, COMPACT_LARGER_NUMBER, LARGER_NUMBER_LIMIT, COMPACT_DECIMAL_LARGER_NUMBER, DEFAULT_FORMAT_NUMBER_OPTIONS } from "../constants/dataFormat.constants.js";
|
|
5
|
+
import { getDateParts, translateDateTimeParts, dateTimePartsToString, getTimeParts, getMonthLongDateParts, getDateTimePartsSubset, getMonthShortDateParts, getWeekdayLongDateParts, getWeekdayShortDateParts, numberPartsToString } from "./dateTimeParts.utils.js";
|
|
6
6
|
dayjs.extend(relativeTimePlugin);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (updatedNumberOptions
|
|
7
|
+
const convertNumberString = (value, numberFormatIntl, languageIntl, thousandDelimiter, decimalDelimiter, numberOptions) => {
|
|
8
|
+
const updatedNumberOptions = numberOptions;
|
|
9
|
+
if (updatedNumberOptions?.pluralOptions) {
|
|
10
10
|
return numberFormatIntl.formatPlural(value, updatedNumberOptions);
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
12
|
+
if (updatedNumberOptions?.targetFormat === COMPACT_LARGER_NUMBER && value > LARGER_NUMBER_LIMIT) {
|
|
13
13
|
if (!updatedNumberOptions.notation) {
|
|
14
|
-
updatedNumberOptions.notation =
|
|
14
|
+
updatedNumberOptions.notation = "compact";
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
17
|
+
if (updatedNumberOptions?.targetFormat === COMPACT_DECIMAL_LARGER_NUMBER && value > LARGER_NUMBER_LIMIT) {
|
|
18
18
|
if (!updatedNumberOptions.notation) {
|
|
19
|
-
updatedNumberOptions.notation =
|
|
19
|
+
updatedNumberOptions.notation = "compact";
|
|
20
20
|
}
|
|
21
21
|
if (!updatedNumberOptions.minimumFractionDigits && updatedNumberOptions.minimumFractionDigits !== 0) {
|
|
22
22
|
updatedNumberOptions.minimumFractionDigits = 1;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
const numberParts = languageIntl.formatNumberToParts(value, {
|
|
26
|
+
...DEFAULT_FORMAT_NUMBER_OPTIONS,
|
|
27
|
+
...updatedNumberOptions
|
|
28
|
+
});
|
|
26
29
|
return numberPartsToString(numberParts, thousandDelimiter, decimalDelimiter);
|
|
27
30
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return date
|
|
31
|
+
const convertDateToDateTimeString = (value, dateFormatIntl, timeFormatIntl, languageIntl, options) => {
|
|
32
|
+
const dateParts = getDateParts(value, dateFormatIntl, options?.dateOptions);
|
|
33
|
+
const datePartsByLanguageIntl = getDateParts(value, languageIntl, options?.dateOptions);
|
|
34
|
+
const translatedDateParts = translateDateTimeParts(dateParts, datePartsByLanguageIntl, options);
|
|
35
|
+
const date = dateTimePartsToString(translatedDateParts);
|
|
36
|
+
const time = dateTimePartsToString(getTimeParts(value, timeFormatIntl, options?.timeOptions));
|
|
37
|
+
return `${date}, ${time}`;
|
|
35
38
|
};
|
|
36
|
-
|
|
39
|
+
const convertDateToRelativeToString = (value, withoutSuffix) => {
|
|
37
40
|
return dayjs().to(dayjs(value), withoutSuffix);
|
|
38
41
|
};
|
|
39
|
-
|
|
42
|
+
const convertDateToRelativeFromString = (value, withoutSuffix) => {
|
|
40
43
|
return dayjs().from(dayjs(value), withoutSuffix);
|
|
41
44
|
};
|
|
42
|
-
|
|
45
|
+
const convertDateToTimeString = (value, timeFormatIntl, options) => {
|
|
43
46
|
return dateTimePartsToString(getTimeParts(value, timeFormatIntl, options));
|
|
44
47
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const convertDateToDateString = (value, dateFormatIntl, languageIntl, options) => {
|
|
49
|
+
const dateParts = getDateParts(value, dateFormatIntl, options);
|
|
50
|
+
const datePartsByLanguageIntl = getDateParts(value, languageIntl, options);
|
|
51
|
+
const translatedDateParts = translateDateTimeParts(dateParts, datePartsByLanguageIntl, options);
|
|
49
52
|
return dateTimePartsToString(translatedDateParts);
|
|
50
53
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const convertDateToWeekdayLongString = (value, dateFormatIntl, languageIntl, options) => {
|
|
55
|
+
const weekdayLongDateParts = getWeekdayLongDateParts(value, dateFormatIntl, options);
|
|
56
|
+
const weekdayLongDatePartsByLanguageIntl = getWeekdayLongDateParts(value, languageIntl, options);
|
|
57
|
+
const translatedDateTimeParts = translateDateTimeParts(weekdayLongDateParts, weekdayLongDatePartsByLanguageIntl, options);
|
|
58
|
+
const reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ["weekday"]);
|
|
56
59
|
return dateTimePartsToString(reducedDateTimeParts);
|
|
57
60
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const convertDateToWeekdayShortString = (value, dateFormatIntl, languageIntl, options) => {
|
|
62
|
+
const weekdayShortDateParts = getWeekdayShortDateParts(value, dateFormatIntl, options);
|
|
63
|
+
const weekdayShortDatePartsByLanguageIntl = getWeekdayShortDateParts(value, languageIntl, options);
|
|
64
|
+
const translatedDateTimeParts = translateDateTimeParts(weekdayShortDateParts, weekdayShortDatePartsByLanguageIntl, options);
|
|
65
|
+
const reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ["weekday"]);
|
|
63
66
|
return dateTimePartsToString(reducedDateTimeParts);
|
|
64
67
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const convertDateToMonthLongString = (value, dateFormatIntl, languageIntl, options) => {
|
|
69
|
+
const monthLongDateParts = getMonthLongDateParts(value, dateFormatIntl, options);
|
|
70
|
+
const monthLongDatePartsByLanguageIntl = getMonthLongDateParts(value, languageIntl, options);
|
|
71
|
+
const translatedDateTimeParts = translateDateTimeParts(monthLongDateParts, monthLongDatePartsByLanguageIntl, options);
|
|
72
|
+
const reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ["month"]);
|
|
70
73
|
return dateTimePartsToString(reducedDateTimeParts);
|
|
71
74
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const convertDateToMonthShortString = (value, dateFormatIntl, languageIntl, options) => {
|
|
76
|
+
const monthShortDateParts = getMonthShortDateParts(value, dateFormatIntl, options);
|
|
77
|
+
const monthShortDatePartsByLanguageIntl = getMonthShortDateParts(value, languageIntl, options);
|
|
78
|
+
const translatedDateTimeParts = translateDateTimeParts(monthShortDateParts, monthShortDatePartsByLanguageIntl, options);
|
|
79
|
+
const reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ["month"]);
|
|
77
80
|
return dateTimePartsToString(reducedDateTimeParts);
|
|
78
81
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (options
|
|
82
|
-
result =
|
|
82
|
+
const addPrefix = (value, options) => {
|
|
83
|
+
let result = value;
|
|
84
|
+
if (options?.prefix) {
|
|
85
|
+
result = options?.prefix + result;
|
|
83
86
|
}
|
|
84
87
|
return result;
|
|
85
88
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (options
|
|
89
|
-
result += options
|
|
89
|
+
const addSuffix = (value, options) => {
|
|
90
|
+
let result = value;
|
|
91
|
+
if (options?.suffix) {
|
|
92
|
+
result += options?.suffix;
|
|
90
93
|
}
|
|
91
94
|
return result;
|
|
92
95
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
switch (options
|
|
96
|
+
const changeNamingConvention = (value, options) => {
|
|
97
|
+
let result = value;
|
|
98
|
+
switch (options?.namingConvention) {
|
|
96
99
|
case UPPER_CASE:
|
|
97
100
|
result = result.toUpperCase();
|
|
98
101
|
break;
|
|
@@ -105,15 +108,27 @@ export var changeNamingConvention = function changeNamingConvention(value, optio
|
|
|
105
108
|
case LOWER_FIRST:
|
|
106
109
|
result = result.charAt(0).toLowerCase() + result.slice(1);
|
|
107
110
|
break;
|
|
108
|
-
default:
|
|
109
|
-
break;
|
|
110
111
|
}
|
|
111
112
|
return result;
|
|
112
113
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
const getDefaultDataTimeOptions = (showTime) => ({
|
|
115
|
+
targetFormat: showTime ? DATETIME : DATE,
|
|
116
|
+
dateOptions: DEFAULT_FORMAT_MONTH_SHORT_OPTIONS,
|
|
117
|
+
namingConvention: UPPER_FIRST
|
|
118
|
+
});
|
|
119
|
+
export {
|
|
120
|
+
addPrefix,
|
|
121
|
+
addSuffix,
|
|
122
|
+
changeNamingConvention,
|
|
123
|
+
convertDateToDateString,
|
|
124
|
+
convertDateToDateTimeString,
|
|
125
|
+
convertDateToMonthLongString,
|
|
126
|
+
convertDateToMonthShortString,
|
|
127
|
+
convertDateToRelativeFromString,
|
|
128
|
+
convertDateToRelativeToString,
|
|
129
|
+
convertDateToTimeString,
|
|
130
|
+
convertDateToWeekdayLongString,
|
|
131
|
+
convertDateToWeekdayShortString,
|
|
132
|
+
convertNumberString,
|
|
133
|
+
getDefaultDataTimeOptions
|
|
134
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataFormatConfig, DataFormatNotationType } from '../types';
|
|
2
2
|
export declare const getDataFormatConfigFromNotation: (notation: DataFormatNotationType) => DataFormatConfig;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const getDataFormatConfigFromNotation = (notation) => ({
|
|
2
|
+
startWeekDayNotation: notation,
|
|
3
|
+
dateFormatNotation: notation,
|
|
4
|
+
timeFormatNotation: notation,
|
|
5
|
+
numberFormatNotation: notation
|
|
6
|
+
});
|
|
7
|
+
export {
|
|
8
|
+
getDataFormatConfigFromNotation
|
|
9
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import {
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
|
+
import { DateConstantsTargetFormat, DateToFormatOptions } from '../types';
|
|
3
3
|
export declare const getDatesRange: (start: Date, end: Date, interval: dayjs.UnitType) => Date[];
|
|
4
4
|
export declare const isValidDate: (date: Date) => boolean;
|
|
5
5
|
export declare const getConstantDatesAndFormattingOptions: (targetFormat: DateConstantsTargetFormat, isSundayFirstWeekDay: boolean, customStartDate?: Date, customEndDate?: Date, customInterval?: dayjs.UnitType) => {
|
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import "../constants/dataFormatConfig.constants.js";
|
|
3
|
+
import { WEEKDAYS_SHORT, WEEKDAYS_LONG, MONTHS_SHORT, MONTHS_LONG, MONTH_LONG, UPPER_FIRST, WEEKDAY_SHORT, WEEKDAY_LONG, MONTH_SHORT } from "../constants/dataFormat.constants.js";
|
|
4
|
+
const getDatesRange = (start, end, interval) => {
|
|
5
|
+
const startDate = dayjs(start);
|
|
6
|
+
const endDate = dayjs(end);
|
|
7
|
+
const diffInUnits = endDate.diff(startDate, interval);
|
|
8
|
+
return Array.from(Array(diffInUnits + 1).keys()).map((i) => {
|
|
8
9
|
return startDate.add(i, interval).toDate();
|
|
9
10
|
});
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
+
const isValidDate = (date) => {
|
|
12
13
|
return !isNaN(date.getTime());
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const getConstantDatesAndFormattingOptions = (targetFormat, isSundayFirstWeekDay, customStartDate, customEndDate, customInterval) => {
|
|
16
|
+
const startDate = new Date(2023, 0, isSundayFirstWeekDay ? 1 : 2);
|
|
17
|
+
const endDate = new Date(2023, 0, isSundayFirstWeekDay ? 1 : 2);
|
|
18
|
+
let defaultTargetFormat = MONTH_LONG;
|
|
19
|
+
let interval = "month";
|
|
19
20
|
switch (targetFormat) {
|
|
20
21
|
case MONTHS_LONG:
|
|
21
22
|
endDate.setMonth(11);
|
|
22
|
-
interval =
|
|
23
|
+
interval = "month";
|
|
23
24
|
defaultTargetFormat = MONTH_LONG;
|
|
24
25
|
break;
|
|
25
26
|
case MONTHS_SHORT:
|
|
26
27
|
endDate.setMonth(11);
|
|
27
|
-
interval =
|
|
28
|
+
interval = "month";
|
|
28
29
|
defaultTargetFormat = MONTH_SHORT;
|
|
29
30
|
break;
|
|
30
31
|
case WEEKDAYS_LONG:
|
|
31
32
|
endDate.setDate(isSundayFirstWeekDay ? 7 : 8);
|
|
32
|
-
interval =
|
|
33
|
+
interval = "day";
|
|
33
34
|
defaultTargetFormat = WEEKDAY_LONG;
|
|
34
35
|
break;
|
|
35
36
|
case WEEKDAYS_SHORT:
|
|
36
37
|
endDate.setDate(isSundayFirstWeekDay ? 7 : 8);
|
|
37
|
-
interval =
|
|
38
|
+
interval = "day";
|
|
38
39
|
defaultTargetFormat = WEEKDAY_SHORT;
|
|
39
40
|
break;
|
|
40
|
-
default:
|
|
41
|
-
break;
|
|
42
41
|
}
|
|
43
42
|
return {
|
|
44
|
-
constantDates: getDatesRange(customStartDate
|
|
43
|
+
constantDates: getDatesRange(customStartDate ?? startDate, customEndDate ?? endDate, customInterval ?? interval),
|
|
45
44
|
defaultOptions: {
|
|
46
45
|
namingConvention: UPPER_FIRST,
|
|
47
46
|
targetFormat: defaultTargetFormat
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
|
-
};
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
getConstantDatesAndFormattingOptions,
|
|
52
|
+
getDatesRange,
|
|
53
|
+
isValidDate
|
|
54
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FormatDateOptions, IntlShape } from 'react-intl';
|
|
2
|
+
import { DateToFormatOptions, Delimiter } from '../types';
|
|
3
3
|
export declare const getDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
4
4
|
export declare const getTimeParts: (value: Date, timeFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
5
5
|
export declare const getWeekdayLongDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|