@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.
Files changed (77) hide show
  1. package/README.md +23 -0
  2. package/lib/cjs/index.cjs +2914 -0
  3. package/lib/cjs/index.cjs.map +1 -0
  4. package/lib/esm/index.js +2909 -0
  5. package/lib/esm/index.js.map +1 -0
  6. package/package.json +79 -0
  7. package/tmp/constants/api.d.ts +4 -0
  8. package/tmp/constants/colors.d.ts +6 -0
  9. package/tmp/constants/date.d.ts +8 -0
  10. package/tmp/constants/environment.d.ts +6 -0
  11. package/tmp/constants/fields.d.ts +8 -0
  12. package/tmp/constants/index.d.ts +5 -0
  13. package/tmp/index.d.ts +4 -0
  14. package/tmp/lib/api/core.d.ts +19 -0
  15. package/tmp/lib/api/index.d.ts +1 -0
  16. package/tmp/lib/api/middlewares/auth-middleware.d.ts +2 -0
  17. package/tmp/lib/api/middlewares/console-middleware.d.ts +2 -0
  18. package/tmp/lib/api/middlewares/index.d.ts +2 -0
  19. package/tmp/lib/api/token-request.d.ts +2 -0
  20. package/tmp/lib/browser/download-file.d.ts +7 -0
  21. package/tmp/lib/browser/download-json.d.ts +1 -0
  22. package/tmp/lib/browser/index.d.ts +3 -0
  23. package/tmp/lib/browser/read-file.d.ts +1 -0
  24. package/tmp/lib/colors/get-color-format.d.ts +1 -0
  25. package/tmp/lib/colors/index.d.ts +6 -0
  26. package/tmp/lib/colors/take-opacity-colors.d.ts +1 -0
  27. package/tmp/lib/colors/transform-hex-to-rgb.d.ts +1 -0
  28. package/tmp/lib/colors/transform-rgb-to-rgba.d.ts +1 -0
  29. package/tmp/lib/colors/transform-rgba-to-rgb.d.ts +1 -0
  30. package/tmp/lib/colors/transform-to-color.d.ts +2 -0
  31. package/tmp/lib/date/date-difference.d.ts +2 -0
  32. package/tmp/lib/date/date-format.d.ts +1 -0
  33. package/tmp/lib/date/get-date-by-rules.d.ts +2 -0
  34. package/tmp/lib/date/get-today.d.ts +4 -0
  35. package/tmp/lib/date/get-tomorrow.d.ts +1 -0
  36. package/tmp/lib/date/get-yesterday.d.ts +1 -0
  37. package/tmp/lib/date/index.d.ts +9 -0
  38. package/tmp/lib/date/is-today.d.ts +2 -0
  39. package/tmp/lib/date/is-tomorrow.d.ts +2 -0
  40. package/tmp/lib/date/is-yesterday.d.ts +2 -0
  41. package/tmp/lib/index.d.ts +5 -0
  42. package/tmp/lib/typings/check-type.d.ts +1 -0
  43. package/tmp/lib/typings/index.d.ts +11 -0
  44. package/tmp/lib/typings/is-array.d.ts +1 -0
  45. package/tmp/lib/typings/is-boolean.d.ts +1 -0
  46. package/tmp/lib/typings/is-date.d.ts +1 -0
  47. package/tmp/lib/typings/is-id.d.ts +1 -0
  48. package/tmp/lib/typings/is-null.d.ts +1 -0
  49. package/tmp/lib/typings/is-nullable.d.ts +1 -0
  50. package/tmp/lib/typings/is-number.d.ts +1 -0
  51. package/tmp/lib/typings/is-object.d.ts +1 -0
  52. package/tmp/lib/typings/is-string.d.ts +1 -0
  53. package/tmp/lib/typings/is-undefined.d.ts +1 -0
  54. package/tmp/lib/utils/array-to-map-by-key.d.ts +1 -0
  55. package/tmp/lib/utils/build-query-string.d.ts +2 -0
  56. package/tmp/lib/utils/create-url-with-params.d.ts +7 -0
  57. package/tmp/lib/utils/field-view-format.d.ts +2 -0
  58. package/tmp/lib/utils/get-by-path.d.ts +1 -0
  59. package/tmp/lib/utils/get-file-name-from-header.d.ts +1 -0
  60. package/tmp/lib/utils/index.d.ts +16 -0
  61. package/tmp/lib/utils/json-parse.d.ts +1 -0
  62. package/tmp/lib/utils/limit-stream-of-requests.d.ts +14 -0
  63. package/tmp/lib/utils/random-number.d.ts +1 -0
  64. package/tmp/lib/utils/random-string.d.ts +1 -0
  65. package/tmp/lib/utils/set-by-path.d.ts +1 -0
  66. package/tmp/lib/utils/sync-object-values.d.ts +1 -0
  67. package/tmp/lib/utils/transform-to-number.d.ts +1 -0
  68. package/tmp/lib/utils/trim-url.d.ts +1 -0
  69. package/tmp/lib/utils/wait-until.d.ts +1 -0
  70. package/tmp/lib/utils/wait.d.ts +1 -0
  71. package/tmp/libs.d.ts +2 -0
  72. package/tmp/types/api.d.ts +33 -0
  73. package/tmp/types/colors.d.ts +3 -0
  74. package/tmp/types/common.d.ts +2 -0
  75. package/tmp/types/date.d.ts +7 -0
  76. package/tmp/types/fields.d.ts +3 -0
  77. package/tmp/types/index.d.ts +5 -0
