@capsitech/react-utilities 0.1.4 → 0.1.5

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 (45) hide show
  1. package/lib/Components/SuspenseRoute.d.ts +7 -7
  2. package/lib/Components/SuspenseRoute.js +29 -29
  3. package/lib/Components/index.d.ts +1 -1
  4. package/lib/Components/index.js +1 -1
  5. package/lib/Hooks/index.d.ts +45 -45
  6. package/lib/Hooks/index.js +98 -98
  7. package/lib/Hooks/useInfiniteScroll.d.ts +7 -7
  8. package/lib/Hooks/useInfiniteScroll.js +22 -22
  9. package/lib/Hooks/useNetworkState.d.ts +67 -67
  10. package/lib/Hooks/useNetworkState.js +41 -41
  11. package/lib/Hooks/useShortcuts.d.ts +4 -4
  12. package/lib/Hooks/useShortcuts.js +91 -91
  13. package/lib/Utilities/ApiUtility.axios.d.ts +60 -60
  14. package/lib/Utilities/ApiUtility.axios.js +305 -305
  15. package/lib/Utilities/BrowserInfo.d.ts +74 -74
  16. package/lib/Utilities/BrowserInfo.js +153 -153
  17. package/lib/Utilities/Countries.d.ts +14 -14
  18. package/lib/Utilities/Countries.js +290 -290
  19. package/lib/Utilities/CustomEventEmitter.d.ts +12 -12
  20. package/lib/Utilities/CustomEventEmitter.js +30 -30
  21. package/lib/Utilities/FastCompare.d.ts +1 -1
  22. package/lib/Utilities/FastCompare.js +128 -128
  23. package/lib/Utilities/HideablePromise.d.ts +5 -5
  24. package/lib/Utilities/HideablePromise.js +10 -10
  25. package/lib/Utilities/LoadScripts.d.ts +9 -9
  26. package/lib/Utilities/LoadScripts.js +51 -51
  27. package/lib/Utilities/MTDFraudPrevention.d.ts +28 -28
  28. package/lib/Utilities/MTDFraudPrevention.js +157 -157
  29. package/lib/Utilities/Nationalities.d.ts +5 -5
  30. package/lib/Utilities/Nationalities.js +245 -245
  31. package/lib/Utilities/RouteUtils.d.ts +129 -120
  32. package/lib/Utilities/RouteUtils.js +223 -206
  33. package/lib/Utilities/TimeZones.d.ts +10 -10
  34. package/lib/Utilities/TimeZones.js +1069 -1069
  35. package/lib/Utilities/Types.d.ts +19 -19
  36. package/lib/Utilities/Types.js +1 -1
  37. package/lib/Utilities/Utils.d.ts +174 -174
  38. package/lib/Utilities/Utils.js +331 -331
  39. package/lib/Utilities/dayjs.d.ts +18 -18
  40. package/lib/Utilities/dayjs.js +56 -56
  41. package/lib/Utilities/index.d.ts +14 -14
  42. package/lib/Utilities/index.js +14 -14
  43. package/lib/index.d.ts +3 -3
  44. package/lib/index.js +3 -3
  45. package/package.json +12 -25
