@krainovsd/js-helpers 0.15.2 → 0.16.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 (58) hide show
  1. package/lib/cjs/index.cjs +658 -560
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/esm/{lib/api/middlewares/console-post-middleware.js → api/after/logger-after-handler.js} +5 -5
  4. package/lib/esm/api/after/logger-after-handler.js.map +1 -0
  5. package/lib/esm/api/api.constants.js +23 -0
  6. package/lib/esm/api/api.constants.js.map +1 -0
  7. package/lib/esm/api/api.js +343 -0
  8. package/lib/esm/api/api.js.map +1 -0
  9. package/lib/esm/{lib/api/middlewares/console-middleware.js → api/before/logger-before-handler.js} +4 -4
  10. package/lib/esm/api/before/logger-before-handler.js.map +1 -0
  11. package/lib/esm/{lib/api/middlewares/oauth-middleware.js → api/before/oauth-before-handler.js} +15 -15
  12. package/lib/esm/api/before/oauth-before-handler.js.map +1 -0
  13. package/lib/esm/{lib/api/oauth/token.js → api/oauth.js} +33 -27
  14. package/lib/esm/api/oauth.js.map +1 -0
  15. package/lib/esm/constants/errors.js +16 -0
  16. package/lib/esm/constants/errors.js.map +1 -0
  17. package/lib/esm/constants/index.js +27 -0
  18. package/lib/esm/constants/index.js.map +1 -0
  19. package/lib/esm/index.js +9 -8
  20. package/lib/esm/index.js.map +1 -1
  21. package/lib/esm/lib/colors/get-color-format.js +1 -2
  22. package/lib/esm/lib/colors/get-color-format.js.map +1 -1
  23. package/lib/esm/lib/colors/take-opacity-colors.js +1 -2
  24. package/lib/esm/lib/colors/take-opacity-colors.js.map +1 -1
  25. package/lib/esm/lib/colors/transform-to-color.js +1 -2
  26. package/lib/esm/lib/colors/transform-to-color.js.map +1 -1
  27. package/lib/esm/lib/date/get-date-by-rules.js +1 -2
  28. package/lib/esm/lib/date/get-date-by-rules.js.map +1 -1
  29. package/lib/esm/lib/date/is-yesterday.js +0 -1
  30. package/lib/esm/lib/date/is-yesterday.js.map +1 -1
  31. package/lib/esm/lib/utils/build-query-string.js.map +1 -1
  32. package/lib/esm/lib/utils/{create-url-with-params.js → create-url-with-queries.js} +3 -3
  33. package/lib/esm/lib/utils/create-url-with-queries.js.map +1 -0
  34. package/lib/esm/lib/utils/field-view-format.js +1 -2
  35. package/lib/esm/lib/utils/field-view-format.js.map +1 -1
  36. package/lib/index.d.ts +226 -171
  37. package/package.json +4 -2
  38. package/lib/esm/constants/api.js +0 -10
  39. package/lib/esm/constants/api.js.map +0 -1
  40. package/lib/esm/constants/colors.js +0 -9
  41. package/lib/esm/constants/colors.js.map +0 -1
  42. package/lib/esm/constants/date.js +0 -11
  43. package/lib/esm/constants/date.js.map +0 -1
  44. package/lib/esm/constants/fields.js +0 -11
  45. package/lib/esm/constants/fields.js.map +0 -1
  46. package/lib/esm/lib/api/constants.js +0 -4
  47. package/lib/esm/lib/api/constants.js.map +0 -1
  48. package/lib/esm/lib/api/core.js +0 -187
  49. package/lib/esm/lib/api/core.js.map +0 -1
  50. package/lib/esm/lib/api/middlewares/console-middleware.js.map +0 -1
  51. package/lib/esm/lib/api/middlewares/console-post-middleware.js.map +0 -1
  52. package/lib/esm/lib/api/middlewares/index.js +0 -64
  53. package/lib/esm/lib/api/middlewares/index.js.map +0 -1
  54. package/lib/esm/lib/api/middlewares/oauth-middleware.js.map +0 -1
  55. package/lib/esm/lib/api/oauth/token.js.map +0 -1
  56. package/lib/esm/lib/api/oauth/user.js +0 -35
  57. package/lib/esm/lib/api/oauth/user.js.map +0 -1
  58. package/lib/esm/lib/utils/create-url-with-params.js.map +0 -1
package/lib/index.d.ts CHANGED
@@ -1,65 +1,140 @@
1
- import { Response as Response$1, Headers as Headers$1, RequestInfo, RequestInit } from 'node-fetch';
2
1
  import { Dayjs } from 'dayjs';
