@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.
Files changed (125) hide show
  1. package/dist/functions/copyObjectLite.d.ts +9 -0
  2. package/dist/library.d.ts +1 -0
  3. package/dist/library.js +405 -411
  4. package/package.json +1 -3
  5. package/src/classes/Api.ts +0 -407
  6. package/src/classes/ApiDefault.ts +0 -83
  7. package/src/classes/ApiHeaders.ts +0 -52
  8. package/src/classes/ApiPreparation.ts +0 -114
  9. package/src/classes/ApiResponse.ts +0 -293
  10. package/src/classes/ApiStatus.ts +0 -173
  11. package/src/classes/BroadcastMessage.ts +0 -73
  12. package/src/classes/Cache.ts +0 -60
  13. package/src/classes/CacheItem.ts +0 -95
  14. package/src/classes/CacheStatic.ts +0 -30
  15. package/src/classes/Cookie.ts +0 -135
  16. package/src/classes/CookieBlock.ts +0 -31
  17. package/src/classes/DataStorage.ts +0 -194
  18. package/src/classes/Datetime.ts +0 -891
  19. package/src/classes/EventItem.ts +0 -373
  20. package/src/classes/Geo.ts +0 -320
  21. package/src/classes/GeoFlag.ts +0 -386
  22. package/src/classes/GeoIntl.ts +0 -839
  23. package/src/classes/GeoPhone.ts +0 -272
  24. package/src/classes/Global.ts +0 -32
  25. package/src/classes/Hash.ts +0 -142
  26. package/src/classes/Icons.ts +0 -165
  27. package/src/classes/Loading.ts +0 -90
  28. package/src/classes/Meta.ts +0 -284
  29. package/src/classes/MetaManager.ts +0 -200
  30. package/src/classes/MetaOg.ts +0 -147
  31. package/src/classes/MetaTwitter.ts +0 -154
  32. package/src/classes/ScrollbarWidth.ts +0 -86
  33. package/src/classes/Translate.ts +0 -293
  34. package/src/classes/__tests__/Api.test.ts +0 -728
  35. package/src/classes/__tests__/ApiDefault.test.ts +0 -222
  36. package/src/classes/__tests__/ApiHeaders.test.ts +0 -447
  37. package/src/classes/__tests__/ApiPreparation.test.ts +0 -257
  38. package/src/classes/__tests__/ApiResponse.test.ts +0 -547
  39. package/src/classes/__tests__/ApiStatus.test.ts +0 -403
  40. package/src/classes/__tests__/Meta.test.ts +0 -629
  41. package/src/classes/__tests__/MetaManager.test.ts +0 -836
  42. package/src/classes/__tests__/MetaOg.test.ts +0 -677
  43. package/src/classes/__tests__/MetaTwitter.test.ts +0 -423
  44. package/src/functions/anyToString.ts +0 -36
  45. package/src/functions/applyTemplate.ts +0 -63
  46. package/src/functions/arrFill.ts +0 -10
  47. package/src/functions/copyObject.ts +0 -10
  48. package/src/functions/createElement.ts +0 -40
  49. package/src/functions/domQuerySelector.ts +0 -15
  50. package/src/functions/domQuerySelectorAll.ts +0 -15
  51. package/src/functions/encodeAttribute.ts +0 -15
  52. package/src/functions/eventStopPropagation.ts +0 -10
  53. package/src/functions/executeFunction.ts +0 -13
  54. package/src/functions/executePromise.ts +0 -19
  55. package/src/functions/forEach.ts +0 -39
  56. package/src/functions/frame.ts +0 -38
  57. package/src/functions/getAttributes.ts +0 -27
  58. package/src/functions/getClipboardData.ts +0 -13
  59. package/src/functions/getColumn.ts +0 -18
  60. package/src/functions/getElement.ts +0 -35
  61. package/src/functions/getElementId.ts +0 -39
  62. package/src/functions/getElementItem.ts +0 -27
  63. package/src/functions/getElementOrWindow.ts +0 -23
  64. package/src/functions/getExp.ts +0 -21
  65. package/src/functions/getItemByPath.ts +0 -24
  66. package/src/functions/getKey.ts +0 -9
  67. package/src/functions/getLengthOfAllArray.ts +0 -13
  68. package/src/functions/getMaxLengthAllArray.ts +0 -13
  69. package/src/functions/getMinLengthAllArray.ts +0 -13
  70. package/src/functions/getMouseClient.ts +0 -17
  71. package/src/functions/getMouseClientX.ts +0 -9
  72. package/src/functions/getMouseClientY.ts +0 -9
  73. package/src/functions/getObjectByKeys.ts +0 -24
  74. package/src/functions/getObjectNoUndefined.ts +0 -23
  75. package/src/functions/getObjectOrNone.ts +0 -11
  76. package/src/functions/getRandomText.ts +0 -29
  77. package/src/functions/getRequestString.ts +0 -21
  78. package/src/functions/getStepPercent.ts +0 -19
  79. package/src/functions/getStepValue.ts +0 -19
  80. package/src/functions/goScroll.ts +0 -40
  81. package/src/functions/inArray.ts +0 -10
  82. package/src/functions/initScrollbarOffset.ts +0 -14
  83. package/src/functions/intersectKey.ts +0 -34
  84. package/src/functions/isArray.ts +0 -9
  85. package/src/functions/isDifferent.ts +0 -27
  86. package/src/functions/isDomRuntime.ts +0 -12
  87. package/src/functions/isFilled.ts +0 -49
  88. package/src/functions/isFloat.ts +0 -16
  89. package/src/functions/isFunction.ts +0 -11
  90. package/src/functions/isInDom.ts +0 -15
  91. package/src/functions/isIntegerBetween.ts +0 -11
  92. package/src/functions/isNull.ts +0 -11
  93. package/src/functions/isNumber.ts +0 -16
  94. package/src/functions/isObject.ts +0 -9
  95. package/src/functions/isObjectNotArray.ts +0 -11
  96. package/src/functions/isSelected.ts +0 -32
  97. package/src/functions/isSelectedByList.ts +0 -19
  98. package/src/functions/isString.ts +0 -9
  99. package/src/functions/isWindow.ts +0 -11
  100. package/src/functions/random.ts +0 -10
  101. package/src/functions/replaceRecursive.ts +0 -60
  102. package/src/functions/replaceTemplate.ts +0 -22
  103. package/src/functions/secondToTime.ts +0 -20
  104. package/src/functions/setElementItem.ts +0 -56
  105. package/src/functions/setValues.ts +0 -59
  106. package/src/functions/splice.ts +0 -59
  107. package/src/functions/strFill.ts +0 -12
  108. package/src/functions/toArray.ts +0 -19
  109. package/src/functions/toCamelCase.ts +0 -16
  110. package/src/functions/toCamelCaseFirst.ts +0 -12
  111. package/src/functions/toDate.ts +0 -44
  112. package/src/functions/toKebabCase.ts +0 -25
  113. package/src/functions/toNumber.ts +0 -35
  114. package/src/functions/toNumberByMax.ts +0 -33
  115. package/src/functions/toPercent.ts +0 -10
  116. package/src/functions/toPercentBy100.ts +0 -12
  117. package/src/functions/transformation.ts +0 -59
  118. package/src/functions/uniqueArray.ts +0 -9
  119. package/src/functions/writeClipboardData.ts +0 -17
  120. package/src/library.ts +0 -116
  121. package/src/types/apiTypes.ts +0 -143
  122. package/src/types/basicTypes.ts +0 -155
  123. package/src/types/geoTypes.ts +0 -109
  124. package/src/types/metaTypes.ts +0 -764
  125. package/src/vite-env.d.ts +0 -1
