@dxtmisha/functional-basic 0.1.1 → 0.2.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.
Files changed (126) hide show
  1. package/dist/functions/copyObjectLite.d.ts +9 -0
  2. package/dist/functions/isDomData.d.ts +6 -0
  3. package/dist/library.d.ts +2 -0
  4. package/dist/library.js +414 -413
  5. package/package.json +1 -3
  6. package/src/classes/Api.ts +0 -407
  7. package/src/classes/ApiDefault.ts +0 -83
  8. package/src/classes/ApiHeaders.ts +0 -52
  9. package/src/classes/ApiPreparation.ts +0 -114
  10. package/src/classes/ApiResponse.ts +0 -293
  11. package/src/classes/ApiStatus.ts +0 -173
  12. package/src/classes/BroadcastMessage.ts +0 -73
  13. package/src/classes/Cache.ts +0 -60
  14. package/src/classes/CacheItem.ts +0 -95
  15. package/src/classes/CacheStatic.ts +0 -30
  16. package/src/classes/Cookie.ts +0 -135
  17. package/src/classes/CookieBlock.ts +0 -31
  18. package/src/classes/DataStorage.ts +0 -194
  19. package/src/classes/Datetime.ts +0 -891
  20. package/src/classes/EventItem.ts +0 -373
  21. package/src/classes/Geo.ts +0 -320
  22. package/src/classes/GeoFlag.ts +0 -386
  23. package/src/classes/GeoIntl.ts +0 -839
  24. package/src/classes/GeoPhone.ts +0 -272
  25. package/src/classes/Global.ts +0 -32
  26. package/src/classes/Hash.ts +0 -142
  27. package/src/classes/Icons.ts +0 -165
  28. package/src/classes/Loading.ts +0 -90
  29. package/src/classes/Meta.ts +0 -284
  30. package/src/classes/MetaManager.ts +0 -200
  31. package/src/classes/MetaOg.ts +0 -147
  32. package/src/classes/MetaTwitter.ts +0 -154
  33. package/src/classes/ScrollbarWidth.ts +0 -86
  34. package/src/classes/Translate.ts +0 -293
  35. package/src/classes/__tests__/Api.test.ts +0 -728
  36. package/src/classes/__tests__/ApiDefault.test.ts +0 -222
  37. package/src/classes/__tests__/ApiHeaders.test.ts +0 -447
  38. package/src/classes/__tests__/ApiPreparation.test.ts +0 -257
  39. package/src/classes/__tests__/ApiResponse.test.ts +0 -547
  40. package/src/classes/__tests__/ApiStatus.test.ts +0 -403
  41. package/src/classes/__tests__/Meta.test.ts +0 -629
  42. package/src/classes/__tests__/MetaManager.test.ts +0 -836
  43. package/src/classes/__tests__/MetaOg.test.ts +0 -677
  44. package/src/classes/__tests__/MetaTwitter.test.ts +0 -423
  45. package/src/functions/anyToString.ts +0 -36
  46. package/src/functions/applyTemplate.ts +0 -63
  47. package/src/functions/arrFill.ts +0 -10
  48. package/src/functions/copyObject.ts +0 -10
  49. package/src/functions/createElement.ts +0 -40
  50. package/src/functions/domQuerySelector.ts +0 -15
  51. package/src/functions/domQuerySelectorAll.ts +0 -15
  52. package/src/functions/encodeAttribute.ts +0 -15
  53. package/src/functions/eventStopPropagation.ts +0 -10
  54. package/src/functions/executeFunction.ts +0 -13
  55. package/src/functions/executePromise.ts +0 -19
  56. package/src/functions/forEach.ts +0 -39
  57. package/src/functions/frame.ts +0 -38
  58. package/src/functions/getAttributes.ts +0 -27
  59. package/src/functions/getClipboardData.ts +0 -13
  60. package/src/functions/getColumn.ts +0 -18
  61. package/src/functions/getElement.ts +0 -35
  62. package/src/functions/getElementId.ts +0 -39
  63. package/src/functions/getElementItem.ts +0 -27
  64. package/src/functions/getElementOrWindow.ts +0 -23
  65. package/src/functions/getExp.ts +0 -21
  66. package/src/functions/getItemByPath.ts +0 -24
  67. package/src/functions/getKey.ts +0 -9
  68. package/src/functions/getLengthOfAllArray.ts +0 -13
  69. package/src/functions/getMaxLengthAllArray.ts +0 -13
  70. package/src/functions/getMinLengthAllArray.ts +0 -13
  71. package/src/functions/getMouseClient.ts +0 -17
  72. package/src/functions/getMouseClientX.ts +0 -9
  73. package/src/functions/getMouseClientY.ts +0 -9
  74. package/src/functions/getObjectByKeys.ts +0 -24
  75. package/src/functions/getObjectNoUndefined.ts +0 -23
  76. package/src/functions/getObjectOrNone.ts +0 -11
  77. package/src/functions/getRandomText.ts +0 -29
  78. package/src/functions/getRequestString.ts +0 -21
  79. package/src/functions/getStepPercent.ts +0 -19
  80. package/src/functions/getStepValue.ts +0 -19
  81. package/src/functions/goScroll.ts +0 -40
  82. package/src/functions/inArray.ts +0 -10
  83. package/src/functions/initScrollbarOffset.ts +0 -14
  84. package/src/functions/intersectKey.ts +0 -34
  85. package/src/functions/isArray.ts +0 -9
  86. package/src/functions/isDifferent.ts +0 -27
  87. package/src/functions/isDomRuntime.ts +0 -12
  88. package/src/functions/isFilled.ts +0 -49
  89. package/src/functions/isFloat.ts +0 -16
  90. package/src/functions/isFunction.ts +0 -11
  91. package/src/functions/isInDom.ts +0 -15
  92. package/src/functions/isIntegerBetween.ts +0 -11
  93. package/src/functions/isNull.ts +0 -11
  94. package/src/functions/isNumber.ts +0 -16
  95. package/src/functions/isObject.ts +0 -9
  96. package/src/functions/isObjectNotArray.ts +0 -11
  97. package/src/functions/isSelected.ts +0 -32
  98. package/src/functions/isSelectedByList.ts +0 -19
  99. package/src/functions/isString.ts +0 -9
  100. package/src/functions/isWindow.ts +0 -11
  101. package/src/functions/random.ts +0 -10
  102. package/src/functions/replaceRecursive.ts +0 -60
  103. package/src/functions/replaceTemplate.ts +0 -22
  104. package/src/functions/secondToTime.ts +0 -20
  105. package/src/functions/setElementItem.ts +0 -56
  106. package/src/functions/setValues.ts +0 -59
  107. package/src/functions/splice.ts +0 -59
  108. package/src/functions/strFill.ts +0 -12
  109. package/src/functions/toArray.ts +0 -19
  110. package/src/functions/toCamelCase.ts +0 -16
  111. package/src/functions/toCamelCaseFirst.ts +0 -12
  112. package/src/functions/toDate.ts +0 -44
  113. package/src/functions/toKebabCase.ts +0 -25
  114. package/src/functions/toNumber.ts +0 -35
  115. package/src/functions/toNumberByMax.ts +0 -33
  116. package/src/functions/toPercent.ts +0 -10
  117. package/src/functions/toPercentBy100.ts +0 -12
  118. package/src/functions/transformation.ts +0 -59
  119. package/src/functions/uniqueArray.ts +0 -9
  120. package/src/functions/writeClipboardData.ts +0 -17
  121. package/src/library.ts +0 -116
  122. package/src/types/apiTypes.ts +0 -143
  123. package/src/types/basicTypes.ts +0 -155
  124. package/src/types/geoTypes.ts +0 -109
  125. package/src/types/metaTypes.ts +0 -764
  126. package/src/vite-env.d.ts +0 -1
