@dxtmisha/functional-basic 0.1.0 → 0.1.1

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 (122) hide show
  1. package/package.json +5 -3
  2. package/src/classes/Api.ts +407 -0
  3. package/src/classes/ApiDefault.ts +83 -0
  4. package/src/classes/ApiHeaders.ts +52 -0
  5. package/src/classes/ApiPreparation.ts +114 -0
  6. package/src/classes/ApiResponse.ts +293 -0
  7. package/src/classes/ApiStatus.ts +173 -0
  8. package/src/classes/BroadcastMessage.ts +73 -0
  9. package/src/classes/Cache.ts +60 -0
  10. package/src/classes/CacheItem.ts +95 -0
  11. package/src/classes/CacheStatic.ts +30 -0
  12. package/src/classes/Cookie.ts +135 -0
  13. package/src/classes/CookieBlock.ts +31 -0
  14. package/src/classes/DataStorage.ts +194 -0
  15. package/src/classes/Datetime.ts +891 -0
  16. package/src/classes/EventItem.ts +373 -0
  17. package/src/classes/Geo.ts +320 -0
  18. package/src/classes/GeoFlag.ts +386 -0
  19. package/src/classes/GeoIntl.ts +839 -0
  20. package/src/classes/GeoPhone.ts +272 -0
  21. package/src/classes/Global.ts +32 -0
  22. package/src/classes/Hash.ts +142 -0
  23. package/src/classes/Icons.ts +165 -0
  24. package/src/classes/Loading.ts +90 -0
  25. package/src/classes/Meta.ts +284 -0
  26. package/src/classes/MetaManager.ts +200 -0
  27. package/src/classes/MetaOg.ts +147 -0
  28. package/src/classes/MetaTwitter.ts +154 -0
  29. package/src/classes/ScrollbarWidth.ts +86 -0
  30. package/src/classes/Translate.ts +293 -0
  31. package/src/classes/__tests__/Api.test.ts +728 -0
  32. package/src/classes/__tests__/ApiDefault.test.ts +222 -0
  33. package/src/classes/__tests__/ApiHeaders.test.ts +447 -0
  34. package/src/classes/__tests__/ApiPreparation.test.ts +257 -0
  35. package/src/classes/__tests__/ApiResponse.test.ts +547 -0
  36. package/src/classes/__tests__/ApiStatus.test.ts +403 -0
  37. package/src/classes/__tests__/Meta.test.ts +629 -0
  38. package/src/classes/__tests__/MetaManager.test.ts +836 -0
  39. package/src/classes/__tests__/MetaOg.test.ts +677 -0
  40. package/src/classes/__tests__/MetaTwitter.test.ts +423 -0
  41. package/src/functions/anyToString.ts +36 -0
  42. package/src/functions/applyTemplate.ts +63 -0
  43. package/src/functions/arrFill.ts +10 -0
  44. package/src/functions/copyObject.ts +10 -0
  45. package/src/functions/createElement.ts +40 -0
  46. package/src/functions/domQuerySelector.ts +15 -0
  47. package/src/functions/domQuerySelectorAll.ts +15 -0
  48. package/src/functions/encodeAttribute.ts +15 -0
  49. package/src/functions/eventStopPropagation.ts +10 -0
  50. package/src/functions/executeFunction.ts +13 -0
  51. package/src/functions/executePromise.ts +19 -0
  52. package/src/functions/forEach.ts +39 -0
  53. package/src/functions/frame.ts +38 -0
  54. package/src/functions/getAttributes.ts +27 -0
  55. package/src/functions/getClipboardData.ts +13 -0
  56. package/src/functions/getColumn.ts +18 -0
  57. package/src/functions/getElement.ts +35 -0
  58. package/src/functions/getElementId.ts +39 -0
  59. package/src/functions/getElementItem.ts +27 -0
  60. package/src/functions/getElementOrWindow.ts +23 -0
  61. package/src/functions/getExp.ts +21 -0
  62. package/src/functions/getItemByPath.ts +24 -0
  63. package/src/functions/getKey.ts +9 -0
  64. package/src/functions/getLengthOfAllArray.ts +13 -0
  65. package/src/functions/getMaxLengthAllArray.ts +13 -0
  66. package/src/functions/getMinLengthAllArray.ts +13 -0
  67. package/src/functions/getMouseClient.ts +17 -0
  68. package/src/functions/getMouseClientX.ts +9 -0
  69. package/src/functions/getMouseClientY.ts +9 -0
  70. package/src/functions/getObjectByKeys.ts +24 -0
  71. package/src/functions/getObjectNoUndefined.ts +23 -0
  72. package/src/functions/getObjectOrNone.ts +11 -0
  73. package/src/functions/getRandomText.ts +29 -0
  74. package/src/functions/getRequestString.ts +21 -0
  75. package/src/functions/getStepPercent.ts +19 -0
  76. package/src/functions/getStepValue.ts +19 -0
  77. package/src/functions/goScroll.ts +40 -0
  78. package/src/functions/inArray.ts +10 -0
  79. package/src/functions/initScrollbarOffset.ts +14 -0
  80. package/src/functions/intersectKey.ts +34 -0
  81. package/src/functions/isArray.ts +9 -0
  82. package/src/functions/isDifferent.ts +27 -0
  83. package/src/functions/isDomRuntime.ts +12 -0
  84. package/src/functions/isFilled.ts +49 -0
  85. package/src/functions/isFloat.ts +16 -0
  86. package/src/functions/isFunction.ts +11 -0
  87. package/src/functions/isInDom.ts +15 -0
  88. package/src/functions/isIntegerBetween.ts +11 -0
  89. package/src/functions/isNull.ts +11 -0
  90. package/src/functions/isNumber.ts +16 -0
  91. package/src/functions/isObject.ts +9 -0
  92. package/src/functions/isObjectNotArray.ts +11 -0
  93. package/src/functions/isSelected.ts +32 -0
  94. package/src/functions/isSelectedByList.ts +19 -0
  95. package/src/functions/isString.ts +9 -0
  96. package/src/functions/isWindow.ts +11 -0
  97. package/src/functions/random.ts +10 -0
  98. package/src/functions/replaceRecursive.ts +60 -0
  99. package/src/functions/replaceTemplate.ts +22 -0
  100. package/src/functions/secondToTime.ts +20 -0
  101. package/src/functions/setElementItem.ts +56 -0
  102. package/src/functions/setValues.ts +59 -0
  103. package/src/functions/splice.ts +59 -0
  104. package/src/functions/strFill.ts +12 -0
  105. package/src/functions/toArray.ts +19 -0
  106. package/src/functions/toCamelCase.ts +16 -0
  107. package/src/functions/toCamelCaseFirst.ts +12 -0
  108. package/src/functions/toDate.ts +44 -0
  109. package/src/functions/toKebabCase.ts +25 -0
  110. package/src/functions/toNumber.ts +35 -0
  111. package/src/functions/toNumberByMax.ts +33 -0
  112. package/src/functions/toPercent.ts +10 -0
  113. package/src/functions/toPercentBy100.ts +12 -0
  114. package/src/functions/transformation.ts +59 -0
  115. package/src/functions/uniqueArray.ts +9 -0
  116. package/src/functions/writeClipboardData.ts +17 -0
  117. package/src/library.ts +116 -0
  118. package/src/types/apiTypes.ts +143 -0
  119. package/src/types/basicTypes.ts +155 -0
  120. package/src/types/geoTypes.ts +109 -0
  121. package/src/types/metaTypes.ts +764 -0
  122. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,12 @@