@@ -1,257 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest'
2
- import { ApiPreparation } from '../ApiPreparation'
3
- import type { ApiPreparationEnd } from '../../types/apiTypes'
4
-
5
- describe('ApiPreparation', () => {
6
- let apiPreparation: ApiPreparation
7
-
8
- beforeEach(() => {
9
- apiPreparation = new ApiPreparation()
10
- })
11
-
12
- describe('make', () => {
13
- it('should not call callback when active is false', async () => {
14
- const callback = vi.fn().mockResolvedValue(undefined)
15
- apiPreparation.set(callback)
16
-
17
- await apiPreparation.make(false)
18
-
19
- expect(callback).not.toHaveBeenCalled()
20
- })
21
-
22
- it('should not call callback when callback is not set', async () => {
23
- const result = await apiPreparation.make(true)
24
-
25
- expect(result).toBeUndefined()
26
- })
27
-
28
- it('should call callback when active is true and callback is set', async () => {
29
- const callback = vi.fn().mockResolvedValue(undefined)
30
- apiPreparation.set(callback)
31
-
32
- await apiPreparation.make(true)
33
-
34
- expect(callback).toHaveBeenCalledTimes(1)
35
- })
36
-
37
- it('should wait for callback to complete', async () => {
38
- let callbackCompleted = false
39
- const callback = vi.fn().mockImplementation(async () => {
40
- await new Promise(resolve => setTimeout(resolve, 100))
41
- callbackCompleted = true
42
- })
43
- apiPreparation.set(callback)
44
-
45
- await apiPreparation.make(true)
46
-
47
- expect(callbackCompleted).toBe(true)
48
- })
49
-
50
- it('should handle multiple concurrent calls without overlapping', async () => {
51
- let executionCount = 0
52
- const callback = vi.fn().mockImplementation(async () => {
53
- executionCount++
54
- await new Promise(resolve => setTimeout(resolve, 50))
55
- executionCount--
56
- })
57
- apiPreparation.set(callback)
58
-
59
- // Start multiple concurrent calls
60
- const promises = [
61
- apiPreparation.make(true),
62
- apiPreparation.make(true),
63
- apiPreparation.make(true)
64
- ]
65
-
66
- await Promise.all(promises)
67
-
68
- // Callback should be called 3 times but never overlap
69
- expect(callback).toHaveBeenCalledTimes(3)
70
- expect(executionCount).toBe(0)
71
- })
72
- })
73
-
74
- describe('makeEnd', () => {
75
- it('should return empty object when active is false', async () => {
76
- const callback = vi.fn().mockResolvedValue({ reset: true })
77
- const mockResponse = new Response('{}', { status: 200 })
78
- apiPreparation.setEnd(callback)
79
-
80
- const result = await apiPreparation.makeEnd(false, mockResponse)
81
-
82
- expect(result).toEqual({})
83
- expect(callback).not.toHaveBeenCalled()
84
- })
85
-
86
- it('should return empty object when callback is not set', async () => {
87
- const mockResponse = new Response('{}', { status: 200 })
88
-
89
- const result = await apiPreparation.makeEnd(true, mockResponse)
90
-
91
- expect(result).toEqual({})
92
- })
93
-
94
- it('should call callback and return result when active is true', async () => {
95
- const expectedResult: ApiPreparationEnd = {
96
- reset: true,
97
- data: { message: 'Success' }
98
- }
99
- const callback = vi.fn().mockResolvedValue(expectedResult)
100
- const mockResponse = new Response('{}', { status: 200 })
101
- apiPreparation.setEnd(callback)
102
-
103
- const result = await apiPreparation.makeEnd(true, mockResponse)
104
-
105
- expect(callback).toHaveBeenCalledWith(mockResponse)
106
- expect(result).toEqual(expectedResult)
107
- })
108
-
109
- it('should pass Response object to callback', async () => {
110
- const callback = vi.fn().mockResolvedValue({})
111
- const mockResponse = new Response('{"test": "data"}', {
112
- status: 201,
113
- statusText: 'Created'
114
- })
115
- apiPreparation.setEnd(callback)
116
-
117
- await apiPreparation.makeEnd(true, mockResponse)
118
-
119
- expect(callback).toHaveBeenCalledWith(mockResponse)
120
- })
121
-
122
- it('should handle callback returning reset flag', async () => {
123
- const callback = vi.fn().mockResolvedValue({ reset: true })
124
- const mockResponse = new Response('{}', { status: 200 })
125
- apiPreparation.setEnd(callback)
126
-
127
- const result = await apiPreparation.makeEnd(true, mockResponse)
128
-
129
- expect(result.reset).toBe(true)
130
- })
131
-
132
- it('should handle callback returning data', async () => {
133
- const testData = { userId: 123, token: 'abc' }
134
- const callback = vi.fn().mockResolvedValue({ data: testData })
135
- const mockResponse = new Response('{}', { status: 200 })
136
- apiPreparation.setEnd(callback)
137
-
138
- const result = await apiPreparation.makeEnd(true, mockResponse)
139
-
140
- expect(result.data).toEqual(testData)
141
- })
142
- })
143
-
144
- describe('set', () => {
145
- it('should set callback function', async () => {
146
- const callback = vi.fn().mockResolvedValue(undefined)
147
-
148
- const returnedInstance = apiPreparation.set(callback)
149
-
150
- expect(returnedInstance).toBe(apiPreparation)
151
- await apiPreparation.make(true)
152
- expect(callback).toHaveBeenCalled()
153
- })
154
-
155
- it('should return this for chaining', () => {
156
- const callback = vi.fn().mockResolvedValue(undefined)
157
-
158
- const result = apiPreparation.set(callback)
159
-
160
- expect(result).toBe(apiPreparation)
161
- })
162
-
163
- it('should allow replacing callback', async () => {
164
- const callback1 = vi.fn().mockResolvedValue(undefined)
165
- const callback2 = vi.fn().mockResolvedValue(undefined)
166
-
167
- apiPreparation.set(callback1)
168
- apiPreparation.set(callback2)
169
-
170
- await apiPreparation.make(true)
171
-
172
- expect(callback1).not.toHaveBeenCalled()
173
- expect(callback2).toHaveBeenCalled()
174
- })
175
- })
176
-
177
- describe('setEnd', () => {
178
- it('should set end callback function', async () => {
179
- const callback = vi.fn().mockResolvedValue({})
180
- const mockResponse = new Response('{}', { status: 200 })
181
-
182
- const returnedInstance = apiPreparation.setEnd(callback)
183
-
184
- expect(returnedInstance).toBe(apiPreparation)
185
- await apiPreparation.makeEnd(true, mockResponse)
186
- expect(callback).toHaveBeenCalled()
187
- })
188
-
189
- it('should return this for chaining', () => {
190
- const callback = vi.fn().mockResolvedValue({})
191
-
192
- const result = apiPreparation.setEnd(callback)
193
-
194
- expect(result).toBe(apiPreparation)
195
- })
196
-
197
- it('should allow chaining set and setEnd', async () => {
198
- const callback = vi.fn().mockResolvedValue(undefined)
199
- const callbackEnd = vi.fn().mockResolvedValue({ reset: true })
200
- const mockResponse = new Response('{}', { status: 200 })
201
-
202
- apiPreparation
203
- .set(callback)
204
- .setEnd(callbackEnd)
205
-
206
- await apiPreparation.make(true)
207
- await apiPreparation.makeEnd(true, mockResponse)
208
-
209
- expect(callback).toHaveBeenCalled()
210
- expect(callbackEnd).toHaveBeenCalled()
211
- })
212
-
213
- it('should allow replacing end callback', async () => {
214
- const callback1 = vi.fn().mockResolvedValue({})
215
- const callback2 = vi.fn().mockResolvedValue({ data: 'test' })
216
- const mockResponse = new Response('{}', { status: 200 })
217
-
218
- apiPreparation.setEnd(callback1)
219
- apiPreparation.setEnd(callback2)
220
-
221
- await apiPreparation.makeEnd(true, mockResponse)
222
-
223
- expect(callback1).not.toHaveBeenCalled()
224
- expect(callback2).toHaveBeenCalled()
225
- })
226
- })
227
-
228
- describe('integration', () => {
229
- it('should handle full lifecycle with both callbacks', async () => {
230
- let preparationDone = false
231
- const callback = vi.fn().mockImplementation(async () => {
232
- preparationDone = true
233
- })
234
- const callbackEnd = vi.fn().mockResolvedValue({ reset: true, data: { preparationDone } })
235
- const mockResponse = new Response('{}', { status: 200 })
236
-
237
- apiPreparation.set(callback).setEnd(callbackEnd)
238
-
239
- await apiPreparation.make(true)
240
- const result = await apiPreparation.makeEnd(true, mockResponse)
241
-
242
- expect(preparationDone).toBe(true)
243
- expect(callback).toHaveBeenCalled()
244
- expect(callbackEnd).toHaveBeenCalled()
245
- expect(result.reset).toBe(true)
246
- })
247
-
248
- it('should handle errors in end callback', async () => {
249
- const error = new Error('End processing failed')
250
- const callbackEnd = vi.fn().mockRejectedValue(error)
251
- const mockResponse = new Response('{}', { status: 200 })
252
- apiPreparation.setEnd(callbackEnd)
253
-
254
- await expect(apiPreparation.makeEnd(true, mockResponse)).rejects.toThrow('End processing failed')
255
- })
256
- })
257
- })