d2core
v26.1.1
Published
Core types and utilities library.
Readme
d2core
Framework-agnostic core types and utilities of the Ipesoft D2000 HTML5 UI: localization,
number and date/time formatting, a pre-configured dayjs, D2000 unix time handling and predefined time intervals.
It is the base of d2coreui (React components) and has no UI dependencies.
Installation
npm install d2core dayjsdayjs (1.x) is a peer dependency. The package is published as ES modules with TypeScript declarations.
Usage
There is no index module - import each module by its path. Every exported symbol is documented with JSDoc, so your editor shows the details on hover.
import i18n from "d2core/i18n/i18n";
import {LocaleHolder} from "d2core/i18n/localeHolder";
import {unixTimeToDayJs} from "d2core/types/unixTimeUtils";
await LocaleHolder.setLocale("sk", "sk-SK");
const amount = LocaleHolder.formatNumber(1234.5, 2);
const time = unixTimeToDayJs(1700000000).format(LocaleHolder.getDateTimeFormat(true, true));
const label = i18n("Cancel");Call LocaleHolder.setLocale once at startup, before anything is formatted; until then English defaults are used.
Modules
| Module | Contents |
|---|---|
| d2core/dayjs | dayjs extended with the plugins used across the D2000 UI (isSameOrAfter, isSameOrBefore, localeData, relativeTime, isoWeek, quarterOfYear, localizedFormat, updateLocale) and a custom duration plugin (days-based durations with the DDDDD format, no months/years). Import dayjs from here to get the plugins and their types. |
| d2core/dayjs/duration | The custom duration plugin and its types. |
| d2core/dayjs/ambiguousTime | The plugin of the format tokens for the hour repeated at the end of the daylight saving time: Z? - the UTC offset (as Z) only in that hour, nothing elsewhere; HH? - the hour as HH, but A2 (first occurrence) / B2 (second) in that hour. LocaleHolder.getDateTimeFormat puts them in the mask for the "offsetInFold" / "hourLetter" modes. customParseFormat does not parse them; DateTimeInput does. |
| d2core/i18n/i18n | Global translator (i18n(text), i18n.translator.add(...)) the UI texts are translated with. |
| d2core/i18n/localeHolder | LocaleHolder - current UI language (en, sk, cs, ru, kk, sr, uk), antd/dayjs locale, number formatting and date/time/duration masks. |
| d2core/types/unixTime | UnixTime type and UnixTimeConversionEnum. |
| d2core/types/unixTimeUtils | Conversions between D2000 unix time and Dayjs, D2000UnixTimeNullValue and setUnixTimeConversion. |
| d2core/types/timeInterval | TimeInterval and AlignMode - definition of a predefined time interval. |
| d2core/types/dateTimeIntervals | DateTimeInterval - the predefined intervals by id (HOUR_ACT, DAY_PREV, WEEK_ACT, MONTH_PREV, YEAR_ACT, ...). |
| d2core/types/dataChangeStateEnum | DataChangeStateEnum - kind of change of an item in a D2000 subscription update. |
| d2core/utils/dateTimeUtils | DateTimeUtils - conversions of time periods between Date, Dayjs and unix time, date picker helpers. |
| d2core/utils/timeUtils | TimeUtils.sleep. |
Unix time unit
D2000 unix time values are in seconds by default. An application that works with milliseconds switches the unit once at startup:
import {setUnixTimeConversion} from "d2core/types/unixTimeUtils";
import {UnixTimeConversionEnum} from "d2core/types/unixTime";
setUnixTimeConversion(UnixTimeConversionEnum.FROM_MILIS);The switch reassigns the exported conversion functions, so always call them through the import.
Changelog
See CHANGELOG.md.
