@inzombieland/core 1.18.35 → 1.18.37

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.
@@ -3,7 +3,6 @@ export { useActiveSessions } from "./use-active-sessions";
3
3
  export { useApiActions } from "./use-api-actions";
4
4
  export { useAppLocale } from "./use-app-locale";
5
5
  export { useCookies } from "./use-cookies";
6
- export { useDayjs } from "./use-dayjs";
7
6
  export { useSubscribe } from "./use-subscribe";
8
7
  export { useThemeMode } from "./use-theme-mode";
9
8
  export { useUser } from "./use-user";
@@ -3,7 +3,6 @@ export { useActiveSessions } from "./use-active-sessions.mjs";
3
3
  export { useApiActions } from "./use-api-actions.mjs";
4
4
  export { useAppLocale } from "./use-app-locale.mjs";
5
5
  export { useCookies } from "./use-cookies.mjs";
6
- export { useDayjs } from "./use-dayjs.mjs";
7
6
  export { useSubscribe } from "./use-subscribe.mjs";
8
7
  export { useThemeMode } from "./use-theme-mode.mjs";
9
8
  export { useUser } from "./use-user.mjs";
@@ -1,4 +1,4 @@
1
- import { dateHelper } from "./date-helper.mjs";
1
+ import { dateHelper } from "./date-helper";
2
2
  const isoExp = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/gm;
3
3
  const isISODate = (value) => {
4
4
  return typeof value === "string" && isoExp.test(value);
@@ -1,5 +1,4 @@
1
1
  export { useApiHelper } from "./api-helper";
2
- export { useDateHelper } from "./date-helper";
3
2
  export { useDevice } from "./device-helper";
4
3
  export { usePhoneHelper } from "./phone-helper";
5
4
  export { useStringHelper } from "./string-helper";
@@ -1,5 +1,4 @@
1
1
  export { useApiHelper } from "./api-helper.mjs";
2
- export { useDateHelper } from "./date-helper.mjs";
3
2
  export { useDevice } from "./device-helper.mjs";
4
3
  export { usePhoneHelper } from "./phone-helper.mjs";
5
4
  export { useStringHelper } from "./string-helper.mjs";
package/helpers/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  export { apiHelper } from "./api-helper.mjs";
2
- export { dateHelper } from "./date-helper.mjs";
2
+ export { dateHelper } from "./date-helper";
3
3
  export { deviceHelper } from "./device-helper.mjs";
4
4
  export { phoneHelper } from "./phone-helper.mjs";
5
5
  export { stringHelper } from "./string-helper.mjs";
@@ -1,10 +1,7 @@
1
1
  import { StyleProvider, Themes, Locale as VarletLocale } from "@varlet/ui";
2
- import dayjs from "dayjs";
3
- import localizedFormat from "dayjs/plugin/localizedFormat";
4
- import relativeTime from "dayjs/plugin/relativeTime";
5
2
  import { setNotifyDefaultOptions, Locale as VantLocale } from "vant";
6
- import VantLocaleEnUS from "vant/es/locale/lang/en-US";
7
- import VantLocaleRuRU from "vant/es/locale/lang/ru-RU";
3
+ import enUS from "vant/es/locale/lang/en-US";
4
+ import ruRU from "vant/es/locale/lang/ru-RU";
8
5
  import { watch } from "vue";
9
6
  import { useI18n } from "vue-i18n";
10
7
  import { useRouter } from "vue-router";
@@ -57,7 +54,14 @@ function initApplication() {
57
54
  if ("setLocale" in i18n && typeof i18n.setLocale === "function") {
58
55
  i18n.setLocale(locale2?.value);
59
56
  }
60
- loadThirdPartyLocales(locale2?.value);
57
+ if (locale2?.value === "en") {
58
+ VantLocale.use("en-US", enUS);
59
+ VarletLocale.add("en-US", VarletLocale.enUS);
60
+ }
61
+ if (locale2?.value === "ru") {
62
+ VantLocale.use("ru-RU", ruRU);
63
+ VarletLocale.add("en-US", VarletLocale.enUS);
64
+ }
61
65
  const localeCookie = useCookies("locale", { maxAge: 60 * 60 * 24 * 365 });
62
66
  localeCookie.value = locale2?.value;
63
67
  },
@@ -91,39 +95,6 @@ function initApplication() {
91
95
  }
92
96
  });
93
97
  }