1
+ import { toCamelCase } from './toCamelCase'
2
+
3
+ /**
4
+ * Convert a String to Camel Case (+ first letter).
5
+ *
6
+ * Преобразование строки в Camel Case (+ первая буква).
7
+ * @param value input value/ входное значение
8
+ */
9
+ export function toCamelCaseFirst(value: string): string {
10
+ return toCamelCase(value)
11
+ .replace(/^([a-z])/, char => `${char.toUpperCase()}`)
12
+ }
@@ -0,0 +1,44 @@
1
+ import { isNull } from './isNull'
2
+ import { Geo } from '../classes/Geo'
3
+
4
+ /**
5
+ * Conversion to Date object.
6
+ *
7
+ * Преобразование в объект Date.
8
+ * @param value input value/ входное значение
9
+ */
10
+ export function toDate<T extends Date | number | string>(value?: T): (T & Date) | Date {
11
+ if (value instanceof Date) {
12
+ return value
13
+ }
14
+
15
+ if (isNull(value)) {
16
+ return new Date()
17
+ }
18
+
19
+ if (typeof value === 'number') {
20
+ return new Date(value)
21
+ }
22
+
23
+ let date: string = value
24
+ let timeZone: string = Geo.getTimezoneFormat()
25
+
26
+ value.replace(/^([\s\S]+)([-+]\d{2}:?\d{2})$/, (all, d: string, z: string) => {
27
+ date = d
28
+ timeZone = z
29
+
30
+ return all
31
+ })
32
+
33
+ const stringDate = ((/^\d{4}\d{2}\d{2}$/.exec(date)) && `${date.replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3')}T00:00:00`)
34
+ ?? ((/^\d{4}\d{2}$/.exec(date)) && `${date.replace(/^(\d{4})(\d{2})$/, '$1-$2')}-01T00:00:00`)
35
+ ?? ((/^\d{4}\d{2}\d{2} \d{2}:\d{2}:\d{2}$/.exec(date)) && date.replace(/^(\d{4})(\d{2})(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, '$1-$2-$3T$4:$5:$6'))
36
+ ?? ((/^\d{4}-\d{2}-\d{2}$/.exec(date)) && `${date}T00:00:00`)
37
+ ?? ((/^\d{4}-\d{2}$/.exec(date)) && `${date}-01T00:00:00`)
38
+ ?? ((/^\d{4}$/.exec(date)) && `${date}-01-01T00:00:00`)
39
+ ?? ((/^\d{2}:\d{2}$/.exec(date)) && `2000-01-01T${date}:00`)
40
+ ?? ((/^\d{2}:\d{2}:\d{2}$/.exec(date)) && `2000-01-01T${date}`)
41
+ ?? (date.replace(' ', 'T'))
42
+
43
+ return new Date(`${stringDate}${timeZone}`)
44
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Преобразует строку в формат kebab-case.
3
+ * Преобразует все заглавные буквы в строчные, заменяет пробелы и другие символы на дефисы.
4
+ *
5
+ * Converts a string to kebab-case.
6
+ * It converts uppercase letters to lowercase, replaces spaces and other characters with dashes.
7
+ *
8
+ * @param value - Строка, которую необходимо преобразовать.
9
+ *
10
+ * The string to be converted.
11
+ * @returns Строка в формате kebab-case.
12
+ *
13
+ * The string in kebab-case format.
14
+ */
15
+ export function toKebabCase(value: string): string {
16
+ return value
17
+ .toString()
18
+ .trim()
19
+ .replace(/[^\w- ]+/g, '')
20
+ .replace(/ +/g, '-')
21
+ .replace(/(?<=[A-Z])([A-Z])/g, char => `${char.toLowerCase()}`)
22
+ .replace(/^[A-Z]/, char => char.toLowerCase())
23
+ .replace(/(?<=[\w ])[A-Z]/g, char => `-${char.toLowerCase()}`)
24
+ .replace(/[A-Z]/g, char => char.toLowerCase())
25
+ }
@@ -0,0 +1,35 @@
1
+ import type { NumberOrString } from '../types/basicTypes'
2
+
3
+ /**
4
+ * The method parses a string argument and returns a floating point number.
5
+ *
6
+ * Метод принимает строку в качестве аргумента и возвращает десятичное число
7
+ * @param value input value/ входное значение
8
+ */
9
+ export function toNumber<T extends NumberOrString>(value?: T): (T & number) | number {
10
+ if (typeof value === 'number') {
11
+ return value
12
+ }
13
+
14
+ if (!value) {
15
+ return 0
16
+ }
17
+
18
+ let number = value.replace(/[^\d., ]+/ig, '')
19
+
20
+ if (number.match(/( [0-9]{3}[ ,.]|[0-9] [0-9])/ig)) {
21
+ number = number
22
+ .replace(/ /ig, '')
23
+ .replace(/,/ig, '.')
24
+ } else if (number.match(/,[0-9]{3}[,.]/ig)) {
25
+ number = number.replace(/,/ig, '')
26
+ } else if (number.match(/[.][0-9]{3}[,.]/ig)) {
27
+ number = number
28
+ .replace(/[.]/ig, '')
29
+ .replace(/,/ig, '.')
30
+ } else {
31
+ number = number.replace(/,/ig, '.')
32
+ }
33
+
34
+ return parseFloat(number)
35
+ }
@@ -0,0 +1,33 @@
1
+ import { toNumber } from './toNumber'
2
+
3
+ import { GeoIntl } from '../classes/GeoIntl'
4
+
5
+ /**
6
+ * Converts the data into a number, taking into account the maximum permissible value.<br>
7
+ * Преобразует данные в число с учетом максимально допустимого значения.
8
+ * @param value input value /<br>входное значение
9
+ * @param max maximum achievable value /<br>максимально достижимое значение
10
+ * @param formatting format the number /<br>форматировать число
11
+ * @param language formatting language /<br>язык форматирования
12
+ */
13
+ export function toNumberByMax(
14
+ value: string | number,
15
+ max?: string | number,
16
+ formatting?: boolean,
17
+ language?: string
18
+ ) {
19
+ const number = toNumber(value)
20
+ const maxNumber = toNumber(max)
21
+
22
+ if (max && maxNumber < number) {
23
+ return `${getFormatting(maxNumber, formatting, language)}+`
24
+ }
25
+
26
+ return getFormatting(number, formatting, language)
27
+ }
28
+
29
+ const getFormatting = (
30
+ value: number,
31
+ formatting?: boolean,
32
+ language?: string
33
+ ) => formatting ? new GeoIntl(language).number(value) : value
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts values to percentages
3
+ *
4
+ * Преобразует значения в проценты
5
+ * @param maxValue maximum value/ максимальное значение
6
+ * @param value current value/ текущее значение
7
+ */
8
+ export function toPercent(maxValue: number, value: number): number {
9
+ return 1 / maxValue * value
10
+ }
@@ -0,0 +1,12 @@
1
+ import { toPercent } from './toPercent'
2
+
3
+ /**
4
+ * Converts values to percentages (three-digit)
5
+ *
6
+ * Преобразует значения в проценты (трёхзначный)
7
+ * @param maxValue maximum value/ максимальное значение
8
+ * @param value current value/ текущее значение
9
+ */
10
+ export function toPercentBy100(maxValue: number, value: number): number {
11
+ return toPercent(maxValue, value) * 100
12
+ }
@@ -0,0 +1,59 @@
1
+ import { isDomRuntime } from './isDomRuntime'
2
+ import { type FunctionArgs } from '../types/basicTypes'
3
+
4
+ /**
5
+ * Преобразует строку в соответствующий тип данных.
6
+ * В зависимости от содержания строки, она может быть преобразована в
7
+ * `undefined`, `null`, `true`, `false`, объект, число или функцию.
8
+ *
9
+ * Transforms a string into the corresponding data type.
10
+ * Based on the string content, it may be transformed into `undefined`,
11
+ * `null`, `true`, `false`, object, number, or function.
12
+ *
13
+ * @param value - Значение, которое необходимо преобразовать
14
+ *
15
+ * The value to be transformed
16
+ * @param isFunction - Флаг, который указывает, необходимо ли проверять функцию
17
+ * в глобальном объекте window
18
+ *
19
+ * A flag that indicates whether to check for a function in the global window object
20
+ * @returns Преобразованное значение
21
+ *
22
+ * The transformed value
23
+ */
24
+ export function transformation(value: any, isFunction = false): any {
25
+ if (typeof value === 'string') {
26
+ const item = value.trim()
27
+
28
+ switch (item) {
29
+ case 'undefined':
30
+ return undefined
31
+ case 'null':
32
+ return null
33
+ case 'true':
34
+ return true
35
+ case 'false':
36
+ return false
37
+ default:
38
+ if (/^[{[]/.exec(item)) {
39
+ try {
40
+ return JSON.parse(item)
41
+ } catch (e) {
42
+ console.error('transformation: JSON error', e)
43
+ }
44
+ } else if (/^[0-9]+\.[0-9.]+$/.exec(item)) {
45
+ return parseFloat(item)
46
+ } else if (/^[0-9]+$/.exec(item)) {
47
+ return parseInt(item, 10)
48
+ } else if (
49
+ isFunction
50
+ && isDomRuntime()
51
+ && typeof window?.[item as any] === 'function'
52
+ ) {
53
+ return window[item as any] as any as FunctionArgs<any, any>
54
+ }
55
+ }
56
+ }
57
+
58
+ return value
59
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Removes duplicate entries in an array.
3
+ *
4
+ * Удаляет повторяющиеся записи в массиве.
5
+ * @param value input value/ входное значение
6
+ */
7
+ export function uniqueArray<T>(value: T[]): T[] {
8
+ return [...new Set(value)]
9
+ }
@@ -0,0 +1,17 @@
1
+ import { isDomRuntime } from './isDomRuntime'
2
+
3
+ /**
4
+ * Writes data to the buffer.
5
+ *
6
+ * Записывает данные в буфер.
7
+ * @param text text for recording/ текст для записи
8
+ */
9
+ export async function writeClipboardData(text: string) {
10
+ if (isDomRuntime()) {
11
+ try {
12
+ await navigator.clipboard.writeText(text)
13
+ } catch (_) {
14
+ document?.execCommand(text)
15
+ }
16
+ }
17
+ }
package/src/library.ts ADDED
@@ -0,0 +1,116 @@
1
+ // Classes
2
+ export * from './classes/Api'
3
+ export * from './classes/ApiDefault'
4
+ export * from './classes/ApiHeaders'
5
+ export * from './classes/ApiPreparation'
6
+ export * from './classes/ApiResponse'
7
+ export * from './classes/ApiStatus'
8
+ export * from './classes/BroadcastMessage'
9
+ export * from './classes/Cache'
10
+ export * from './classes/CacheItem'
11
+ export * from './classes/CacheStatic'
12
+ export * from './classes/Cookie'
13
+ export * from './classes/CookieBlock'
14
+ export * from './classes/DataStorage'
15
+ export * from './classes/Datetime'
16
+ export * from './classes/EventItem'
17
+ export * from './classes/Geo'
18
+ export * from './classes/GeoFlag'
19
+ export * from './classes/GeoIntl'
20
+ export * from './classes/GeoPhone'
21
+ export * from './classes/Global'
22
+ export * from './classes/Hash'
23
+ export * from './classes/Icons'
24
+ export * from './classes/Loading'
25
+ export * from './classes/Meta'
26
+ export * from './classes/MetaManager'
27
+ export * from './classes/MetaOg'
28
+ export * from './classes/MetaTwitter'
29
+ export * from './classes/ScrollbarWidth'
30
+ export * from './classes/Translate'
31
+
32
+ // Composables
33
+
34
+ // Functions
35
+ export * from './functions/anyToString'
36
+ export * from './functions/applyTemplate'
37
+ export * from './functions/arrFill'
38
+ export * from './functions/copyObject'
39
+ export * from './functions/createElement'
40
+ export * from './functions/domQuerySelector'
41
+ export * from './functions/domQuerySelectorAll'
42
+ export * from './functions/encodeAttribute'
43
+ export * from './functions/eventStopPropagation'
44
+ export * from './functions/executeFunction'
45
+ export * from './functions/executePromise'
46
+ export * from './functions/forEach'
47
+ export * from './functions/frame'
48
+ export * from './functions/getAttributes'
49
+ export * from './functions/getClipboardData'
50
+ export * from './functions/getColumn'
51
+ export * from './functions/getElement'
52
+ export * from './functions/getElementId'
53
+ export * from './functions/getElementItem'
54
+ export * from './functions/getElementOrWindow'
55
+ export * from './functions/getExp'
56
+ export * from './functions/getItemByPath'
57
+ export * from './functions/getKey'
58
+ export * from './functions/getLengthOfAllArray'
59
+ export * from './functions/getMaxLengthAllArray'
60
+ export * from './functions/getMinLengthAllArray'
61
+ export * from './functions/getMouseClient'
62
+ export * from './functions/getMouseClientX'
63
+ export * from './functions/getMouseClientY'
64
+ export * from './functions/getObjectByKeys'
65
+ export * from './functions/getObjectNoUndefined'
66
+ export * from './functions/getObjectOrNone'
67
+ export * from './functions/getRandomText'
68
+ export * from './functions/getRequestString'
69
+ export * from './functions/getStepPercent'
70
+ export * from './functions/getStepValue'
71
+ export * from './functions/goScroll'
72
+ export * from './functions/inArray'
73
+ export * from './functions/initScrollbarOffset'
74
+ export * from './functions/intersectKey'
75
+ export * from './functions/isArray'
76
+ export * from './functions/isDifferent'
77
+ export * from './functions/isDomRuntime'
78
+ export * from './functions/isFilled'
79
+ export * from './functions/isFloat'
80
+ export * from './functions/isFunction'
81
+ export * from './functions/isInDom'
82
+ export * from './functions/isIntegerBetween'
83
+ export * from './functions/isNull'
84
+ export * from './functions/isNumber'
85
+ export * from './functions/isObject'
86
+ export * from './functions/isObjectNotArray'
87
+ export * from './functions/isSelected'
88
+ export * from './functions/isSelectedByList'
89
+ export * from './functions/isString'
90
+ export * from './functions/isWindow'
91
+ export * from './functions/random'
92
+ export * from './functions/replaceRecursive'
93
+ export * from './functions/replaceTemplate'
94
+ export * from './functions/secondToTime'
95
+ export * from './functions/setElementItem'
96
+ export * from './functions/setValues'
97
+ export * from './functions/splice'
98
+ export * from './functions/strFill'
99
+ export * from './functions/toArray'
100
+ export * from './functions/toCamelCase'
101
+ export * from './functions/toCamelCaseFirst'
102
+ export * from './functions/toDate'
103
+ export * from './functions/toKebabCase'
104
+ export * from './functions/toNumber'
105
+ export * from './functions/toNumberByMax'
106
+ export * from './functions/toPercent'
107
+ export * from './functions/toPercentBy100'
108
+ export * from './functions/transformation'
109
+ export * from './functions/uniqueArray'
110
+ export * from './functions/writeClipboardData'
111
+
112
+ // Types
113
+ export * from './types/apiTypes'
114
+ export * from './types/basicTypes'
115
+ export * from './types/geoTypes'
116
+ export * from './types/metaTypes'
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Supported HTTP methods for API requests.
3
+ * Поддерживаемые HTTP-методы для API-запросов.
4
+ */
5
+ export enum ApiMethodItem {
6
+ /**
7
+ * HTTP GET — used to retrieve resources (no request body).
8
+ * HTTP GET — используется для получения ресурсов (без тела запроса).
9
+ */
10
+ get = 'GET',
11
+
12
+ /**
13
+ * HTTP POST — used to create resources or send data.
14
+ * HTTP POST — используется для создания ресурсов или отправки данных.
15
+ */
16
+ post = 'POST',
17
+
18
+ /**
19
+ * HTTP PUT — used to update/replace resources.
20
+ * HTTP PUT — используется для обновления/замены ресурсов.
21
+ */
22
+ put = 'PUT',
23
+
24
+ /**
25
+ * HTTP DELETE — used to delete resources.
26
+ * HTTP DELETE — используется для удаления ресурсов.
27
+ */
28
+ delete = 'DELETE'
29
+ }
30
+
31
+ /**
32
+ * Supported HTTP methods type/ Тип HTTP-методов
33
+ * (derived from ApiMethodItem enum)/ (получен из перечисления ApiMethodItem)
34
+ */
35
+ export type ApiMethod = string & ApiMethodItem
36
+
37
+ /**
38
+ * Options for making API requests/ Опции для выполнения API-запросов
39
+ */
40
+ export type ApiFetch = {
41
+ /** Use base API URL/ Использовать базовый URL API */
42
+ api?: boolean
43
+
44
+ /** Endpoint path relative to base URL/ Путь endpoint относительно базового URL */
45
+ path?: string
46
+
47
+ /** Complete URL (overrides api + path)/ Полный URL (переопределяет api + path) */
48
+ pathFull?: string
49
+
50
+ /** HTTP method/ HTTP метод */
51
+ method?: ApiMethod
52
+
53
+ /** Request body data or query parameters/ Данные тела запроса или параметры запроса */
54
+ request?: FormData | Record<string, any> | string
55
+
56
+ /** Include authentication headers/ Включить заголовки аутентификации */
57
+ auth?: boolean
58
+
59
+ /** Custom headers (null = no headers)/ Пользовательские заголовки (null = без заголовков) */
60
+ headers?: Record<string, string> | null
61
+
62
+ /** Content-Type header value/ Значение заголовка Content-Type */
63
+ type?: string
64
+
65
+ /** Extract 'data' field from response/ Извлечь поле 'data' из ответа */
66
+ toData?: boolean
67
+
68
+ /** Use global response cache/ Использовать глобальный кеш ответов */
69
+ global?: boolean
70
+
71
+ /** Enable development logging/ Включить логирование разработки */
72
+ devMode?: boolean
73
+
74
+ /** Suppress error logging/ Подавить логирование ошибок */
75
+ hideError?: boolean
76
+
77
+ /** Custom response processor/ Пользовательский процессор ответа */
78
+ queryReturn?: (query: Response) => Promise<any>
79
+
80
+ /** Run global preparation hooks/ Запускать глобальные хуки подготовки */
81
+ globalPreparation?: boolean
82
+
83
+ /** Run global end hooks/ Запускать глобальные хуки завершения */
84
+ globalEnd?: boolean
85
+
86
+ /** Additional fetch() options/ Дополнительные опции fetch() */
87
+ init?: RequestInit
88
+ }
89
+
90
+ /**
91
+ * Mock API response descriptor/ Описание мок-ответа API
92
+ */
93
+ export type ApiResponseItem = {
94
+ /** Path string or RegExp to match request URL/ Путь или RegExp для сопоставления URL */
95
+ path: string | RegExp
96
+ /** Expected HTTP method/ Ожидаемый HTTP метод */
97
+ method: ApiMethod
98
+ /** Expected request payload or special marker '*any'/ Ожидаемая нагрузка запроса или маркер '*any' */
99
+ request?: ApiFetch['request'] | '*any'
100
+ /** Static response or factory function/ Статический ответ или функция, возвращающая ответ */
101
+ response: any | ((request?: ApiFetch['request']) => any)
102
+ /** Disable this mock/ Отключить этот мок */
103
+ disable?: any
104
+ /** Mark as global mock/ Мок для глобального использования */
105
+ isForGlobal?: boolean
106
+ /** Simulate network lag/ Имитировать задержку */
107
+ lag?: any
108
+ }
109
+
110
+ /**
111
+ * Shape of API response data wrapper/ Структура обёртки данных ответа API
112
+ */
113
+ export type ApiData<T>
114
+ = T
115
+ & {
116
+ /** Primary payload (optional)/ Основная полезная нагрузка (опционально) */
117
+ data?: T
118
+ /** Success flag/ Флаг успешности */
119
+ success?: boolean
120
+ }
121
+
122
+ /**
123
+ * Result of global preparation/end hooks/ Результат глобальных хуков
124
+ */
125
+ export type ApiPreparationEnd = {
126
+ /** Reset flag to indicate state reset/ Флаг сброса состояния */
127
+ reset?: boolean
128
+ /** Arbitrary data returned by hook/ Произвольные данные, возвращаемые хуком */
129
+ data?: any
130
+ }
131
+
132
+ /**
133
+ * Default API request data type/ Тип данных запроса API по умолчанию
134
+ */
135
+ export type ApiDefaultValue = Record<string, any>
136
+
137
+ export type ApiStatusItem = {
138
+ status?: number
139
+ statusText?: string
140
+ error?: string
141
+ lastResponse?: any
142
+ lastMessage?: string
143
+ }