@@ -0,0 +1,2 @@
1
+ import type { ColorFormat } from "../../types";
2
+ export declare function transformToColor(currentColor: unknown, defaultColor?: string, defaultFormat?: ColorFormat): string;
@@ -0,0 +1,2 @@
1
+ import type { DateType } from "../../types";
2
+ export declare function dateDifference(type: DateType, firstDate: Date, secondDate?: Date, float?: boolean): number;
@@ -0,0 +1 @@
1
+ export declare function dateFormat(date: Date | string | number, format: string): string;
@@ -0,0 +1,2 @@
1
+ import { type DateGetterRule } from "../../types";
2
+ export declare function getDateByRules(rules: DateGetterRule[], date?: Date): Date;
@@ -0,0 +1,4 @@
1
+ export declare function getToday(): {
2
+ startToday: Date;
3
+ endToday: Date;
4
+ };
@@ -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,2 @@
1
+ import type { Maybe } from "../../types";
2
+ export declare function isToday(date: Maybe<string | Date | number>): boolean;
@@ -0,0 +1,2 @@
1
+ import type { Maybe } from "../../types";
2
+ export declare function isTomorrow(date: Maybe<string | Date | number>): boolean;
@@ -0,0 +1,2 @@
1
+ import { type Maybe } from "../../types";
2
+ export declare function isYesterday(date: Maybe<string | Date | number>): boolean;
@@ -0,0 +1,5 @@
1
+ export * as api from "./api";
2
+ export * as browser from "./browser";
3
+ export * as colors from "./colors";
4
+ export * as date from "./date";
5
+ export * as utils from "./utils";
@@ -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,2 @@
1
+ import type { ParamsType } from "../../types";
2
+ export declare function buildQueryString(params: ParamsType): string;
@@ -0,0 +1,7 @@
1
+ import type { ParamsType } from "../../types";
2
+ type CreateURLOptionsInterface = {
3
+ baseURL: string;
4
+ params?: ParamsType;
5
+ };
6
+ export declare function createURLWithParams(options: CreateURLOptionsInterface): string;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { FieldType } from "../../types";
2
+ export declare function fieldViewFormat(field: unknown, type?: FieldType): string;
@@ -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,2 @@
1
+ export * from "./lib";
2
+ export * as constants from "./constants";
@@ -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
+ };
@@ -0,0 +1,3 @@
1
+ import type { COLOR_FORMATS } from "../constants";
2
+ import type { ValueOf } from "./common";
3
+ export type ColorFormat = ValueOf<typeof COLOR_FORMATS>;
@@ -0,0 +1,2 @@
1
+ export type Maybe<T> = T | undefined | null;
2
+ export type ValueOf<T> = T extends {} ? T[keyof T] : unknown;
@@ -0,0 +1,7 @@
1
+ import { type DATE_TYPES } from "../constants";
2
+ import { type ValueOf } from "./common";
3
+ export type DateType = ValueOf<typeof DATE_TYPES>;
4
+ export type DateGetterRule = {
5
+ increment: number;
6
+ type: DateType;
7
+ };
@@ -0,0 +1,3 @@
1
+ import type { FIELD_TYPES } from "../constants";
2
+ import type { ValueOf } from "./common";
3
+ export type FieldType = ValueOf<typeof FIELD_TYPES>;
@@ -0,0 +1,5 @@
1
+ export * from "./api";
2
+ export * from "./common";
3
+ export * from "./date";
4
+ export * from "./fields";
5
+ export * from "./colors";