@@ -1,91 +1,91 @@
1
- import React from 'react';
2
- const blacklistedTargets = ['INPUT', 'TEXTAREA', 'SELECT'];
3
- const keysReducer = (state, action) => {
4
- switch (action.type) {
5
- case 'set-key-down':
6
- const keydownState = { ...state, [action.key]: true };
7
- return keydownState;
8
- case 'set-key-up':
9
- const keyUpState = { ...state, [action.key]: false };
10
- return keyUpState;
11
- case 'reset-keys':
12
- const resetState = { ...action.data };
13
- return resetState;
14
- default:
15
- return state;
16
- }
17
- };
18
- export const useShortcuts = (shortcutKeys, callback, options) => {
19
- if (!Array.isArray(shortcutKeys))
20
- throw new Error('The first parameter to `useShortcuts` must be an ordered array of `KeyboardEvent.key` strings.');
21
- if (!shortcutKeys.length)
22
- throw new Error('The first parameter to `useShortcuts` must contain atleast one `KeyboardEvent.key` string.');
23
- if (!callback || typeof callback !== 'function')
24
- throw new Error('The second parameter to `useShortcuts` must be a function that will be envoked when the keys are pressed.');
25
- const { overrideSystem } = options || {};
26
- const initalKeyMapping = shortcutKeys.reduce((currentKeys, key) => {
27
- currentKeys[key.toLowerCase()] = false;
28
- return currentKeys;
29
- }, {});
30
- const [keys, setKeys] = React.useReducer(keysReducer, initalKeyMapping);
31
- const keydownListener = React.useCallback((assignedKey) => (keydownEvent) => {
32
- const loweredKey = assignedKey.toLowerCase();
33
- if (keydownEvent.repeat)
34
- return;
35
- if (blacklistedTargets.includes(keydownEvent.target.tagName))
36
- return;
37
- if (loweredKey !== keydownEvent.key.toLowerCase())
38
- return;
39
- if (keys[loweredKey] === undefined)
40
- return;
41
- if (overrideSystem) {
42
- keydownEvent.preventDefault();
43
- disabledEventPropagation(keydownEvent);
44
- }
45
- setKeys({ type: 'set-key-down', key: loweredKey });
46
- return false;
47
- }, [keys, overrideSystem]);
48
- const keyupListener = React.useCallback((assignedKey) => (keyupEvent) => {
49
- const raisedKey = assignedKey.toLowerCase();
50
- if (blacklistedTargets.includes(keyupEvent.target.tagName))
51
- return;
52
- if (keyupEvent.key.toLowerCase() !== raisedKey)
53
- return;
54
- if (keys[raisedKey] === undefined)
55
- return;
56
- if (overrideSystem) {
57
- keyupEvent.preventDefault();
58
- disabledEventPropagation(keyupEvent);
59
- }
60
- setKeys({ type: 'set-key-up', key: raisedKey });
61
- return false;
62
- }, [keys, overrideSystem]);
63
- React.useEffect(() => {
64
- //console.log('keys', keys);
65
- if (!Object.values(keys).filter((value) => !value).length) {
66
- callback(keys);
67
- setKeys({ type: 'reset-keys', data: initalKeyMapping });
68
- }
69
- else {
70
- setKeys({ type: '' });
71
- }
72
- }, [callback, keys]);
73
- React.useEffect(() => {
74
- shortcutKeys.forEach((k) => window.addEventListener('keydown', keydownListener(k)));
75
- return () => shortcutKeys.forEach((k) => window.removeEventListener('keydown', keydownListener(k)));
76
- }, []);
77
- React.useEffect(() => {
78
- shortcutKeys.forEach((k) => window.addEventListener('keyup', keyupListener(k)));
79
- return () => shortcutKeys.forEach((k) => window.removeEventListener('keyup', keyupListener(k)));
80
- }, []);
81
- };
82
- export function disabledEventPropagation(e) {
83
- if (e) {
84
- if (e.stopPropagation) {
85
- e.stopPropagation();
86
- }
87
- else if (window.event) {
88
- window.event.cancelBubble = true;
89
- }
90
- }
91
- }
1
+ import React from 'react';
2
+ const blacklistedTargets = ['INPUT', 'TEXTAREA', 'SELECT'];
3
+ const keysReducer = (state, action) => {
4
+ switch (action.type) {
5
+ case 'set-key-down':
6
+ const keydownState = { ...state, [action.key]: true };
7
+ return keydownState;
8
+ case 'set-key-up':
9
+ const keyUpState = { ...state, [action.key]: false };
10
+ return keyUpState;
11
+ case 'reset-keys':
12
+ const resetState = { ...action.data };
13
+ return resetState;
14
+ default:
15
+ return state;
16
+ }
17
+ };
18
+ export const useShortcuts = (shortcutKeys, callback, options) => {
19
+ if (!Array.isArray(shortcutKeys))
20
+ throw new Error('The first parameter to `useShortcuts` must be an ordered array of `KeyboardEvent.key` strings.');
21
+ if (!shortcutKeys.length)
22
+ throw new Error('The first parameter to `useShortcuts` must contain atleast one `KeyboardEvent.key` string.');
23
+ if (!callback || typeof callback !== 'function')
24
+ throw new Error('The second parameter to `useShortcuts` must be a function that will be envoked when the keys are pressed.');
25
+ const { overrideSystem } = options || {};
26
+ const initalKeyMapping = shortcutKeys.reduce((currentKeys, key) => {
27
+ currentKeys[key.toLowerCase()] = false;
28
+ return currentKeys;
29
+ }, {});
30
+ const [keys, setKeys] = React.useReducer(keysReducer, initalKeyMapping);
31
+ const keydownListener = React.useCallback((assignedKey) => (keydownEvent) => {
32
+ const loweredKey = assignedKey.toLowerCase();
33
+ if (keydownEvent.repeat)
34
+ return;
35
+ if (blacklistedTargets.includes(keydownEvent.target.tagName))
36
+ return;
37
+ if (loweredKey !== keydownEvent.key.toLowerCase())
38
+ return;
39
+ if (keys[loweredKey] === undefined)
40
+ return;
41
+ if (overrideSystem) {
42
+ keydownEvent.preventDefault();
43
+ disabledEventPropagation(keydownEvent);
44
+ }
45
+ setKeys({ type: 'set-key-down', key: loweredKey });
46
+ return false;
47
+ }, [keys, overrideSystem]);
48
+ const keyupListener = React.useCallback((assignedKey) => (keyupEvent) => {
49
+ const raisedKey = assignedKey.toLowerCase();
50
+ if (blacklistedTargets.includes(keyupEvent.target.tagName))
51
+ return;
52
+ if (keyupEvent.key.toLowerCase() !== raisedKey)
53
+ return;
54
+ if (keys[raisedKey] === undefined)
55
+ return;
56
+ if (overrideSystem) {
57
+ keyupEvent.preventDefault();
58
+ disabledEventPropagation(keyupEvent);
59
+ }
60
+ setKeys({ type: 'set-key-up', key: raisedKey });
61
+ return false;
62
+ }, [keys, overrideSystem]);
63
+ React.useEffect(() => {
64
+ //console.log('keys', keys);
65
+ if (!Object.values(keys).filter((value) => !value).length) {
66
+ callback(keys);
67
+ setKeys({ type: 'reset-keys', data: initalKeyMapping });
68
+ }
69
+ else {
70
+ setKeys({ type: '' });
71
+ }
72
+ }, [callback, keys]);
73
+ React.useEffect(() => {
74
+ shortcutKeys.forEach((k) => window.addEventListener('keydown', keydownListener(k)));
75
+ return () => shortcutKeys.forEach((k) => window.removeEventListener('keydown', keydownListener(k)));
76
+ }, []);
77
+ React.useEffect(() => {
78
+ shortcutKeys.forEach((k) => window.addEventListener('keyup', keyupListener(k)));
79
+ return () => shortcutKeys.forEach((k) => window.removeEventListener('keyup', keyupListener(k)));
80
+ }, []);
81
+ };
82
+ export function disabledEventPropagation(e) {
83
+ if (e) {
84
+ if (e.stopPropagation) {
85
+ e.stopPropagation();
86
+ }
87
+ else if (window.event) {
88
+ window.event.cancelBubble = true;
89
+ }
90
+ }
91
+ }
@@ -1,60 +1,60 @@
1
- import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- export interface IApiResponse<T = any> {
3
- status: boolean;
4
- result: T;
5
- message?: string;
6
- errors?: {
7
- number: number;
8
- message: string;
9
- suggestion: string;
10
- exception: any;
11
- }[];
12
- }
13
- export interface IApiListResult<T = any> {
14
- totalRecords: number;
15
- items: T[];
16
- moreRecords?: boolean;
17
- continuationToken?: string;
18
- }
19
- export interface IApiListResultWithTotal<TItem = any, TTotal = any> extends IApiListResult<TItem> {
20
- total: TTotal;
21
- }
22
- export declare enum HttpMethods {
23
- get = "get",
24
- post = "post"
25
- }
26
- export declare enum FileDownloadStatus {
27
- downloading = "downloading",
28
- done = "done",
29
- error = "error"
30
- }
31
- export type DownloadCallback = (status: FileDownloadStatus, error?: any) => void;
32
- export interface IAxiosRequestConfigWithoutParams extends Omit<AxiosRequestConfig, 'params' | 'paramsSerializer'> {
33
- contentType?: string;
34
- }
35
- declare class ApiUtilityBase {
36
- accessToken?: string;
37
- handleError: (error: string, errors?: any) => void;
38
- getResponse: <T = any>(endpoint: string, params?: any, options?: IAxiosRequestConfigWithoutParams) => Promise<AxiosResponse<T, any>>;
39
- get: <T = IApiResponse<any>>(endpoint: string, params?: any, throwErrorOn401?: boolean, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
40
- getResult: <T = any>(endpoint: string, params?: any, throwErrorOn401?: boolean, options?: IAxiosRequestConfigWithoutParams) => Promise<T | null>;
41
- post: <T = IApiResponse<any>>(endpoint: string, body: any, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
42
- put: <T = IApiResponse<any>>(endpoint: string, body: any, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
43
- appendFormDataValues: (form: FormData, values: any, preFix?: string) => void;
44
- postForm: <T = IApiResponse<any>>(endpoint: string, params: any, options?: IAxiosRequestConfigWithoutParams) => Promise<IApiResponse<any> | T>;
45
- putForm: <T = IApiResponse<any>>(endpoint: string, params: any, options?: IAxiosRequestConfigWithoutParams) => Promise<IApiResponse<any> | T>;
46
- delete: <T = IApiResponse<any>>(endpoint: string, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
47
- private getFileName;
48
- downloadFile: (endpoint: string, params?: any, method?: HttpMethods, options?: IAxiosRequestConfigWithoutParams) => Promise<{
49
- status: FileDownloadStatus;
50
- error?: any;
51
- }>;
52
- getAuthHeader: (contentType?: string) => any;
53
- handleResponse: <T = IApiResponse<any>>(response: AxiosResponse<T, any>, throwErrorOn401?: boolean) => T;
54
- handleAxiosError: <T = IApiResponse<any>>(error: AxiosError, throwErrorOn401?: boolean) => T;
55
- handleErrorResponse: (message: any, errors?: any) => void;
56
- _axiosOptions: (options?: IAxiosRequestConfigWithoutParams) => AxiosRequestConfig;
57
- getBaseUrl: () => string | undefined;
58
- }
59
- export declare const ApiUtility: ApiUtilityBase;
60
- export {};
1
+ import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ export interface IApiResponse<T = any> {
3
+ status: boolean;
4
+ result: T;
5
+ message?: string;
6
+ errors?: {
7
+ number: number;
8
+ message: string;
9
+ suggestion: string;
10
+ exception: any;
11
+ }[];
12
+ }
13
+ export interface IApiListResult<T = any> {
14
+ totalRecords: number;
15
+ items: T[];
16
+ moreRecords?: boolean;
17
+ continuationToken?: string;
18
+ }
19
+ export interface IApiListResultWithTotal<TItem = any, TTotal = any> extends IApiListResult<TItem> {
20
+ total: TTotal;
21
+ }
22
+ export declare enum HttpMethods {
23
+ get = "get",
24
+ post = "post"
25
+ }
26
+ export declare enum FileDownloadStatus {
27
+ downloading = "downloading",
28
+ done = "done",
29
+ error = "error"
30
+ }
31
+ export type DownloadCallback = (status: FileDownloadStatus, error?: any) => void;
32
+ export interface IAxiosRequestConfigWithoutParams extends Omit<AxiosRequestConfig, 'params' | 'paramsSerializer'> {
33
+ contentType?: string;
34
+ }
35
+ declare class ApiUtilityBase {
36
+ accessToken?: string;
37
+ handleError: (error: string, errors?: any) => void;
38
+ getResponse: <T = any>(endpoint: string, params?: any, options?: IAxiosRequestConfigWithoutParams) => Promise<AxiosResponse<T, any>>;
39
+ get: <T = IApiResponse>(endpoint: string, params?: any, throwErrorOn401?: boolean, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
40
+ getResult: <T = any>(endpoint: string, params?: any, throwErrorOn401?: boolean, options?: IAxiosRequestConfigWithoutParams) => Promise<T | null>;
41
+ post: <T = IApiResponse>(endpoint: string, body: any, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
42
+ put: <T = IApiResponse>(endpoint: string, body: any, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
43
+ appendFormDataValues: (form: FormData, values: any, preFix?: string) => void;
44
+ postForm: <T = IApiResponse>(endpoint: string, params: any, options?: IAxiosRequestConfigWithoutParams) => Promise<IApiResponse<any> | T>;
45
+ putForm: <T = IApiResponse>(endpoint: string, params: any, options?: IAxiosRequestConfigWithoutParams) => Promise<IApiResponse<any> | T>;
46
+ delete: <T = IApiResponse>(endpoint: string, contentType?: string, options?: IAxiosRequestConfigWithoutParams) => Promise<T>;
47
+ private getFileName;
48
+ downloadFile: (endpoint: string, params?: any, method?: HttpMethods, options?: IAxiosRequestConfigWithoutParams) => Promise<{
49
+ status: FileDownloadStatus;
50
+ error?: any;
51
+ }>;
52
+ getAuthHeader: (contentType?: string) => any;
53
+ handleResponse: <T = IApiResponse>(response: AxiosResponse<T>, throwErrorOn401?: boolean) => T;
54
+ handleAxiosError: <T = IApiResponse>(error: AxiosError, throwErrorOn401?: boolean) => T;
55
+ handleErrorResponse: (message: any, errors?: any) => void;
56
+ _axiosOptions: (options?: IAxiosRequestConfigWithoutParams) => AxiosRequestConfig;
57
+ getBaseUrl: () => string | undefined;
58
+ }
59
+ export declare const ApiUtility: ApiUtilityBase;
60
+ export {};