@dxtmisha/functional-basic 0.1.1 → 0.1.4
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/dist/functions/copyObjectLite.d.ts +9 -0
- package/dist/library.d.ts +1 -0
- package/dist/library.js +405 -411
- package/package.json +1 -3
- package/src/classes/Api.ts +0 -407
- package/src/classes/ApiDefault.ts +0 -83
- package/src/classes/ApiHeaders.ts +0 -52
- package/src/classes/ApiPreparation.ts +0 -114
- package/src/classes/ApiResponse.ts +0 -293
- package/src/classes/ApiStatus.ts +0 -173
- package/src/classes/BroadcastMessage.ts +0 -73
- package/src/classes/Cache.ts +0 -60
- package/src/classes/CacheItem.ts +0 -95
- package/src/classes/CacheStatic.ts +0 -30
- package/src/classes/Cookie.ts +0 -135
- package/src/classes/CookieBlock.ts +0 -31
- package/src/classes/DataStorage.ts +0 -194
- package/src/classes/Datetime.ts +0 -891
- package/src/classes/EventItem.ts +0 -373
- package/src/classes/Geo.ts +0 -320
- package/src/classes/GeoFlag.ts +0 -386
- package/src/classes/GeoIntl.ts +0 -839
- package/src/classes/GeoPhone.ts +0 -272
- package/src/classes/Global.ts +0 -32
- package/src/classes/Hash.ts +0 -142
- package/src/classes/Icons.ts +0 -165
- package/src/classes/Loading.ts +0 -90
- package/src/classes/Meta.ts +0 -284
- package/src/classes/MetaManager.ts +0 -200
- package/src/classes/MetaOg.ts +0 -147
- package/src/classes/MetaTwitter.ts +0 -154
- package/src/classes/ScrollbarWidth.ts +0 -86
- package/src/classes/Translate.ts +0 -293
- package/src/classes/__tests__/Api.test.ts +0 -728
- package/src/classes/__tests__/ApiDefault.test.ts +0 -222
- package/src/classes/__tests__/ApiHeaders.test.ts +0 -447
- package/src/classes/__tests__/ApiPreparation.test.ts +0 -257
- package/src/classes/__tests__/ApiResponse.test.ts +0 -547
- package/src/classes/__tests__/ApiStatus.test.ts +0 -403
- package/src/classes/__tests__/Meta.test.ts +0 -629
- package/src/classes/__tests__/MetaManager.test.ts +0 -836
- package/src/classes/__tests__/MetaOg.test.ts +0 -677
- package/src/classes/__tests__/MetaTwitter.test.ts +0 -423
- package/src/functions/anyToString.ts +0 -36
- package/src/functions/applyTemplate.ts +0 -63
- package/src/functions/arrFill.ts +0 -10
- package/src/functions/copyObject.ts +0 -10
- package/src/functions/createElement.ts +0 -40
- package/src/functions/domQuerySelector.ts +0 -15
- package/src/functions/domQuerySelectorAll.ts +0 -15
- package/src/functions/encodeAttribute.ts +0 -15
- package/src/functions/eventStopPropagation.ts +0 -10
- package/src/functions/executeFunction.ts +0 -13
- package/src/functions/executePromise.ts +0 -19
- package/src/functions/forEach.ts +0 -39
- package/src/functions/frame.ts +0 -38
- package/src/functions/getAttributes.ts +0 -27
- package/src/functions/getClipboardData.ts +0 -13
- package/src/functions/getColumn.ts +0 -18
- package/src/functions/getElement.ts +0 -35
- package/src/functions/getElementId.ts +0 -39
- package/src/functions/getElementItem.ts +0 -27
- package/src/functions/getElementOrWindow.ts +0 -23
- package/src/functions/getExp.ts +0 -21
- package/src/functions/getItemByPath.ts +0 -24
- package/src/functions/getKey.ts +0 -9
- package/src/functions/getLengthOfAllArray.ts +0 -13
- package/src/functions/getMaxLengthAllArray.ts +0 -13
- package/src/functions/getMinLengthAllArray.ts +0 -13
- package/src/functions/getMouseClient.ts +0 -17
- package/src/functions/getMouseClientX.ts +0 -9
- package/src/functions/getMouseClientY.ts +0 -9
- package/src/functions/getObjectByKeys.ts +0 -24
- package/src/functions/getObjectNoUndefined.ts +0 -23
- package/src/functions/getObjectOrNone.ts +0 -11
- package/src/functions/getRandomText.ts +0 -29
- package/src/functions/getRequestString.ts +0 -21
- package/src/functions/getStepPercent.ts +0 -19
- package/src/functions/getStepValue.ts +0 -19
- package/src/functions/goScroll.ts +0 -40
- package/src/functions/inArray.ts +0 -10
- package/src/functions/initScrollbarOffset.ts +0 -14
- package/src/functions/intersectKey.ts +0 -34
- package/src/functions/isArray.ts +0 -9
- package/src/functions/isDifferent.ts +0 -27
- package/src/functions/isDomRuntime.ts +0 -12
- package/src/functions/isFilled.ts +0 -49
- package/src/functions/isFloat.ts +0 -16
- package/src/functions/isFunction.ts +0 -11
- package/src/functions/isInDom.ts +0 -15
- package/src/functions/isIntegerBetween.ts +0 -11
- package/src/functions/isNull.ts +0 -11
- package/src/functions/isNumber.ts +0 -16
- package/src/functions/isObject.ts +0 -9
- package/src/functions/isObjectNotArray.ts +0 -11
- package/src/functions/isSelected.ts +0 -32
- package/src/functions/isSelectedByList.ts +0 -19
- package/src/functions/isString.ts +0 -9
- package/src/functions/isWindow.ts +0 -11
- package/src/functions/random.ts +0 -10
- package/src/functions/replaceRecursive.ts +0 -60
- package/src/functions/replaceTemplate.ts +0 -22
- package/src/functions/secondToTime.ts +0 -20
- package/src/functions/setElementItem.ts +0 -56
- package/src/functions/setValues.ts +0 -59
- package/src/functions/splice.ts +0 -59
- package/src/functions/strFill.ts +0 -12
- package/src/functions/toArray.ts +0 -19
- package/src/functions/toCamelCase.ts +0 -16
- package/src/functions/toCamelCaseFirst.ts +0 -12
- package/src/functions/toDate.ts +0 -44
- package/src/functions/toKebabCase.ts +0 -25
- package/src/functions/toNumber.ts +0 -35
- package/src/functions/toNumberByMax.ts +0 -33
- package/src/functions/toPercent.ts +0 -10
- package/src/functions/toPercentBy100.ts +0 -12
- package/src/functions/transformation.ts +0 -59
- package/src/functions/uniqueArray.ts +0 -9
- package/src/functions/writeClipboardData.ts +0 -17
- package/src/library.ts +0 -116
- package/src/types/apiTypes.ts +0 -143
- package/src/types/basicTypes.ts +0 -155
- package/src/types/geoTypes.ts +0 -109
- package/src/types/metaTypes.ts +0 -764
- package/src/vite-env.d.ts +0 -1
package/src/classes/EventItem.ts
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { getElement } from '../functions/getElement'
|
|
2
|
-
import { getElementOrWindow } from '../functions/getElementOrWindow'
|
|
3
|
-
import { isInDom } from '../functions/isInDom'
|
|
4
|
-
import { isNull } from '../functions/isNull'
|
|
5
|
-
import { isObject } from '../functions/isObject'
|
|
6
|
-
import { toArray } from '../functions/toArray'
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
type ElementOrString,
|
|
10
|
-
type ElementOrWindow,
|
|
11
|
-
type EventActivityItem,
|
|
12
|
-
type EventListenerDetail,
|
|
13
|
-
type EventOptions
|
|
14
|
-
} from '../types/basicTypes'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Class for working with events.
|
|
18
|
-
*
|
|
19
|
-
* Класс для работы с событиями.
|
|
20
|
-
*/
|
|
21
|
-
export class EventItem<
|
|
22
|
-
E extends ElementOrWindow,
|
|
23
|
-
O extends Event,
|
|
24
|
-
D extends Record<string, any> = Record<string, any>
|
|
25
|
-
> {
|
|
26
|
-
/**
|
|
27
|
-
* Element.
|
|
28
|
-
*
|
|
29
|
-
* Элемент.
|
|
30
|
-
*/
|
|
31
|
-
protected element?: E
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Element for checking. If the element is missing in the DOM, the event is turned off.
|
|
35
|
-
*
|
|
36
|
-
* Элемент для проверки. Если элемент отсутствует в DOM, событие выключается.
|
|
37
|
-
*/
|
|
38
|
-
protected elementControl?: ElementOrWindow
|
|
39
|
-
protected elementControlEdit?: boolean
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* A case-sensitive string representing the event type to listen for.
|
|
43
|
-
*
|
|
44
|
-
* Чувствительная к регистру строка, представляющая тип обрабатываемого события.
|
|
45
|
-
*/
|
|
46
|
-
protected type: string[]
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The object that receives a notification (an object that implements the Event interface)
|
|
50
|
-
* when an event of the specified type occurs. This must be null, an object with a
|
|
51
|
-
* handleEvent() method, or a JavaScript function.
|
|
52
|
-
*
|
|
53
|
-
* Объект, который принимает уведомление, когда событие указанного типа произошло.
|
|
54
|
-
* Это должен быть объект, реализующий интерфейс EventListener или просто функция JavaScript.
|
|
55
|
-
*/
|
|
56
|
-
protected listenerRecent = (event?: O | ResizeObserverEntry): void => {
|
|
57
|
-
if (isInDom(this.elementControl)) {
|
|
58
|
-
this.listener?.call(this.element, event as O, this.detail)
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
isObject(this.options)
|
|
62
|
-
&& this.options?.once
|
|
63
|
-
) {
|
|
64
|
-
this.stop()
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
this.stop()
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Event states.
|
|
73
|
-
*
|
|
74
|
-
* Состояния события.
|
|
75
|
-
*/
|
|
76
|
-
protected activity = false
|
|
77
|
-
protected activityItems: EventActivityItem<E>[] = []
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Classes Constructor
|
|
81
|
-
* @param elementSelector element/ элемент
|
|
82
|
-
* @param type type/ тип
|
|
83
|
-
* @param listener the object that receives a notification (an object that implements the
|
|
84
|
-
* Event interface) when an event of the specified type occurs/ объект, который принимает
|
|
85
|
-
* уведомление, когда событие указанного типа произошло
|
|
86
|
-
* @param options object that specifies characteristics/ объект options
|
|
87
|
-
* @param detail an event-dependent value associated with the event/ зависимое от события
|
|
88
|
-
* значение, связанное с событием
|
|
89
|
-
*/
|
|
90
|
-
constructor(
|
|
91
|
-
elementSelector?: ElementOrString<E>,
|
|
92
|
-
type: string | string[] = ['click'],
|
|
93
|
-
protected listener?: EventListenerDetail<O, D>,
|
|
94
|
-
protected options?: EventOptions,
|
|
95
|
-
protected detail?: D
|
|
96
|
-
) {
|
|
97
|
-
this.element = getElementOrWindow(elementSelector)
|
|
98
|
-
this.elementControl = getElement(elementSelector)
|
|
99
|
-
this.type = toArray(type)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Checks whether event listening is currently enabled.
|
|
104
|
-
*
|
|
105
|
-
* Проверяет, включено ли сейчас прослушивание события.
|
|
106
|
-
*/
|
|
107
|
-
isActive(): boolean {
|
|
108
|
-
return this.activity
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getElement(): E | undefined {
|
|
112
|
-
return this.element
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Change of an element for tracking.
|
|
117
|
-
*
|
|
118
|
-
* Изменение элемента для прослеживания.
|
|
119
|
-
* @param elementSelector element/ элемент
|
|
120
|
-
*/
|
|
121
|
-
setElement(elementSelector?: ElementOrString<E>): this {
|
|
122
|
-
const element = getElementOrWindow(elementSelector)
|
|
123
|
-
|
|
124
|
-
if (!this.elementControlEdit) {
|
|
125
|
-
this.elementControl = getElement(elementSelector)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this.element = element
|
|
129
|
-
this.reset()
|
|
130
|
-
|
|
131
|
-
return this
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Modifies the object that receives the notification.
|
|
136
|
-
*
|
|
137
|
-
* Модифицирует объект, который получает уведомление.
|
|
138
|
-
* @param elementSelector element/ элемент
|
|
139
|
-
*/
|
|
140
|
-
setElementControl<EC extends HTMLElement>(elementSelector?: ElementOrString<EC>): this {
|
|
141
|
-
this.elementControl = getElement(elementSelector)
|
|
142
|
-
this.elementControlEdit = !isNull(this.elementControl)
|
|
143
|
-
|
|
144
|
-
if (!this.elementControlEdit) {
|
|
145
|
-
this.elementControl = getElement(this.element)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return this
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Changes the type of the handled event.
|
|
153
|
-
*
|
|
154
|
-
* Изменяет тип обрабатываемого события.
|
|
155
|
-
* @param type type/ тип
|
|
156
|
-
*/
|
|
157
|
-
setType(type: string | string[]): this {
|
|
158
|
-
this.type = toArray(type)
|
|
159
|
-
this.reset()
|
|
160
|
-
|
|
161
|
-
return this
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Modifies the object that receives the notification.
|
|
166
|
-
*
|
|
167
|
-
* Модифицирует объект, который получает уведомление.
|
|
168
|
-
* @param listener
|
|
169
|
-
*/
|
|
170
|
-
setListener(listener: EventListenerDetail<O, D>): this {
|
|
171
|
-
this.listener = listener
|
|
172
|
-
return this
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Modifying the options object that defines the characteristics of an object.
|
|
177
|
-
*
|
|
178
|
-
* Изменение объекта options, который определяет характеристики объекта.
|
|
179
|
-
* @param options
|
|
180
|
-
*/
|
|
181
|
-
setOptions(options?: EventOptions): this {
|
|
182
|
-
this.options = options
|
|
183
|
-
this.reset()
|
|
184
|
-
|
|
185
|
-
return this
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Modifying a dependent value for the dispatch method.
|
|
190
|
-
*
|
|
191
|
-
* Изменение зависимого значения для метода dispatch.
|
|
192
|
-
* @param detail
|
|
193
|
-
*/
|
|
194
|
-
setDetail(detail?: D): this {
|
|
195
|
-
this.detail = detail
|
|
196
|
-
return this
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* The method of the EventTarget sends an Event to the object, (synchronously) invoking
|
|
201
|
-
* the affected EventListeners in the appropriate order.
|
|
202
|
-
*
|
|
203
|
-
* Отправляет событие в общую систему событий. Это событие подчиняется тем же правилам
|
|
204
|
-
* поведения "Захвата" и "Всплывания" как и непосредственно инициированные события.
|
|
205
|
-
* @param detail an event-dependent value associated with the event/ зависимое от события
|
|
206
|
-
* значение, связанное с событием
|
|
207
|
-
*/
|
|
208
|
-
dispatch(detail: D | undefined = this.detail): this {
|
|
209
|
-
this.type.forEach(
|
|
210
|
-
type => this.element?.dispatchEvent(new CustomEvent(type, { detail }))
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
return this
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Starting event listening.
|
|
218
|
-
*
|
|
219
|
-
* Запуск прослушивания события.
|
|
220
|
-
*/
|
|
221
|
-
start(): this {
|
|
222
|
-
if (!this.activity) {
|
|
223
|
-
this.activity = true
|
|
224
|
-
this.activityItems = []
|
|
225
|
-
|
|
226
|
-
this.type.forEach((type) => {
|
|
227
|
-
if (this.element) {
|
|
228
|
-
if (
|
|
229
|
-
!(type === 'resize' && this.makeResize())
|
|
230
|
-
&& !(type === 'scroll-sync' && this.makeScroll())
|
|
231
|
-
) {
|
|
232
|
-
this.element.addEventListener(type, this.listenerRecent as EventListener, this.options)
|
|
233
|
-
this.activityItems.push({
|
|
234
|
-
element: this.element,
|
|
235
|
-
type
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return this
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Stopping event listening.
|
|
247
|
-
*
|
|
248
|
-
* Остановка прослушивания события.
|
|
249
|
-
*/
|
|
250
|
-
stop(): this {
|
|
251
|
-
if (this.activity) {
|
|
252
|
-
this.activity = false
|
|
253
|
-
this.activityItems.forEach(({
|
|
254
|
-
element,
|
|
255
|
-
type,
|
|
256
|
-
listener,
|
|
257
|
-
observer
|
|
258
|
-
}) => {
|
|
259
|
-
if (observer) {
|
|
260
|
-
observer.disconnect()
|
|
261
|
-
} else if (listener) {
|
|
262
|
-
element?.removeEventListener(type, listener as EventListener)
|
|
263
|
-
} else {
|
|
264
|
-
element?.removeEventListener(type, this.listenerRecent as EventListener)
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return this
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Toggling event handler state.
|
|
274
|
-
*
|
|
275
|
-
* Переключение состояния работы события.
|
|
276
|
-
* @param activity event activation/ активация события
|
|
277
|
-
*/
|
|
278
|
-
toggle(activity: boolean): this {
|
|
279
|
-
return activity ? this.start() : this.stop()
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Overloads the listening events.
|
|
284
|
-
*
|
|
285
|
-
* Перегружает события прослушивания.
|
|
286
|
-
*/
|
|
287
|
-
reset() {
|
|
288
|
-
if (this.activity) {
|
|
289
|
-
this.stop()
|
|
290
|
-
this.start()
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return this
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Checks if the ResizeObserver object exists.
|
|
298
|
-
*
|
|
299
|
-
* Проверяет, существует ли объект ResizeObserver.
|
|
300
|
-
*/
|
|
301
|
-
protected isObserver(): boolean {
|
|
302
|
-
return 'ResizeObserver' in window
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* The implementation of the resize event for an element.
|
|
307
|
-
*
|
|
308
|
-
* Реализация события изменения размера для элемента.
|
|
309
|
-
*/
|
|
310
|
-
protected makeResize(): boolean {
|
|
311
|
-
if (
|
|
312
|
-
this.element
|
|
313
|
-
&& this.element instanceof HTMLElement
|
|
314
|
-
&& this.element !== document.body
|
|
315
|
-
&& this.isObserver()
|
|
316
|
-
) {
|
|
317
|
-
const observer = new ResizeObserver(
|
|
318
|
-
(entries: ResizeObserverEntry[]) => this.listenerRecent(entries?.[0])
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
observer.observe(this.element)
|
|
322
|
-
|
|
323
|
-
this.activityItems.push({
|
|
324
|
-
element: this.element,
|
|
325
|
-
type: 'resize',
|
|
326
|
-
observer
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
return true
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return false
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Implementation of the scroll event for an element.
|
|
337
|
-
*
|
|
338
|
-
* Реализация события изменения положения скролла для элемента.
|
|
339
|
-
*/
|
|
340
|
-
protected makeScroll(): boolean {
|
|
341
|
-
if (this.element) {
|
|
342
|
-
let go = false
|
|
343
|
-
const listener = (event: O): void => {
|
|
344
|
-
if (!go) {
|
|
345
|
-
go = true
|
|
346
|
-
requestAnimationFrame(() => {
|
|
347
|
-
this.listenerRecent(event)
|
|
348
|
-
go = false
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
this.element.addEventListener('scroll', listener as EventListener, this.options)
|
|
354
|
-
this.element.addEventListener('resize', listener as EventListener, this.options)
|
|
355
|
-
this.activityItems.push(
|
|
356
|
-
{
|
|
357
|
-
element: this.element,
|
|
358
|
-
type: 'scroll',
|
|
359
|
-
listener
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
element: this.element,
|
|
363
|
-
type: 'resize',
|
|
364
|
-
listener
|
|
365
|
-
}
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
return true
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return false
|
|
372
|
-
}
|
|
373
|
-
}
|
package/src/classes/Geo.ts
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { copyObject } from '../functions/copyObject'
|
|
2
|
-
import { isDomRuntime } from '../functions/isDomRuntime'
|
|
3
|
-
import { isSelected } from '../functions/isSelected'
|
|
4
|
-
|
|
5
|
-
import { DataStorage } from './DataStorage'
|
|
6
|
-
|
|
7
|
-
import { geo } from '@dxtmisha/media'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
type GeoItem,
|
|
11
|
-
type GeoItemFull
|
|
12
|
-
} from '../types/geoTypes'
|
|
13
|
-
|
|
14
|
-
const STORAGE_NAME_CODE = 'geo-code'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Base class for working with geographic data.
|
|
18
|
-
*
|
|
19
|
-
* Базовый класс для работы с географическими данными.
|
|
20
|
-
*/
|
|
21
|
-
export class Geo {
|
|
22
|
-
private static storage = new DataStorage<string>(STORAGE_NAME_CODE)
|
|
23
|
-
private static location: string
|
|
24
|
-
|
|
25
|
-
private static item: GeoItemFull
|
|
26
|
-
private static language: string
|
|
27
|
-
|
|
28
|
-
private static timezone: number = new Date().getTimezoneOffset()
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Information about the current country.
|
|
32
|
-
*
|
|
33
|
-
* Информация об текущей стране.
|
|
34
|
-
*/
|
|
35
|
-
static get(): GeoItemFull {
|
|
36
|
-
return this.item
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Current country.
|
|
41
|
-
*
|
|
42
|
-
* Текущая страна.
|
|
43
|
-
*/
|
|
44
|
-
static getCountry(): string {
|
|
45
|
-
return this.item.country
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Current language.
|
|
50
|
-
*
|
|
51
|
-
* Текущий язык.
|
|
52
|
-
*/
|
|
53
|
-
static getLanguage(): string {
|
|
54
|
-
return this.language
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Full format according to the standard.
|
|
59
|
-
*
|
|
60
|
-
* Полный формат согласно стандарту.
|
|
61
|
-
*/
|
|
62
|
-
static getStandard(): string {
|
|
63
|
-
return this.item.standard
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Returns the first day of the week.
|
|
68
|
-
*
|
|
69
|
-
* Возвращает первый день недели.
|
|
70
|
-
*/
|
|
71
|
-
static getFirstDay(): string {
|
|
72
|
-
return this.item.firstDay
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Full format.
|
|
77
|
-
*
|
|
78
|
-
* Полный формат.
|
|
79
|
-
*/
|
|
80
|
-
static getLocation(): string {
|
|
81
|
-
return this.location
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Obtaining processed data.
|
|
86
|
-
*
|
|
87
|
-
* Получение обработанных данных.
|
|
88
|
-
*/
|
|
89
|
-
static getItem(): GeoItemFull {
|
|
90
|
-
return {
|
|
91
|
-
...this.item,
|
|
92
|
-
language: this.language
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Returns the full list of countries.
|
|
98
|
-
*
|
|
99
|
-
* Возвращает полный список стран.
|
|
100
|
-
*/
|
|
101
|
-
static getList(): GeoItem[] {
|
|
102
|
-
return geo
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Returns the data about the country by its full code.
|
|
107
|
-
*
|
|
108
|
-
* Возвращает данные о стране по ее полному коду.
|
|
109
|
-
* @param code country code, full form language-country or one of them/
|
|
110
|
-
* код страны, полный вид язык-страна или один из них
|
|
111
|
-
*/
|
|
112
|
-
static getByCode(code?: string): GeoItemFull {
|
|
113
|
-
let item: GeoItem | undefined
|
|
114
|
-
|
|
115
|
-
if (code) {
|
|
116
|
-
if (code.match(/([A-Z]{2}-[a-z]{2})|([a-z]{2}-[A-Z]{2})/)) {
|
|
117
|
-
item = this.getByCodeFull(code)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!item && code.match(/[A-Z]{2}/)) {
|
|
121
|
-
item = this.getByCountry(this.toCountry(code))
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (!item && code.match(/[a-z]{2}/)) {
|
|
125
|
-
item = this.getByLanguage(this.toLanguage(code))
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return this.toFull(copyObject(item ?? this.getList()[0] as GeoItem))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Returns the full data by language and country.
|
|
134
|
-
*
|
|
135
|
-
* Возвращает полные данные по языку и стране.
|
|
136
|
-
* @param code string in the form of language-country/ строка в виде язык-страна
|
|
137
|
-
*/
|
|
138
|
-
static getByCodeFull(code: string): GeoItem | undefined {
|
|
139
|
-
return this.getList().find(
|
|
140
|
-
item => isSelected(code, [
|
|
141
|
-
`${item.language}-${item.country}`,
|
|
142
|
-
`${item.country}-${item.language}`
|
|
143
|
-
])
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Returns the full data by country.
|
|
149
|
-
*
|
|
150
|
-
* Возвращает полные данные по стране.
|
|
151
|
-
* @param country country/ страна
|
|
152
|
-
*/
|
|
153
|
-
static getByCountry(country: string): GeoItem | undefined {
|
|
154
|
-
return this.getList().find((item) => {
|
|
155
|
-
return item.country === country
|
|
156
|
-
|| item?.countryAlternative?.find(countryAlternative => countryAlternative === country)
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Returns the full data by language.
|
|
162
|
-
*
|
|
163
|
-
* Возвращает полные данные по языку.
|
|
164
|
-
* @param language language/ язык
|
|
165
|
-
*/
|
|
166
|
-
static getByLanguage(language: string): GeoItem | undefined {
|
|
167
|
-
return this.getList().find((item) => {
|
|
168
|
-
return item.language === language
|
|
169
|
-
|| item?.languageAlternative?.find(languageAlternative => languageAlternative === language)
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Retrieving the default timezone.
|
|
175
|
-
*
|
|
176
|
-
* Получение временной зоны по умолчанию
|
|
177
|
-
*/
|
|
178
|
-
static getTimezone(): number {
|
|
179
|
-
return this.timezone
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Retrieving the default timezone (formatted view).
|
|
184
|
-
*
|
|
185
|
-
* Получение временной зоны по умолчанию (отформатированный вид).
|
|
186
|
-
*/
|
|
187
|
-
static getTimezoneFormat(): string {
|
|
188
|
-
const hours = Math.abs(Math.trunc(this.timezone / 60)).toString().padStart(2, '0')
|
|
189
|
-
const minutes = Math.abs(this.timezone % 60).toString().padStart(2, '0')
|
|
190
|
-
|
|
191
|
-
if (this.timezone >= 0) {
|
|
192
|
-
return `-${hours}:${minutes}`
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return `+${hours}:${minutes}`
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Determines the current country by its full name.
|
|
200
|
-
*
|
|
201
|
-
* Определяет текущую страну по ее полному названию.
|
|
202
|
-
* @param code country code, full form language-country or one of them/
|
|
203
|
-
* код страны, полный вид язык-страна или один из них
|
|
204
|
-
*/
|
|
205
|
-
static find(code: string): GeoItemFull {
|
|
206
|
-
return this.getByCode(code)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Returns a complete string with the country code and language.
|
|
211
|
-
*
|
|
212
|
-
* Возвращает полную строку с кодом страны и языка.
|
|
213
|
-
* @param item object with data about the current country/
|
|
214
|
-
* объект с данными об текущей стране
|
|
215
|
-
*/
|
|
216
|
-
static toStandard(item: GeoItem) {
|
|
217
|
-
return `${item.language}-${item.country}`
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Changes the data by the full code.
|
|
222
|
-
*
|
|
223
|
-
* Изменяет данные по полному коду.
|
|
224
|
-
* @param code country code, full form language-country or one of them/
|
|
225
|
-
* код страны, полный вид язык-страна или один из них
|
|
226
|
-
* @param save save the result/ сохранить результат
|
|
227
|
-
*/
|
|
228
|
-
static set(code: string, save?: boolean): void {
|
|
229
|
-
this.location = code
|
|
230
|
-
|
|
231
|
-
this.item = this.getByCode(this.location)
|
|
232
|
-
this.language = this.findLanguage(this.location)
|
|
233
|
-
|
|
234
|
-
if (save) {
|
|
235
|
-
this.storage.set(this.location)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Changing the default timezone for transmitted dates.
|
|
241
|
-
*
|
|
242
|
-
* Изменение временной зоны по умолчанию для отправляемых дат
|
|
243
|
-
* @param timezone new time zone/ новая временная зона
|
|
244
|
-
*/
|
|
245
|
-
static setTimezone(timezone: number) {
|
|
246
|
-
this.timezone = timezone
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Determines the current location.
|
|
251
|
-
*
|
|
252
|
-
* Определяет текущую локацию.
|
|
253
|
-
*/
|
|
254
|
-
private static findLocation(): string {
|
|
255
|
-
return (
|
|
256
|
-
isDomRuntime() && (
|
|
257
|
-
this.storage.get()
|
|
258
|
-
|| document.querySelector('html')?.lang
|
|
259
|
-
|| navigator.language
|
|
260
|
-
|| navigator.languages[0]
|
|
261
|
-
|| 'en-GB'
|
|
262
|
-
)
|
|
263
|
-
) || 'en-GB'
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Determines the current language.
|
|
268
|
-
*
|
|
269
|
-
* Определяет текущий язык.
|
|
270
|
-
* @param code country code, full form language-country or one of them/
|
|
271
|
-
* код страны, полный вид язык-страна или один из них
|
|
272
|
-
*/
|
|
273
|
-
private static findLanguage(code?: string): string {
|
|
274
|
-
if (code && code.match(/[a-z]{2}/)) {
|
|
275
|
-
return this.toLanguage(code)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return this.item.language
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Returns the country code by its full language-country.
|
|
283
|
-
*
|
|
284
|
-
* Возвращает код страны по ее полному язык-страна.
|
|
285
|
-
* @param code country code/ код страна
|
|
286
|
-
*/
|
|
287
|
-
private static toCountry(code: string): string {
|
|
288
|
-
return code.replace(/[^A-Z]+/g, '')
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Returns the language code by its full language-country.<br>
|
|
293
|
-
* Возвращает код языка по его полному язык-страна.
|
|
294
|
-
* @param code country code/ код страна
|
|
295
|
-
*/
|
|
296
|
-
private static toLanguage(code: string): string {
|
|
297
|
-
return code.replace(/[^a-z]+/g, '')
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Adding missing data.<br>
|
|
302
|
-
* Добавление недостающих данных.
|
|
303
|
-
* @param item object with data about the current country/
|
|
304
|
-
* объект с данными об текущей стране
|
|
305
|
-
*/
|
|
306
|
-
private static toFull(item: GeoItem): GeoItemFull {
|
|
307
|
-
return {
|
|
308
|
-
...item,
|
|
309
|
-
standard: this.toStandard(item),
|
|
310
|
-
firstDay: item?.firstDay || 'Mo'
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
static {
|
|
315
|
-
this.location = this.findLocation()
|
|
316
|
-
|
|
317
|
-
this.language = this.findLanguage(this.location)
|
|
318
|
-
this.item = this.getByCode(this.location)
|
|
319
|
-
}
|
|
320
|
-
}
|