@krainovsd/js-helpers 0.2.2
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/README.md +23 -0
- package/lib/cjs/index.cjs +2914 -0
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/esm/index.js +2909 -0
- package/lib/esm/index.js.map +1 -0
- package/package.json +79 -0
- package/tmp/constants/api.d.ts +4 -0
- package/tmp/constants/colors.d.ts +6 -0
- package/tmp/constants/date.d.ts +8 -0
- package/tmp/constants/environment.d.ts +6 -0
- package/tmp/constants/fields.d.ts +8 -0
- package/tmp/constants/index.d.ts +5 -0
- package/tmp/index.d.ts +4 -0
- package/tmp/lib/api/core.d.ts +19 -0
- package/tmp/lib/api/index.d.ts +1 -0
- package/tmp/lib/api/middlewares/auth-middleware.d.ts +2 -0
- package/tmp/lib/api/middlewares/console-middleware.d.ts +2 -0
- package/tmp/lib/api/middlewares/index.d.ts +2 -0
- package/tmp/lib/api/token-request.d.ts +2 -0
- package/tmp/lib/browser/download-file.d.ts +7 -0
- package/tmp/lib/browser/download-json.d.ts +1 -0
- package/tmp/lib/browser/index.d.ts +3 -0
- package/tmp/lib/browser/read-file.d.ts +1 -0
- package/tmp/lib/colors/get-color-format.d.ts +1 -0
- package/tmp/lib/colors/index.d.ts +6 -0
- package/tmp/lib/colors/take-opacity-colors.d.ts +1 -0
- package/tmp/lib/colors/transform-hex-to-rgb.d.ts +1 -0
- package/tmp/lib/colors/transform-rgb-to-rgba.d.ts +1 -0
- package/tmp/lib/colors/transform-rgba-to-rgb.d.ts +1 -0
- package/tmp/lib/colors/transform-to-color.d.ts +2 -0
- package/tmp/lib/date/date-difference.d.ts +2 -0
- package/tmp/lib/date/date-format.d.ts +1 -0
- package/tmp/lib/date/get-date-by-rules.d.ts +2 -0
- package/tmp/lib/date/get-today.d.ts +4 -0
- package/tmp/lib/date/get-tomorrow.d.ts +1 -0
- package/tmp/lib/date/get-yesterday.d.ts +1 -0
- package/tmp/lib/date/index.d.ts +9 -0
- package/tmp/lib/date/is-today.d.ts +2 -0
- package/tmp/lib/date/is-tomorrow.d.ts +2 -0
- package/tmp/lib/date/is-yesterday.d.ts +2 -0
- package/tmp/lib/index.d.ts +5 -0
- package/tmp/lib/typings/check-type.d.ts +1 -0
- package/tmp/lib/typings/index.d.ts +11 -0
- package/tmp/lib/typings/is-array.d.ts +1 -0
- package/tmp/lib/typings/is-boolean.d.ts +1 -0
- package/tmp/lib/typings/is-date.d.ts +1 -0
- package/tmp/lib/typings/is-id.d.ts +1 -0
- package/tmp/lib/typings/is-null.d.ts +1 -0
- package/tmp/lib/typings/is-nullable.d.ts +1 -0
- package/tmp/lib/typings/is-number.d.ts +1 -0
- package/tmp/lib/typings/is-object.d.ts +1 -0
- package/tmp/lib/typings/is-string.d.ts +1 -0
- package/tmp/lib/typings/is-undefined.d.ts +1 -0
- package/tmp/lib/utils/array-to-map-by-key.d.ts +1 -0
- package/tmp/lib/utils/build-query-string.d.ts +2 -0
- package/tmp/lib/utils/create-url-with-params.d.ts +7 -0
- package/tmp/lib/utils/field-view-format.d.ts +2 -0
- package/tmp/lib/utils/get-by-path.d.ts +1 -0
- package/tmp/lib/utils/get-file-name-from-header.d.ts +1 -0
- package/tmp/lib/utils/index.d.ts +16 -0
- package/tmp/lib/utils/json-parse.d.ts +1 -0
- package/tmp/lib/utils/limit-stream-of-requests.d.ts +14 -0
- package/tmp/lib/utils/random-number.d.ts +1 -0
- package/tmp/lib/utils/random-string.d.ts +1 -0
- package/tmp/lib/utils/set-by-path.d.ts +1 -0
- package/tmp/lib/utils/sync-object-values.d.ts +1 -0
- package/tmp/lib/utils/transform-to-number.d.ts +1 -0
- package/tmp/lib/utils/trim-url.d.ts +1 -0
- package/tmp/lib/utils/wait-until.d.ts +1 -0
- package/tmp/lib/utils/wait.d.ts +1 -0
- package/tmp/libs.d.ts +2 -0
- package/tmp/types/api.d.ts +33 -0
- package/tmp/types/colors.d.ts +3 -0
- package/tmp/types/common.d.ts +2 -0
- package/tmp/types/date.d.ts +7 -0
- package/tmp/types/fields.d.ts +3 -0
- package/tmp/types/index.d.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dateFormat(date: Date | string | number, format: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTomorrow(): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getYesterday(): Date;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./date-difference";
|
|
2
|
+
export * from "./get-date-by-rules";
|
|
3
|
+
export * from "./get-today";
|
|
4
|
+
export * from "./get-tomorrow";
|
|
5
|
+
export * from "./get-yesterday";
|
|
6
|
+
export * from "./is-today";
|
|
7
|
+
export * from "./is-tomorrow";
|
|
8
|
+
export * from "./is-yesterday";
|
|
9
|
+
export * from "./date-format";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkType<R>(value: unknown, condition: boolean): value is R;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./check-type";
|
|
2
|
+
export * from "./is-array";
|
|
3
|
+
export * from "./is-boolean";
|
|
4
|
+
export * from "./is-id";
|
|
5
|
+
export * from "./is-null";
|
|
6
|
+
export * from "./is-nullable";
|
|
7
|
+
export * from "./is-number";
|
|
8
|
+
export * from "./is-object";
|
|
9
|
+
export * from "./is-string";
|
|
10
|
+
export * from "./is-undefined";
|
|
11
|
+
export * from "./is-date";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDate(value: unknown): value is Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isId(value: unknown): value is number | string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNull(value: unknown): value is null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNullable(value: unknown): value is null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNumber(value: unknown): value is number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isString(value: unknown): value is string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isUndefined(value: unknown): value is undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function arrayToMapByKey<T extends Record<string, unknown>>(array: T[], key: keyof T): Record<string, T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getByPath<T>(data: unknown, path?: string, defaultValue?: unknown): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFileNameFromHeader(header: string): string | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./wait-until";
|
|
2
|
+
export * from "./get-by-path";
|
|
3
|
+
export * from "./field-view-format";
|
|
4
|
+
export * from "./set-by-path";
|
|
5
|
+
export * from "./json-parse";
|
|
6
|
+
export * from "./random-string";
|
|
7
|
+
export * from "./wait";
|
|
8
|
+
export * from "./transform-to-number";
|
|
9
|
+
export * from "./create-url-with-params";
|
|
10
|
+
export * from "./trim-url";
|
|
11
|
+
export * from "./array-to-map-by-key";
|
|
12
|
+
export * from "./build-query-string";
|
|
13
|
+
export * from "./sync-object-values";
|
|
14
|
+
export * from "./random-number";
|
|
15
|
+
export * from "./get-file-name-from-header";
|
|
16
|
+
export * from "./limit-stream-of-requests";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jsonParse<T>(json: unknown): T | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type LimitStreamOfRequestsOptions<T> = {
|
|
2
|
+
countRequests: number;
|
|
3
|
+
maxCountInParallel: number;
|
|
4
|
+
promiseGetter: (count: number) => Promise<T>;
|
|
5
|
+
refetchAfterError?: boolean;
|
|
6
|
+
maxTryCount?: number;
|
|
7
|
+
collectResult?: boolean;
|
|
8
|
+
resultCb?: (result: T) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function limitStreamOfRequests<T>({ countRequests, maxCountInParallel, promiseGetter, refetchAfterError, resultCb, collectResult, maxTryCount, }: LimitStreamOfRequestsOptions<T>): {
|
|
11
|
+
promise: Promise<T[]>;
|
|
12
|
+
cancel: () => void;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomNumber(min: number, max: number): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomString(length?: number, allowCharacters?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setByPath(data: Record<string, unknown> | unknown[], path: string, value: unknown): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function syncObjectValues(oldObj: Record<string, unknown>, newObj: Record<string, unknown>, exception?: string[]): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transformToNumber(value: unknown): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trimUrl(url: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const waitUntil: (condition: () => boolean, checkInterval?: number) => Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wait(delay: number): Promise<unknown>;
|
package/tmp/libs.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type API_MIDDLEWARES } from "../constants";
|
|
2
|
+
import type { ValueOf } from "./common";
|
|
3
|
+
export type ParamValueType = string | number | boolean;
|
|
4
|
+
export type ParamsType = Record<string, ParamValueType | ParamValueType[] | null | undefined>;
|
|
5
|
+
export interface RequestInterface<T, Incoming, Body, Outcoming> {
|
|
6
|
+
path: string;
|
|
7
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
8
|
+
body?: Body | Outcoming;
|
|
9
|
+
params?: ParamsType;
|
|
10
|
+
headers?: Record<string, string | undefined>;
|
|
11
|
+
delay?: number;
|
|
12
|
+
transformOutcomingData?: (data: Body) => Outcoming;
|
|
13
|
+
transformIncomingData?: (data: Incoming) => T;
|
|
14
|
+
mock?: Incoming;
|
|
15
|
+
downloadFile?: boolean;
|
|
16
|
+
token?: string;
|
|
17
|
+
withoutResponse?: boolean;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
export type Middleware = <T, Incoming, Body, Outcoming>(request: RequestInterface<T, Incoming, Body, Outcoming>) => Promise<unknown>;
|
|
21
|
+
export type MiddlewareType = ValueOf<typeof API_MIDDLEWARES>;
|
|
22
|
+
export type ActiveMiddleware = MiddlewareType[];
|
|
23
|
+
export type AuthMiddleWareOptions = {
|
|
24
|
+
authRedirectUrl: string;
|
|
25
|
+
authTokenUrl: string;
|
|
26
|
+
storageExpiresTokenName: string;
|
|
27
|
+
storageTokenName: string;
|
|
28
|
+
pathToToken: string;
|
|
29
|
+
pathToExpires: string;
|
|
30
|
+
};
|
|
31
|
+
export type MiddlewaresOptions = {
|
|
32
|
+
auth?: AuthMiddleWareOptions;
|
|
33
|
+
};
|