@@ -1,30 +0,0 @@
1
- import { Cache } from './Cache'
2
-
3
- /**
4
- * Class for working with fast cache during code execution.
5
- *
6
- * Класс для работы с быстрым кэшем во время выполнения кода.
7
- */
8
- export class CacheStatic {
9
- private static cache: Cache
10
-
11
- /**
12
- * Getting data for the cache, and if there is no cache, it performs a function to save the cache.
13
- *
14
- * Получение данных для кэша, и если нет кэша, выполняет функцию для сохранения кэша.
15
- * @param name cache name/ название кэша
16
- * @param callback function for the cache/ функция для кэша
17
- * @param comparison additional data for comparison/ дополнительные данные для сравнения
18
- */
19
- static get<T>(
20
- name: string,
21
- callback: () => T,
22
- comparison?: any[]
23
- ): T {
24
- return this.cache.get(name, callback, comparison)
25
- }
26
-
27
- static {
28
- this.cache = new Cache()
29
- }
30
- }
@@ -1,135 +0,0 @@
1
- import { executeFunction } from '../functions/executeFunction'
2
- import { isDomRuntime } from '../functions/isDomRuntime'
3
- import { isFilled } from '../functions/isFilled'
4
- import { transformation } from '../functions/transformation'
5
-
6
- import { CookieBlock } from './CookieBlock'
7
-
8
- type CookieSameSite = 'strict' | 'lax'
9
-
10
- export type CookieOptions = {
11
- age?: number
12
- sameSite?: CookieSameSite
13
- arguments?: string[]
14
- }
15
-
16
- const cookie: Record<string, any> = {}
17
-
18
- /**
19
- * Class for working with cookies.
20
- *
21
- * Класс для управления Cookie.
22
- */
23
- export class Cookie<T> {
24
- value?: T | string
25
- private options: CookieOptions = {}
26
-
27
- constructor(private name: string) {
28
- if (name in items) {
29
- return items[name] as Cookie<T>
30
- }
31
-
32
- this.value = cookie?.[name]
33
- items[name] = this
34
- }
35
-
36
- /**
37
- * Get data or update if none.
38
- *
39
- * Получает данные или обновляет, если их нет.
40
- * @param defaultValue value or function to change data/ значение или функция для изменения данных
41
- * @param options additional parameters/ дополнительные параметры
42
- */
43
- get(
44
- defaultValue?: T | string | (() => (T | string)),
45
- options?: CookieOptions
46
- ) {
47
- if (
48
- this.value === undefined
49
- && defaultValue
50
- ) {
51
- this.set(defaultValue, options)
52
- }
53
-
54
- return this.value
55
- }
56
-
57
- /**
58
- * Updates cookie data.
59
- *
60
- * Обновляет данные cookie.
61
- * @param value value or function to change data/ значение или функция для изменения данных
62
- * @param options additional parameters/ дополнительные параметры
63
- */
64
- set(
65
- value?: T | string | (() => (T | string)),
66
- options?: CookieOptions
67
- ): void {
68
- this.value = executeFunction(value)
69
- Object.assign(this.options, options)
70
-
71
- this.update()
72
- }
73
-
74
- /**
75
- * Delete cookie data.
76
- *
77
- * Удаление данных из cookie.
78
- */
79
- remove() {
80
- this.set('')
81
- }
82
-
83
- /**
84
- * Returns cache time.
85
- *
86
- * Возвращает время кэширования.
87
- */
88
- private getAge(): number {
89
- return this.options?.age ?? (7 * 24 * 60 * 60)
90
- }
91
-
92
- /**
93
- * Update cookie data.
94
- *
95
- * Обновление данных cookie.
96
- */
97
- private update(): void {
98
- if (
99
- isDomRuntime()
100
- && !CookieBlock.get()
101
- ) {
102
- const value = String(this.value ?? '')
103
-
104
- document.cookie = [
105
- `${encodeURIComponent(this.name)}=${encodeURIComponent(value)}`,
106
- `max-age=${value === '' ? '-1' : this.getAge()}`,
107
- `SameSite=${this.options?.sameSite ?? 'strict'}`,
108
- ...(this.options?.arguments ?? [])
109
- ].join('; ')
110
- }
111
- }
112
-
113
- /**
114
- * Update data from cookies.
115
- *
116
- * Обновляет данные из cookies.
117
- */
118
- static updateData() {
119
- for (const item of document.cookie.split(';')) {
120
- const [key, value] = item.trim().split('=')
121
-
122
- if (key && isFilled(value)) {
123
- cookie[key] = transformation(value)
124
- }
125
- }
126
- }
127
-
128
- static {
129
- if (isDomRuntime()) {
130
- this.updateData()
131
- }
132
- }
133
- }
134
-
135
- const items: Record<string, Cookie<any>> = {}
@@ -1,31 +0,0 @@
1
- import { DataStorage } from './DataStorage'
2
-
3
- const STORAGE_NAME_BLOCK = 'cookie-block'
4
-
5
- /**
6
- * Class for changing cookie access status.
7
- *
8
- * Класс для изменения статуса доступа к куки.
9
- */
10
- export class CookieBlock {
11
- static storage = new DataStorage<boolean>(STORAGE_NAME_BLOCK)
12
-
13
- /**
14
- * Obtaining status.
15
- *
16
- * Получение статуса.
17
- */
18
- static get(): boolean {
19
- return this.storage.get() ?? false
20
- }
21
-
22
- /**
23
- * Changing status.
24
- *
25
- * Изменение статуса.
26
- * @param value value to be changed/ значение, на которое будет изменен
27
- */
28
- static set(value: boolean): void {
29
- this.storage.set(value)
30
- }
31
- }
@@ -1,194 +0,0 @@
1
- import { executeFunction } from '../functions/executeFunction'
2
- import { isDomRuntime } from '../functions/isDomRuntime'
3
- import { isNull } from '../functions/isNull'
4
-
5
- type DataStorageValue<T> = {
6
- value: T
7
- age: number
8
- }
9
-
10
- const items: Record<string, DataStorage<any>> = {}
11
- let prefix: string = 'ui-storage'
12
-
13
- /**
14
- * Class for working with localStorage.
15
- *
16
- * Класс для работы с localStorage.
17
- */
18
- export class DataStorage<T> {
19
- /**
20
- * Changing the prefix in key names. Should be called at the beginning of the code.
21
- *
22
- * Изменение префикса в названиях ключей. Вызывать нужно в начале кода.
23
- * @param newPrefix new prefix/ новый префикс
24
- */
25
- static setPrefix(newPrefix: string): void {
26
- prefix = newPrefix
27
- }
28
-
29
- private value?: T
30
- private age?: number
31
-
32
- /**
33
- * Constructor
34
- * @param name value name/ название значения
35
- * @param isSession should we use a session/ использовать ли сессию
36
- */
37
- constructor(
38
- private name: string,
39
- private isSession = false
40
- ) {
41
- const nameCache = `${isSession ? 'session' : 'storage'}#${name}`
42
-
43
- if (nameCache in items) {
44
- return items[nameCache] as DataStorage<T>
45
- }
46
-
47
- this.make()
48
-
49
- items[nameCache] = this
50
- }
51
-
52
- /**
53
- * Getting data from local storage.
54
- *
55
- * Получение данных из локального хранилища.
56
- * @param defaultValue default value/ значение по умолчанию
57
- * @param cache cache time/ время кэширования
58
- */
59
- get(
60
- defaultValue?: T | (() => T),
61
- cache?: number
62
- ): T | undefined {
63
- if (
64
- this.value !== null
65
- && this.value !== undefined
66
- && this.isCache(cache)
67
- ) {
68
- return this.value
69
- }
70
-
71
- if (defaultValue !== undefined) {
72
- return this.set(defaultValue)
73
- }
74
-
75
- return undefined
76
- }
77
-
78
- /**
79
- * Changing data in storage.
80
- *
81
- * Изменение данных в хранилище.
82
- * @param value new values/ новые значения
83
- */
84
- set(value?: T | (() => T)): T | undefined {
85
- this.value = executeFunction(value)
86
- this.age = new Date().getTime()
87
-
88
- if (this.value === undefined) {
89
- this.remove()
90
- } else {
91
- this.getMethod()?.setItem(this.getIndex(), JSON.stringify({
92
- value: this.value,
93
- age: this.age
94
- } as DataStorageValue<T>))
95
- }
96
-
97
- return this.value
98
- }
99
-
100
- /**
101
- * Removing data from storage.
102
- *
103
- * Удаление данных из хранилища.
104
- */
105
- remove(): this {
106
- this.getMethod()?.removeItem(this.getIndex())
107
- return this
108
- }
109
-
110
- /**
111
- * Clearing all data from storage.
112
- *
113
- * Очистка всех данных из хранилища.
114
- */
115
- update(): this {
116
- this.make()
117
- return this
118
- }
119
-
120
- /**
121
- * Checks for storage time limit.
122
- *
123
- * Проверяет на лимит времени хранения.
124
- * @param cache cache time/ время кэширования
125
- */
126
- private isCache(cache?: number) {
127
- return isNull(cache) || (
128
- this.age
129
- && this.age + (cache * 1000) >= new Date().getTime()
130
- )
131
- }
132
-
133
- /**
134
- * Returns an object for working with storage.
135
- *
136
- * Возвращает объект для работы с хранилищем.
137
- */
138
- private getMethod(): Storage | undefined {
139
- if (isDomRuntime()) {
140
- return this.isSession
141
- ? window?.sessionStorage
142
- : window?.localStorage
143
- }
144
-
145
- return undefined
146
- }
147
-
148
- /**
149
- * Getting the storage key name.
150
- *
151
- * Получение имени ключа в хранилище.
152
- */
153
- private getIndex(): string {
154
- return `${prefix}__${this.name}`
155
- }
156
-
157
- /**
158
- * Getting data from storage.
159
- *
160
- * Получение данных из хранилища.
161
- */
162
- private getValue(): DataStorageValue<T> | undefined {
163
- const value = this.getMethod()?.getItem(this.getIndex())
164
-
165
- if (value) {
166
- try {
167
- return JSON.parse(value)
168
- } catch (e) {
169
- console.error('DataStorage', e)
170
- }
171
- }
172
-
173
- return undefined
174
- }
175
-
176
- /**
177
- * Filling in the data from storage.
178
- *
179
- * Заполнение данными из хранилища.
180
- */
181
- private make(): this {
182
- const value = this.getValue()
183
-
184
- if (value) {
185
- this.value = value.value
186
- this.age = value.age
187
- } else {
188
- this.value = undefined
189
- this.age = undefined
190
- }
191
-
192
- return this
193
- }
194
- }