94
- function loadThirdPartyLocales(locale) {
95
- loadVantLocale(locale);
96
- loadVarletLocale(locale);
97
- loadDayjsLocale(locale);
98
- }
99
- function loadVantLocale(locale) {
100
- if (locale === "en") {
101
- VantLocale.use("en-US", VantLocaleEnUS);
102
- }
103
- if (locale === "ru") {
104
- VantLocale.use("ru-RU", VantLocaleRuRU);
105
- }
106
- }
107
- function loadVarletLocale(locale) {
108
- if (locale === "en") {
109
- VarletLocale.add("en-US", VarletLocale.enUS);
110
- }
111
- if (locale === "ru") {
112
- VarletLocale.add("en-US", VarletLocale.enUS);
113
- }
114
- }
115
- async function loadDayjsLocale(lang) {
116
- let locale;
117
- if (lang === "en") {
118
- locale = await import("dayjs/locale/en");
119
- }
120
- if (lang === "ru") {
121
- locale = await import("dayjs/locale/ru");
122
- }
123
- dayjs.locale(locale);
124
- dayjs.extend(localizedFormat);
125
- dayjs.extend(relativeTime);
126
- }
127
98
  export const createInitApplication = once(() => {
128
99
  return () => initApplication();
129
100
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/core",
3
- "version": "1.18.35",
3
+ "version": "1.18.37",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "main": "./index.mjs",
@@ -15,7 +15,6 @@
15
15
  "@vueuse/core": "^12.8.2",
16
16
  "centrifuge": "^5.3.4",
17
17
  "cookie-es": "^2.0.0",
18
- "dayjs": "^1.11.13",
19
18
  "destr": "^2.0.5",
20
19
  "klona": "^2.0.6",
21
20
  "ofetch": "^1.4.1",
@@ -1,2 +0,0 @@
1
- import dayjs from "dayjs";
2
- export declare const useDayjs: () => typeof dayjs;
@@ -1,4 +0,0 @@
1
- import dayjs from "dayjs";
2
- export const useDayjs = () => {
3
- return dayjs;
4
- };
@@ -1,19 +0,0 @@
1
- export declare function stringToDate(dateString: unknown): Date | undefined;
2
- /**
3
- * Преобразование даты.
4
- * Например из "d mmmm:R yyyy" в "5 февраля 2020"
5
- * @param date - дата
6
- * @param format - формат даты
7
- * @param locale
8
- * @param dateTimeNow
9
- */
10
- export declare function dateFormat(// @SONAR_STOP@
11
- date?: Date, format?: string, locale?: string, dateTimeNow?: Date): string;
12
- export declare const dateHelper: {
13
- stringToDate: typeof stringToDate;
14
- dateFormat: typeof dateFormat;
15
- };
16
- export declare const useDateHelper: () => {
17
- stringToDate: typeof stringToDate;
18
- dateFormat: typeof dateFormat;
19
- };
@@ -1,233 +0,0 @@
1
- const isoExp = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/;
2
- export function stringToDate(dateString) {
3
- if (typeof dateString === "string") {
4
- if (dateString === "0001-01-01T00:00:00Z") {
5
- return;
6
- }
7
- let date = new Date(Number.NaN);
8
- const parts = isoExp.exec(dateString);
9
- if (parts) {
10
- date = parts.at(-1) === "Z" ? new Date(
11
- Date.UTC(
12
- Number(parts[1]),
13
- Number(parts[2]) - 1,
14
- Number(parts[3]),
15
- Number(parts[4]),
16
- Number(parts[5]),
17
- Number(parts[6])
18
- )
19
- ) : new Date(
20
- Number(parts[1]),
21
- Number(parts[2]) - 1,
22
- Number(parts[3]),
23
- Number(parts[4]),
24
- Number(parts[5]),
25
- Number(parts[6])
26
- );
27
- }
28
- return date;
29
- }
30
- return void 0;
31
- }
32
- const masks = {
33
- default: "dd mmm yyyy",
34
- "default:R": "dd mmmm:R yyyy",
35
- "default:RC": "dd mmmm:R yyyy:C",
36
- defaultshortday: "d mmm yyyy",
37
- "defaultshortday:C": "d mmm yyyy:C",
38
- "defaultshortday:R": "d mmmm:R yyyy",
39
- "defaultshortday:RC": "d mmmm:R yyyy:C",
40
- shortDate: "m/d/yy",
41
- mediumDate: "mmm d, yyyy",
42
- longDate: "mmmm d, yyyy",
43
- fullDate: "dddd, mmmm d, yyyy",
44
- shortTime: "h:MM TT",
45
- mediumTime: "h:MM:ss TT",
46
- longTime: "h:MM:ss TT Z",
47
- isoDate: "yyyy-mm-dd",
48
- isoTime: "HH:MM:ss",
49
- isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
50
- isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'",
51
- time: "HH:MM",
52
- dateTime: "dd.mm.yyyy HH:MM",
53
- clever: "clever"
54
- };
55
- const i18n = {
56
- en: {
57
- dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
58
- dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
59
- monthName: [
60
- "January",
61
- "February",
62
- "March",
63
- "April",
64
- "May",
65
- "June",
66
- "July",
67
- "August",
68
- "September",
69
- "October",
70
- "November",
71
- "December"
72
- ],
73
- yesterday: "'Yesterday'",
74
- today: "'Today'"
75
- },
76
- ru: {
77
- dayNames: ["\u0432\u043E\u0441\u043A\u0440\u0435\u0441\u0435\u043D\u044C\u0435", "\u043F\u043E\u043D\u0435\u0434\u0435\u043B\u044C\u043D\u0438\u043A", "\u0432\u0442\u043E\u0440\u043D\u0438\u043A", "\u0441\u0440\u0435\u0434\u0430", "\u0447\u0435\u0442\u0432\u0435\u0440\u0433", "\u043F\u044F\u0442\u043D\u0438\u0446\u0430", "\u0441\u0443\u0431\u0431\u043E\u0442\u0430"],
78
- dayNamesShort: ["\u0412\u0441", "\u041F\u043D", "\u0412\u0442", "\u0421\u0440", "\u0427\u0442", "\u041F\u0442", "\u0421\u0431"],
79
- monthName: [
80
- "\u044F\u043D\u0432\u0430\u0440\u044C",
81
- "\u0444\u0435\u0432\u0440\u0430\u043B\u044C",
82
- "\u043C\u0430\u0440\u0442",
83
- "\u0430\u043F\u0440\u0435\u043B\u044C",
84
- "\u043C\u0430\u0439",
85
- "\u0438\u044E\u043D\u044C",
86
- "\u0438\u044E\u043B\u044C",
87
- "\u0430\u0432\u0433\u0443\u0441\u0442",
88
- "\u0441\u0435\u043D\u0442\u044F\u0431\u0440\u044C",
89
- "\u043E\u043A\u0442\u044F\u0431\u0440\u044C",
90
- "\u043D\u043E\u044F\u0431\u0440\u044C",
91
- "\u0434\u0435\u043A\u0430\u0431\u0440\u044C"
92
- ],
93
- yesterday: "'\u0412\u0447\u0435\u0440\u0430'",
94
- today: "'\u0421\u0435\u0433\u043E\u0434\u043D\u044F'"
95
- }
96
- };
97
- const token = /d{1,4}:?C?|m{1,4}:?[RC]?|yy(?:yy|y)?:?[RC]?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g;
98
- const timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g;
99
- const timezoneClip = /[^-+\dA-Z]/g;
100
- const pad = (value, len = 2) => {
101
- let val = String(value);
102
- while (val.length < len) {
103
- val = `0${val}`;
104
- }
105
- return val;
106
- };
107
- const createOnlyDate = (date) => {
108
- const d = new Date(date);
109
- d.setHours(0, 0, 0, 0);
110
- return d;
111
- };
112
- const countCalendarDayBetween = (date1, date2) => {
113
- const day1 = createOnlyDate(date1);
114
- const day2 = createOnlyDate(date2);
115
- const dayCount = (day1.getTime() - day2.getTime()) / (24 * 60 * 60 * 1e3);
116
- return Math.abs(dayCount);
117
- };
118
- const checkIsYesterday = (now, date) => {
119
- return now > date && countCalendarDayBetween(now, date) === 1;
120
- };
121
- const getDayName = (day, locale, short = false) => {
122
- return short ? i18n[locale].dayNamesShort[day] : i18n[locale].dayNames[day];
123
- };
124
- const monthDeclination = (month, locale) => {
125
- return month === 3 || month === 8 ? `${i18n[locale].monthName[month - 1]}\u0430` : `${i18n[locale].monthName[month - 1].slice(0, -1)}\u044F`;
126
- };
127
- const getMonthName = (month, locale, countChar = 0, declination = false) => {
128
- const monthName = locale === "ru" && declination ? monthDeclination(month, locale) : i18n[locale].monthName[month - 1];
129
- if (countChar && countChar > 0) {
130
- return monthName.slice(0, 3);
131
- }
132
- return monthName;
133
- };
134
- const getMask = (format, locale, isCurrentDay, isYesterday, isCurrentYear) => {
135
- const defaultFormat = {
136
- en: "mmmm d, yyyy",
137
- ru: "d mmmm:R yyyy"
138
- };
139
- const formats = {
140
- default: defaultFormat,
141
- get clever() {
142
- if (isCurrentDay) {
143
- return {
144
- en: `${i18n.en.today} 'at' H:MM TT`,
145
- ru: `${i18n.ru.today}, HH:MM`
146
- };
147
- } else if (isYesterday) {
148
- return {
149
- en: `${i18n.en.yesterday} 'at' H:MM TT`,
150
- ru: `${i18n.ru.yesterday}, HH:MM`
151
- };
152
- } else if (isCurrentYear) {
153
- return {
154
- en: "mmmm d",
155
- ru: "d mmmm:R"
156
- };
157
- } else {
158
- return defaultFormat;
159
- }
160
- }
161
- };
162
- let mask = String(masks[format] ?? (format || masks.default));
163
- if (mask.startsWith("UTC:")) {
164
- mask = mask.slice(4);
165
- }
166
- if (formats[format]?.[locale]) {
167
- return formats[format]?.[locale] ?? "";
168
- }
169
- return mask;
170
- };
171
- export function dateFormat(date = /* @__PURE__ */ new Date(), format = "default", locale = "en", dateTimeNow) {
172
- date = date ? new Date(date) : /* @__PURE__ */ new Date();
173
- if (Number.isNaN(date)) {
174
- throw new SyntaxError("invalid date");
175
- }
176
- const utc = (masks[format] ?? format).startsWith("UTC:");
177
- const now = dateTimeNow ?? /* @__PURE__ */ new Date();
178
- const currentYear = utc ? now.getUTCFullYear() : now.getFullYear();
179
- const currentMonth = utc ? now.getUTCMonth() : now.getMonth();
180
- const currentDate = utc ? now.getUTCDate() : now.getDate();
181
- const isYesterday = checkIsYesterday(now, date);
182
- const d = utc ? date.getUTCDate() : date.getDate();
183
- const D = utc ? date.getUTCDay() : date.getDay();
184
- const m = utc ? date.getUTCMonth() : date.getMonth();
185
- const y = utc ? date.getUTCFullYear() : date.getFullYear();
186
- const isCurrentYear = y === currentYear;
187
- const isCurrentDay = y === currentYear && m === currentMonth && d === currentDate;
188
- const H = utc ? date.getUTCHours() : date.getHours();
189
- const M = utc ? date.getUTCMinutes() : date.getMinutes();
190
- const s = utc ? date.getUTCSeconds() : date.getSeconds();
191
- const L = utc ? date.getUTCMilliseconds() : date.getMilliseconds();
192
- const o = utc ? 0 : date.getTimezoneOffset();
193
- const flags = {
194
- d,
195
- dd: pad(d),
196
- ddd: getDayName(D, locale, true),
197
- dddd: getDayName(D, locale),
198
- m: m + 1,
199
- mm: pad(m + 1),
200
- mmm: getMonthName(m + 1, locale, 3),
201
- mmmm: getMonthName(m + 1, locale),
202
- "mmmm:R": getMonthName(m + 1, locale, 0, true),
203
- "mm:C": isYesterday || isCurrentDay ? "" : pad(m + 1),
204
- "yy:C": isCurrentYear ? "" : String(y).slice(2),
205
- yy: String(y).slice(2),
206
- "yyyy:C": isCurrentYear ? "" : y,
207
- yyyy: y,
208
- yyy: y,
209
- h: H % 12 || 12,
210
- hh: pad(H % 12 || 12),
211
- H,
212
- HH: pad(H),
213
- M,
214
- MM: pad(M),
215
- s,
216
- ss: pad(s),
217
- l: pad(L, 3),
218
- L: pad(L > 99 ? Math.round(L / 10) : L),
219
- tt: H < 12 ? "am" : "pm",
220
- TT: H < 12 ? "AM" : "PM",
221
- Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop()?.replace(timezoneClip, ""),
222
- o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
223
- };
224
- const mask = getMask(format, locale, isCurrentDay, isYesterday, isCurrentYear);
225
- const parsedDate = mask.replaceAll(token, ($0) => {
226
- return $0 in flags ? String(flags[$0]) : $0.slice(1, -1);
227
- });
228
- return parsedDate.trim();
229
- }
230
- export const dateHelper = { stringToDate, dateFormat };
231
- export const useDateHelper = () => {
232
- return dateHelper;
233
- };