2
+ import { Response as Response$1, RequestInfo, RequestInit, Headers as Headers$1 } from 'node-fetch';
3
3
 
4
- declare const DATE_TYPES: {
5
- readonly Days: "days";
6
- readonly Months: "months";
7
- readonly Years: "years";
8
- readonly Seconds: "seconds";
9
- readonly Minutes: "minutes";
10
- readonly Hours: "hours";
4
+ type DownloadFileOptions = {
5
+ data: Blob;
6
+ fileName: string;
7
+ mimeType: string;
11
8
  };
9
+ declare function downloadFile({ data, fileName, mimeType }: DownloadFileOptions): null;
10
+
11
+ declare function downloadJson(data: unknown, name: string): null | undefined;
12
12
 
13
- declare const API_MIDDLEWARES: {
14
- readonly Oauth: "oauth";
15
- readonly Logger: "logger";
13
+ declare function readFile(file: File): Promise<unknown>;
14
+
15
+ type PositionPlacements = "bottom-center" | "bottom-left" | "bottom-right" | "right-center" | "right-top" | "right-bottom" | "top-left" | "top-center" | "top-right" | "left-center" | "left-top" | "left-bottom" | "flex";
16
+ type VisiblePosition = {
17
+ top: number;
18
+ left: number;
19
+ right: number;
20
+ bottom: number;
21
+ placement: PositionPlacements;
22
+ };
23
+ type InitialPosition = {
24
+ targetNode?: HTMLElement;
25
+ position?: {
26
+ x: number;
27
+ y: number;
28
+ width: number;
29
+ height: number;
30
+ };
16
31
  };
17
- declare const POST_API_MIDDLEWARES: {
18
- readonly Logger: "logger";
32
+ type GetVisiblePositionOptions = {
33
+ node: HTMLElement;
34
+ initialPosition?: InitialPosition;
35
+ visibleArea?: HTMLElement;
36
+ placement?: Exclude<PositionPlacements, "flex">;
37
+ stepX?: number;
38
+ stepY?: number;
39
+ flex?: boolean;
40
+ nested?: boolean;
19
41
  };
42
+ declare function getVisiblePosition({ initialPosition, node, visibleArea, placement, stepX, stepY, flex, nested, }: GetVisiblePositionOptions): VisiblePosition;
20
43
 
21
- declare const IS_JEST: boolean;
22
- declare const IS_BUN: boolean;
23
- declare const IS_DENO: boolean;
24
- declare const IS_NODE: boolean;
25
- declare const IS_WEB_WORKER: boolean;
26
- declare const IS_BROWSER: boolean;
44
+ declare function getQueryValues<K extends string>(keys: K[]): Record<K, string | string[] | undefined> | null;
27
45
 
28
- declare const COLOR_FORMATS: {
29
- readonly Hex: "HEX";
30
- readonly Rgb: "RGB";
31
- readonly Rgba: "RGBA";
32
- readonly Hsl: "HSL";
33
- };
46
+ declare function execAnimation(element: HTMLElement | null | undefined, className: string, autoCloseDelay?: number): Promise<unknown>;
34
47
 
35
- declare const FIELD_TYPES: {
36
- readonly Date: "date";
37
- readonly Time: "time";
38
- readonly DateTime: "dateTime";
39
- readonly String: "string";
40
- readonly Number: "number";
41
- readonly Array: "array";
42
- };
48
+ declare function copyToClipboard(textToCopy: string): Promise<boolean>;
43
49
 
44
- type Maybe<T> = T | undefined | null;
45
- type ValueOf<T> = T extends {} ? T[keyof T] : unknown;
46
- type IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
50
+ declare function extractQueries(): Record<string, string[] | undefined>;
51
+
52
+ declare function getColorFormat(color: string): "HEX" | "RGB" | "RGBA" | "HSL" | undefined;
53
+
54
+ declare function takeOpacityColors(color: string | undefined, opacities: number[]): string[];
55
+
56
+ declare function transformHEXtoRGB(hex: string): string;
57
+
58
+ declare function transformRGBtoRGBA(rgb: string, opacity: number): string;
47
59
 
48
- type ParamValueType = string | number | boolean;
49
- type ParamsType = Record<string, ParamValueType | ParamValueType[] | null | undefined>;
50
- type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
60
+ declare function transformRGBAtoRGB(rgba: string): string;
61
+
62
+ declare const RESPONSE_DATA_SYMBOL: unique symbol;
63
+ declare const REQUEST_ERROR: {
64
+ readonly HTTP_ERROR: "http";
65
+ readonly NETWORK_ERROR: "network";
66
+ readonly TIMEOUT_ERROR: "timeout";
67
+ readonly ABORT_ERROR: "abort";
68
+ readonly VALIDATION_ERROR: "validation";
69
+ readonly CACHE_ERROR: "cache";
70
+ readonly UNKNOWN_ERROR: "unknown";
71
+ };
72
+ declare class OauthState {
73
+ private _fetching;
74
+ get fetching(): boolean;
75
+ set fetching(value: boolean);
76
+ }
77
+ declare const OAUTH_STATE: OauthState;
78
+
79
+ type RequestQueryValue = string | number | boolean;
80
+ type RequestQuery = Record<string, RequestQueryValue | RequestQueryValue[] | null | undefined>;
81
+ type RequestHeader = Record<string, string | string[] | undefined>;
82
+ type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
83
+ type RequestError = ValueOf<typeof REQUEST_ERROR>;
51
84
  type RequestInterface<IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming> = {
52
85
  path: string;
53
86
  method: RequestMethod;
54
87
  body?: Outcoming;
55
- params?: ParamsType;
56
- headers?: Record<string, string | undefined>;
88
+ queries?: RequestQuery;
89
+ headers?: RequestHeader;
90
+ /** A count of milliseconds before start request */
57
91
  delay?: number;
92
+ /** A value that will be returned immediately */
58
93
  mock?: (() => IncomingApi) | IncomingApi;
94
+ /** A value that will be returned after error */
59
95
  defaultResponse?: (() => IncomingApi) | IncomingApi;
60
- downloadFile?: boolean;
96
+ /** A boolean to download file after response */
97
+ download?: boolean;
61
98
  signal?: AbortSignal;
99
+ /** A token for Authorization header */
62
100
  token?: string;
101
+ /** A boolean to activate oauth flow and then retry */
102
+ refetchNoAuth?: boolean;
103
+ /** A handlers before start request that rewrite global's handlers */
104
+ beforeHandlers?: BeforeHandler[];
105
+ /** A handlers after stop request that rewrite global's handlers */
106
+ afterHandlers?: AfterHandler[];
107
+ /** A handlers before start request with global's handlers */
108
+ additionalBeforeHandlers?: BeforeHandler[];
109
+ /** A handlers after stop request with global's handlers */
110
+ additionalAfterHandlers?: AfterHandler[];
111
+ /** An error handler */
112
+ onError?: (type: RequestError, error: ResponseError) => void;
113
+ /** An array of retries strategy where the number is the delay before retry, and size is the count of retries */
114
+ retries?: number[];
115
+ /** A count of millisecond before timeout error */
116
+ timeout?: number;
117
+ /** A string indicating how the request will interact with the browser's cache to set request's cache. */
118
+ cache?: RequestCache;
119
+ /** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
120
+ credentials?: RequestCredentials;
121
+ /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
122
+ integrity?: string;
123
+ /** A boolean to set request's keepalive. */
124
+ keepalive?: boolean;
125
+ /** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
126
+ mode?: RequestMode;
127
+ priority?: RequestPriority;
128
+ /** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
129
+ redirect?: RequestRedirect;
130
+ /** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */
131
+ referrer?: string;
132
+ /** A referrer policy to set request's referrerPolicy. */
133
+ referrerPolicy?: ReferrerPolicy;
134
+ /** A boolean to support gzip/deflate content encoding. (only NodeFetch) */
135
+ compress?: boolean | undefined;
136
+ /** A maximum redirect count. (only NodeFetch) */
137
+ follow?: number | undefined;
63
138
  } & RequestTransformIncoming<IncomingApi, Incoming> & RequestTransformOutcoming<Outcoming, OutcomingApi>;
64
139
  type RequestTransformOutcoming<Outcoming, OutcomingApi> = IsEqual<OutcomingApi, Outcoming> extends true ? {
65
140
  transformOutcomingData?: never;
@@ -71,176 +146,156 @@ type RequestTransformIncoming<IncomingApi, Incoming> = IsEqual<Incoming, Incomin
71
146
  } : {
72
147
  transformIncomingData: (data: IncomingApi) => Incoming;
73
148
  };
74
- type Middleware = <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<unknown>;
75
- type PostMiddleware = (response: Response | Response$1 | undefined) => Promise<unknown>;
76
- type PostMiddlewareType = ValueOf<typeof POST_API_MIDDLEWARES>;
77
- type ActivePostMiddleware = PostMiddlewareType[];
78
- type LoggerPostMiddlewareOptions = {
79
- filter?: (response: Response | Response$1 | undefined) => boolean;
80
- filterStatus?: (status: number) => boolean;
81
- filterUrl?: (url: string) => boolean;
82
- filterHeaders?: (headers: Headers | Headers$1) => boolean;
83
- };
84
- type PostMiddlewareOptions = {
85
- logger?: LoggerPostMiddlewareOptions;
86
- };
87
- type MiddlewareType = ValueOf<typeof API_MIDDLEWARES>;
88
- type ActiveMiddleware = MiddlewareType[];
89
- type LoggerMiddlewareOptions = {
90
- filter?: (request: RequestInterface<unknown, unknown, unknown, unknown>) => boolean;
91
- filterPath?: (path: string) => boolean;
92
- filterMethod?: (method: RequestMethod) => boolean;
93
- filterParams?: (params?: ParamsType) => boolean;
94
- filterHeaders?: (headers?: Record<string, string | undefined>) => boolean;
95
- };
96
- type MiddlewaresOptions = {
97
- oauth?: OauthMiddleWareOptions;
98
- logger?: LoggerMiddlewareOptions;
99
- };
100
- type AuthUserUpdateRequestOptions<User extends Record<string, unknown>> = AuthUserRequestOptions & {
101
- userRequest?: () => Promise<User | null | undefined>;
102
- oauthUrl: () => string;
103
- errorUrl: string;
104
- };
105
- type AuthUserRequestOptions = {
106
- authUserUrl: string;
107
- };
108
- type OauthMiddleWareOptions = {
149
+ type BeforeHandler = <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<unknown>;
150
+ type AfterHandler = <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>, response: Response | Response$1 | undefined) => Promise<unknown>;
151
+ type OauthOptions = {
152
+ /** A name of expires token in localstorage */
109
153
  expiresTokenStorageName: string;
154
+ /** A name of flag in query for oauth flow window */
110
155
  onlyRefreshTokenWindowQueryName: string;
156
+ /** An url of start oauth flow window */
111
157
  refreshTokenWindowUrl?: (() => string) | string;
158
+ /** An error handle that call if oauth flow window wasn't open */
112
159
  onWindowOpenError?: () => void;
160
+ /** A name of token in localstorage */
113
161
  tokenStorageName?: string;
162
+ /** An url for refresh token */
114
163
  tokenRequest?: () => Promise<string | null | undefined>;
164
+ /** A number of millisecond for waiting oauth flow window before force close it */
115
165
  wait?: number;
166
+ /** An interval for check closable property by oauth flow window in ms */
116
167
  closeObserveInterval?: number;
117
168
  };
118
169
  type GetOauthTokenOptions = {
170
+ /** An url of start oauth flow */
119
171
  oauthUrl: (() => string) | string;
172
+ /** A name of expires token in localstorage */
120
173
  expiresTokenStorageName: string;
174
+ /** A name of expires token in query */
121
175
  expiresTokenQueryName: string;
176
+ /** A name of flag in query for oauth flow window */
122
177
  onlyRefreshTokenWindowQueryName: string;
123
178
  };
124
179
  type GetOauthTokenFromOtherWindowOptions = {
180
+ /** An url of start oauth flow window */
125
181
  refreshTokenWindowUrl?: (() => string) | string;
182
+ /** A name of flag in query for oauth flow window */
126
183
  onlyRefreshTokenWindowQueryName: string;
184
+ /** A name of expires token in localstorage */
127
185
  expiresTokenStorageName: string;
186
+ /** An error handle that call if oauth flow window wasn't open */
128
187
  onWindowOpenError?: () => void;
188
+ /** A number of millisecond for waiting oauth flow window before force close it */
129
189
  wait?: number;
190
+ /** An interval for check closable property by oauth flow window in ms */
130
191
  closeObserveInterval?: number;
131
192
  };
132
193
 
133
- type DateType = ValueOf<typeof DATE_TYPES>;
134
- type DateGetterRule = {
135
- increment: number;
136
- type: DateType;
194
+ type CreateRequestClientInstance = {
195
+ client: ((url: URL | RequestInfo, init?: RequestInit) => Promise<Response$1>) | typeof fetch;
196
+ oauthOptions?: OauthOptions;
197
+ beforeHandlers?: BeforeHandler[];
198
+ afterHandlers?: AfterHandler[];
199
+ retries?: number[];
200
+ timeout?: number;
201
+ };
202
+ type RequestInstance = {
203
+ <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>): Promise<Incoming>;
204
+ recreate: (options: CreateRequestClientInstance) => void;
205
+ };
206
+ declare function createFetchClient(options: CreateRequestClientInstance): {
207
+ requestWithArrayResponse: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<[ResponseError, RequestError, Response | Response$1 | null] | [Incoming, null, Response | Response$1 | null]>;
208
+ requestWithObjectResponse: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<{
209
+ data: ResponseError;
210
+ error: RequestError;
211
+ response: Response | Response$1 | null;
212
+ } | {
213
+ data: Incoming;
214
+ error: null;
215
+ response: Response | Response$1 | null;
216
+ }>;
217
+ recreate: (options: CreateRequestClientInstance) => void;
137
218
  };
138
- type DayJS = Dayjs;
139
219
 
140
- type FieldType = ValueOf<typeof FIELD_TYPES>;
220
+ declare function getOauthTokenFromOtherWindow(options: GetOauthTokenFromOtherWindowOptions): Promise<void>;
221
+ declare function refetchAfterOauth<T>(options: OauthOptions, refetch: () => Promise<T>): Promise<T>;
222
+ declare function getOauthToken(options: GetOauthTokenOptions): string | null;
141
223
 
142
- type ColorFormat = ValueOf<typeof COLOR_FORMATS>;
224
+ type LoggerAfterHandlerOptions = {
225
+ filter?: (response: Response | Response$1 | undefined) => boolean;
226
+ filterStatus?: (status: number) => boolean;
227
+ filterUrl?: (url: string) => boolean;
228
+ filterHeaders?: (headers: Headers | Headers$1) => boolean;
229
+ };
230
+ declare function loggerAfterHandler(options?: LoggerAfterHandlerOptions): AfterHandler;
231
+
232
+ type LoggerBeforeHandlerOptions = {
233
+ filter?: (request: RequestInterface<unknown, unknown, unknown, unknown>) => boolean;
234
+ filterPath?: (path: string) => boolean;
235
+ filterMethod?: (method: RequestMethod) => boolean;
236
+ filterParams?: (params?: RequestQuery) => boolean;
237
+ filterHeaders?: (headers?: RequestHeader) => boolean;
238
+ };
239
+ declare function loggerBeforeHandler(options?: LoggerBeforeHandlerOptions): BeforeHandler;
240
+
241
+ declare const oauthBeforeHandler: (options: OauthOptions) => BeforeHandler;
143
242
 
144
243
  type ResponseErrorOptions = {
145
244
  message: string;
146
245
  status: number;
147
246
  code?: number;
148
247
  description?: unknown;
149
- headers?: Record<string, string>;
248
+ headers?: RequestHeader;
150
249
  };
151
250
  declare class ResponseError extends Error {
152
251
  status: number;
153
252
  code?: number;
154
253
  description?: unknown;
155
- headers?: Record<string, string>;
254
+ headers?: RequestHeader;
156
255
  constructor({ message, status, description, code, headers }: ResponseErrorOptions);
157
256
  }
158
- type CreateRequestClientInstance = {
159
- client: ((url: URL | RequestInfo, init?: RequestInit) => Promise<Response$1>) | typeof fetch;
160
- activeMiddlewares?: ActiveMiddleware;
161
- middlewareOptions?: MiddlewaresOptions;
162
- customMiddlewares?: Middleware[];
163
- activePostMiddlewares?: ActivePostMiddleware;
164
- postMiddlewaresOptions?: PostMiddlewareOptions;
165
- customPostMiddlewares?: PostMiddleware[];
166
- };
167
- type RequestInstance = {
168
- <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>): Promise<Incoming>;
169
- setOptions: (options: CreateRequestClientInstance) => void;
170
- };
171
- declare function createRequestClientInstance(options: CreateRequestClientInstance): {
172
- requestApi: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<Incoming>;
173
- requestApiWithMeta: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<{
174
- data: Incoming;
175
- status: number;
176
- headers: Record<string, string>;
177
- }>;
178
- setMiddlewares: ({ activeMiddlewares, middlewareOptions, customMiddlewares, activePostMiddlewares, postMiddlewaresOptions, customPostMiddlewares, }?: Omit<CreateRequestClientInstance, "client">) => void;
179
- };
180
-
181
- declare function getOauthTokenFromOtherWindow(options: GetOauthTokenFromOtherWindowOptions): Promise<void>;
182
- declare function getOauthToken(options: GetOauthTokenOptions): string | null;
183
-
184
- declare function updateAuthUser<User extends Record<string, unknown>>(options: AuthUserUpdateRequestOptions<User>): Promise<User | undefined>;
185
- declare function getAuthUser<User extends Record<string, unknown>>(options: AuthUserRequestOptions): Promise<User | null | undefined>;
186
-
187
- type DownloadFileOptions = {
188
- data: Blob;
189
- fileName: string;
190
- mimeType: string;
191
- };
192
- declare function downloadFile({ data, fileName, mimeType }: DownloadFileOptions): null;
193
-
194
- declare function downloadJson(data: unknown, name: string): null | undefined;
195
257
 
196
- declare function readFile(file: File): Promise<unknown>;
258
+ declare const IS_JEST: boolean;
259
+ declare const IS_BUN: boolean;
260
+ declare const IS_DENO: boolean;
261
+ declare const IS_NODE: boolean;
262
+ declare const IS_WEB_WORKER: boolean;
263
+ declare const IS_BROWSER: boolean;
197
264
 
198
- type PositionPlacements = "bottom-center" | "bottom-left" | "bottom-right" | "right-center" | "right-top" | "right-bottom" | "top-left" | "top-center" | "top-right" | "left-center" | "left-top" | "left-bottom" | "flex";
199
- type VisiblePosition = {
200
- top: number;
201
- left: number;
202
- right: number;
203
- bottom: number;
204
- placement: PositionPlacements;
265
+ declare const COLOR_FORMATS: {
266
+ readonly Hex: "HEX";
267
+ readonly Rgb: "RGB";
268
+ readonly Rgba: "RGBA";
269
+ readonly Hsl: "HSL";
205
270
  };
206
- type InitialPosition = {
207
- targetNode?: HTMLElement;
208
- position?: {
209
- x: number;
210
- y: number;
211
- width: number;
212
- height: number;
213
- };
271
+ declare const DATE_TYPES: {
272
+ readonly Days: "days";
273
+ readonly Months: "months";
274
+ readonly Years: "years";
275
+ readonly Seconds: "seconds";
276
+ readonly Minutes: "minutes";
277
+ readonly Hours: "hours";
214
278
  };
215
- type GetVisiblePositionOptions = {
216
- node: HTMLElement;
217
- initialPosition?: InitialPosition;
218
- visibleArea?: HTMLElement;
219
- placement?: Exclude<PositionPlacements, "flex">;
220
- stepX?: number;
221
- stepY?: number;
222
- flex?: boolean;
223
- nested?: boolean;
279
+ declare const FIELD_TYPES: {
280
+ readonly Date: "date";
281
+ readonly Time: "time";
282
+ readonly DateTime: "dateTime";
283
+ readonly String: "string";
284
+ readonly Number: "number";
285
+ readonly Array: "array";
224
286
  };
225
- declare function getVisiblePosition({ initialPosition, node, visibleArea, placement, stepX, stepY, flex, nested, }: GetVisiblePositionOptions): VisiblePosition;
226
287
 
227
- declare function getQueryValues<K extends string>(keys: K[]): Record<K, string | string[] | undefined> | null;
228
-
229
- declare function execAnimation(element: HTMLElement | null | undefined, className: string, autoCloseDelay?: number): Promise<unknown>;
230
-
231
- declare function copyToClipboard(textToCopy: string): Promise<boolean>;
232
-
233
- declare function extractQueries(): Record<string, string[] | undefined>;
234
-
235
- declare function getColorFormat(color: string): "HEX" | "RGB" | "RGBA" | "HSL" | undefined;
236
-
237
- declare function takeOpacityColors(color: string | undefined, opacities: number[]): string[];
238
-
239
- declare function transformHEXtoRGB(hex: string): string;
240
-
241
- declare function transformRGBtoRGBA(rgb: string, opacity: number): string;
242
-
243
- declare function transformRGBAtoRGB(rgba: string): string;
288
+ type Maybe<T> = T | undefined | null;
289
+ type ValueOf<T> = T extends {} ? T[keyof T] : unknown;
290
+ type IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
291
+ type ColorFormat = ValueOf<typeof COLOR_FORMATS>;
292
+ type DateType = ValueOf<typeof DATE_TYPES>;
293
+ type DateGetterRule = {
294
+ increment: number;
295
+ type: DateType;
296
+ };
297
+ type DayJS = Dayjs;
298
+ type FieldType = ValueOf<typeof FIELD_TYPES>;
244
299
 
245
300
  declare function transformToColor(currentColor: unknown, defaultColor?: string, defaultFormat?: ColorFormat): string;
246
301
 
@@ -289,15 +344,15 @@ declare function transformToNumber(value: unknown): number;
289
344
 
290
345
  type CreateURLOptionsInterface = {
291
346
  baseURL: string;
292
- params?: ParamsType;
347
+ params?: RequestQuery;
293
348
  };
294
- declare function createURLWithParams(options: CreateURLOptionsInterface): string;
349
+ declare function createURLWithQueries(options: CreateURLOptionsInterface): string;
295
350
 
296
351
  declare function trimUrl(url: string): string;
297
352
 
298
353
  declare function arrayToMapByKey<T extends Record<string, unknown>>(array: T[], key: keyof T): Record<string, T>;
299
354
 
300
- declare function buildQueryString(params: ParamsType): string;
355
+ declare function buildQueryString(params: RequestQuery): string;
301
356
 
302
357
  declare function syncObjectValues(oldObj: Record<string, unknown>, newObj: Record<string, unknown>, exception?: string[]): void;
303
358
 
@@ -398,5 +453,5 @@ declare function throttle<TArgs extends any[]>({ interval }: {
398
453
 
399
454
  declare function type(value: unknown): string;
400
455
 
401
- export { API_MIDDLEWARES, COLOR_FORMATS, DATE_TYPES, FIELD_TYPES, IS_BROWSER, IS_BUN, IS_DENO, IS_JEST, IS_NODE, IS_WEB_WORKER, POST_API_MIDDLEWARES, ResponseError, arrayToMapByKey, buildQueryString, checkType, cloneDeep, copyToClipboard, createGlobalId, createLocalIdGenerator, createRequestClientInstance, createURLWithParams, dateDifference, dateFormat, debounce, declination, difference, differenceBy, differenceWith, downloadFile, downloadJson, execAnimation, extractQueries, fieldViewFormat, getAuthUser, getByPath, getCallerFunctionName, getColorFormat, getDateByRules, getFileNameFromHeader, getOauthToken, getOauthTokenFromOtherWindow, getQueryValues, getRandomColor, getToday, getTomorrow, getVisiblePosition, getYesterday, isArray, isBoolean, isDate, isEqual, isId, isNull, isNullable, isNumber, isObject, isPrimitive, isString, isToday, isTomorrow, isUndefined, isYesterday, joinPaths, jsonParse, limitStreamOfRequests, randomNumber, randomString, readFile, setByPath, speedTest, startWith, syncObjectValues, takeOpacityColors, throttle, transformHEXtoRGB, transformRGBAtoRGB, transformRGBtoRGBA, transformToColor, transformToDayjs, transformToNumber, translit, trimUrl, type, updateAuthUser, wait, waitUntil };
402
- export type { ActiveMiddleware, ActivePostMiddleware, AuthUserRequestOptions, AuthUserUpdateRequestOptions, ColorFormat, DateGetterRule, DateType, DayJS, FieldType, GetOauthTokenFromOtherWindowOptions, GetOauthTokenOptions, IsEqual, LoggerMiddlewareOptions, LoggerPostMiddlewareOptions, Maybe, Middleware, MiddlewareType, MiddlewaresOptions, OauthMiddleWareOptions, ParamValueType, ParamsType, PositionPlacements, PostMiddleware, PostMiddlewareOptions, PostMiddlewareType, RequestInstance, RequestInterface, RequestMethod, RequestTransformIncoming, RequestTransformOutcoming, ValueOf, VisiblePosition };
456
+ export { COLOR_FORMATS, DATE_TYPES, FIELD_TYPES, IS_BROWSER, IS_BUN, IS_DENO, IS_JEST, IS_NODE, IS_WEB_WORKER, OAUTH_STATE, REQUEST_ERROR, RESPONSE_DATA_SYMBOL, ResponseError, arrayToMapByKey, buildQueryString, checkType, cloneDeep, copyToClipboard, createFetchClient, createGlobalId, createLocalIdGenerator, createURLWithQueries, dateDifference, dateFormat, debounce, declination, difference, differenceBy, differenceWith, downloadFile, downloadJson, execAnimation, extractQueries, fieldViewFormat, getByPath, getCallerFunctionName, getColorFormat, getDateByRules, getFileNameFromHeader, getOauthToken, getOauthTokenFromOtherWindow, getQueryValues, getRandomColor, getToday, getTomorrow, getVisiblePosition, getYesterday, isArray, isBoolean, isDate, isEqual, isId, isNull, isNullable, isNumber, isObject, isPrimitive, isString, isToday, isTomorrow, isUndefined, isYesterday, joinPaths, jsonParse, limitStreamOfRequests, loggerAfterHandler, loggerBeforeHandler, oauthBeforeHandler, randomNumber, randomString, readFile, refetchAfterOauth, setByPath, speedTest, startWith, syncObjectValues, takeOpacityColors, throttle, transformHEXtoRGB, transformRGBAtoRGB, transformRGBtoRGBA, transformToColor, transformToDayjs, transformToNumber, translit, trimUrl, type, wait, waitUntil };
457
+ export type { AfterHandler, BeforeHandler, ColorFormat, DateGetterRule, DateType, DayJS, FieldType, GetOauthTokenFromOtherWindowOptions, GetOauthTokenOptions, IsEqual, LoggerAfterHandlerOptions, LoggerBeforeHandlerOptions, Maybe, OauthOptions, PositionPlacements, RequestError, RequestHeader, RequestInstance, RequestInterface, RequestMethod, RequestQuery, RequestQueryValue, RequestTransformIncoming, RequestTransformOutcoming, ValueOf, VisiblePosition };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krainovsd/js-helpers",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "description": "Krainov helpers",
5
5
  "type": "module",
6
6
  "author": "KrainovSD <denislosev48@gmail.com>",
@@ -29,6 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "publish-package": "npm run lint && npm run build && npm publish",
32
+ "dev": "vite --host --force",
32
33
  "clear": "rm -rf ./lib",
33
34
  "build-dev": "npm run clear && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --no-stdin --environment BUILD:development,NODE_ENV:development",
34
35
  "build": "npm run clear && npm run build:types && npm run build:js",
@@ -63,6 +64,7 @@
63
64
  "jest": "29.7.0",
64
65
  "node-fetch": "2.7.0",
65
66
  "@types/node-fetch": "2.6.12",
66
- "ts-jest": "29.2.5"
67
+ "ts-jest": "29.2.5",
68
+ "vite": "6.2.1"
67
69
  }
68
70
  }
@@ -1,10 +0,0 @@
1
- const API_MIDDLEWARES = {
2
- Oauth: "oauth",
3
- Logger: "logger",
4
- };
5
- const POST_API_MIDDLEWARES = {
6
- Logger: "logger",
7
- };
8
-
9
- export { API_MIDDLEWARES, POST_API_MIDDLEWARES };
10
- //# sourceMappingURL=api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sources":["../../../src/constants/api.ts"],"sourcesContent":["export const API_MIDDLEWARES = {\n Oauth: \"oauth\",\n Logger: \"logger\",\n} as const;\n\nexport const POST_API_MIDDLEWARES = {\n Logger: \"logger\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,eAAe,GAAG;AAC7B,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,MAAM,EAAE,QAAQ;;AAGL,MAAA,oBAAoB,GAAG;AAClC,IAAA,MAAM,EAAE,QAAQ;;;;;"}
@@ -1,9 +0,0 @@
1
- const COLOR_FORMATS = {
2
- Hex: "HEX",
3
- Rgb: "RGB",
4
- Rgba: "RGBA",
5
- Hsl: "HSL",
6
- };
7
-
8
- export { COLOR_FORMATS };
9
- //# sourceMappingURL=colors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"colors.js","sources":["../../../src/constants/colors.ts"],"sourcesContent":["export const COLOR_FORMATS = {\n Hex: \"HEX\",\n Rgb: \"RGB\",\n Rgba: \"RGBA\",\n Hsl: \"HSL\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,aAAa,GAAG;AAC3B,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,GAAG,EAAE,KAAK;;;;;"}
@@ -1,11 +0,0 @@
1
- const DATE_TYPES = {
2
- Days: "days",
3
- Months: "months",
4
- Years: "years",
5
- Seconds: "seconds",
6
- Minutes: "minutes",
7
- Hours: "hours",
8
- };
9
-
10
- export { DATE_TYPES };
11
- //# sourceMappingURL=date.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"date.js","sources":["../../../src/constants/date.ts"],"sourcesContent":["export const DATE_TYPES = {\n Days: \"days\",\n Months: \"months\",\n Years: \"years\",\n Seconds: \"seconds\",\n Minutes: \"minutes\",\n Hours: \"hours\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,KAAK,EAAE,OAAO;;;;;"}
@@ -1,11 +0,0 @@
1
- const FIELD_TYPES = {
2
- Date: "date",
3
- Time: "time",
4
- DateTime: "dateTime",
5
- String: "string",
6
- Number: "number",
7
- Array: "array",
8
- };
9
-
10
- export { FIELD_TYPES };
11
- //# sourceMappingURL=fields.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fields.js","sources":["../../../src/constants/fields.ts"],"sourcesContent":["export const FIELD_TYPES = {\n Date: \"date\",\n Time: \"time\",\n DateTime: \"dateTime\",\n String: \"string\",\n Number: \"number\",\n Array: \"array\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,WAAW,GAAG;AACzB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;;;;;"}
@@ -1,4 +0,0 @@
1
- const RESPONSE_DATA_SYMBOL = Symbol("response data");
2
-
3
- export { RESPONSE_DATA_SYMBOL };
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/lib/api/constants.ts"],"sourcesContent":["export const RESPONSE_DATA_SYMBOL = Symbol(\"response data\");\n"],"names":[],"mappings":"MAAa,oBAAoB,GAAG,MAAM,CAAC,eAAe;;;;"}