@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.
- package/lib/Components/SuspenseRoute.d.ts +7 -7
- package/lib/Components/SuspenseRoute.js +29 -29
- package/lib/Components/index.d.ts +1 -1
- package/lib/Components/index.js +1 -1
- package/lib/Hooks/index.d.ts +45 -45
- package/lib/Hooks/index.js +98 -98
- package/lib/Hooks/useInfiniteScroll.d.ts +7 -7
- package/lib/Hooks/useInfiniteScroll.js +22 -22
- package/lib/Hooks/useNetworkState.d.ts +67 -67
- package/lib/Hooks/useNetworkState.js +41 -41
- package/lib/Hooks/useShortcuts.d.ts +4 -4
- package/lib/Hooks/useShortcuts.js +91 -91
- package/lib/Utilities/ApiUtility.axios.d.ts +60 -60
- package/lib/Utilities/ApiUtility.axios.js +305 -305
- package/lib/Utilities/BrowserInfo.d.ts +74 -74
- package/lib/Utilities/BrowserInfo.js +153 -153
- package/lib/Utilities/Countries.d.ts +14 -14
- package/lib/Utilities/Countries.js +290 -290
- package/lib/Utilities/CustomEventEmitter.d.ts +12 -12
- package/lib/Utilities/CustomEventEmitter.js +30 -30
- package/lib/Utilities/FastCompare.d.ts +1 -1
- package/lib/Utilities/FastCompare.js +128 -128
- package/lib/Utilities/HideablePromise.d.ts +5 -5
- package/lib/Utilities/HideablePromise.js +10 -10
- package/lib/Utilities/LoadScripts.d.ts +9 -9
- package/lib/Utilities/LoadScripts.js +51 -51
- package/lib/Utilities/MTDFraudPrevention.d.ts +28 -28
- package/lib/Utilities/MTDFraudPrevention.js +157 -157
- package/lib/Utilities/Nationalities.d.ts +5 -5
- package/lib/Utilities/Nationalities.js +245 -245
- package/lib/Utilities/RouteUtils.d.ts +129 -120
- package/lib/Utilities/RouteUtils.js +223 -206
- package/lib/Utilities/TimeZones.d.ts +10 -10
- package/lib/Utilities/TimeZones.js +1069 -1069
- package/lib/Utilities/Types.d.ts +19 -19
- package/lib/Utilities/Types.js +1 -1
- package/lib/Utilities/Utils.d.ts +174 -174
- package/lib/Utilities/Utils.js +331 -331
- package/lib/Utilities/dayjs.d.ts +18 -18
- package/lib/Utilities/dayjs.js +56 -56
- package/lib/Utilities/index.d.ts +14 -14
- package/lib/Utilities/index.js +14 -14
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -3
- package/package.json +12 -25
package/lib/Utilities/Types.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export interface IId<TId = string> {
|
|
2
|
-
id: TId;
|
|
3
|
-
}
|
|
4
|
-
export interface IIdName<TId = string> extends IId<TId> {
|
|
5
|
-
name: string;
|
|
6
|
-
}
|
|
7
|
-
export interface IAddress {
|
|
8
|
-
building: string;
|
|
9
|
-
street: string;
|
|
10
|
-
city: string;
|
|
11
|
-
county: string;
|
|
12
|
-
postcode: string;
|
|
13
|
-
country: string;
|
|
14
|
-
}
|
|
15
|
-
export interface IRecordUpdateInfo {
|
|
16
|
-
userId: string;
|
|
17
|
-
userName: string;
|
|
18
|
-
date: Date;
|
|
19
|
-
}
|
|
1
|
+
export interface IId<TId = string> {
|
|
2
|
+
id: TId;
|
|
3
|
+
}
|
|
4
|
+
export interface IIdName<TId = string> extends IId<TId> {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IAddress {
|
|
8
|
+
building: string;
|
|
9
|
+
street: string;
|
|
10
|
+
city: string;
|
|
11
|
+
county: string;
|
|
12
|
+
postcode: string;
|
|
13
|
+
country: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IRecordUpdateInfo {
|
|
16
|
+
userId: string;
|
|
17
|
+
userName: string;
|
|
18
|
+
date: Date;
|
|
19
|
+
}
|
package/lib/Utilities/Types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/lib/Utilities/Utils.d.ts
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import { Dayjs } from 'dayjs';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { IAddress } from './Types';
|
|
4
|
-
export declare const StorageMessageKey = "ao-message";
|
|
5
|
-
export interface IStorageMessage extends Record<string, any> {
|
|
6
|
-
type: string;
|
|
7
|
-
t: string;
|
|
8
|
-
domain: string;
|
|
9
|
-
}
|
|
10
|
-
export interface IFormattedNumberOptions {
|
|
11
|
-
decimalPlaces?: number;
|
|
12
|
-
withComma?: boolean;
|
|
13
|
-
useDashForZero?: boolean;
|
|
14
|
-
}
|
|
15
|
-
declare class UtilsBase {
|
|
16
|
-
DateRegEx: RegExp;
|
|
17
|
-
NiNoRegEx: RegExp;
|
|
18
|
-
/**
|
|
19
|
-
* Unique id for the tab (openned browser tab)
|
|
20
|
-
*/
|
|
21
|
-
TabIdKey: string;
|
|
22
|
-
constructor();
|
|
23
|
-
/**
|
|
24
|
-
* Get number from any type/value
|
|
25
|
-
* @param num Value to get number
|
|
26
|
-
*/
|
|
27
|
-
getNumber: (num?: string | number) => number;
|
|
28
|
-
/**
|
|
29
|
-
* Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY
|
|
30
|
-
* @param date Date to be formatted
|
|
31
|
-
* @param emptyValue Value to return if date is empty or null
|
|
32
|
-
* @param withTime Return date with time
|
|
33
|
-
*/
|
|
34
|
-
getFormattedDate: (date: string | number | Date | Dayjs | undefined, emptyValue?: string, withTime?: boolean, timeZone?: string) => string | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* Get formatted number
|
|
37
|
-
* @param number Number to format
|
|
38
|
-
* @param decimalPlaces Number of decimal places
|
|
39
|
-
* @param withComma Get number with separator
|
|
40
|
-
* @param useDashForZero Use dash for zero
|
|
41
|
-
* @param withCurrency Prepend £ before number
|
|
42
|
-
*/
|
|
43
|
-
getFormattedNumber: (number: any, decimalPlaces?: number, withComma?: boolean, useDashForZero?: boolean, withCurrency?: boolean) => string;
|
|
44
|
-
/**
|
|
45
|
-
* Get formatted number
|
|
46
|
-
* @param number Number to format
|
|
47
|
-
* @param useDashForZero Use dash for zero
|
|
48
|
-
*/
|
|
49
|
-
getFormattedCurrency: (number: any, useDashForZero?: boolean) => string;
|
|
50
|
-
/**
|
|
51
|
-
* Append zero if number is less then 10
|
|
52
|
-
* @param num Number to check
|
|
53
|
-
*/
|
|
54
|
-
appendZero: (num: number) => string | number;
|
|
55
|
-
/**
|
|
56
|
-
* Get formatted time (MM:SS)
|
|
57
|
-
* @param seconds Seconds - to get time
|
|
58
|
-
* @param minutes Minutes - to get time
|
|
59
|
-
*/
|
|
60
|
-
getFormattedTime: (seconds: number, minutes?: number) => string;
|
|
61
|
-
/**
|
|
62
|
-
* Get formatted time from total seconds
|
|
63
|
-
* @param seconds Total seconds to calculate hours and minutes
|
|
64
|
-
* @param ignoreSeconds Skip seconds in output string
|
|
65
|
-
*/
|
|
66
|
-
getFormattedSeconds: (seconds: number, ignoreSeconds?: boolean) => string;
|
|
67
|
-
/**
|
|
68
|
-
* Get a property value from local storage
|
|
69
|
-
* @param {string} Key name to find the value
|
|
70
|
-
*/
|
|
71
|
-
getLocal: (key: string) => any;
|
|
72
|
-
/**
|
|
73
|
-
* Set a property with value to local storage
|
|
74
|
-
* @param {string} Key name to find the value
|
|
75
|
-
* @param {any} data Data/value to be stored
|
|
76
|
-
*/
|
|
77
|
-
setLocal: (key: string, data: any) => void;
|
|
78
|
-
/**
|
|
79
|
-
* Remove a property with value from local storage
|
|
80
|
-
* @param {string} Key name to find the value
|
|
81
|
-
*/
|
|
82
|
-
removeLocal: (key: string) => void;
|
|
83
|
-
/**
|
|
84
|
-
* Get a property value from session storage
|
|
85
|
-
* @param {string} Key name to find the value
|
|
86
|
-
*/
|
|
87
|
-
getSession: (key: string) => any;
|
|
88
|
-
/**
|
|
89
|
-
* Set a property with value to session storage
|
|
90
|
-
* @param {string} Key name to find the value
|
|
91
|
-
* @param {any} data Data/value to be stored
|
|
92
|
-
*/
|
|
93
|
-
setSession: (key: string, data: any) => void;
|
|
94
|
-
jsonReplacer: (key: string, value: any) => any;
|
|
95
|
-
/**
|
|
96
|
-
* Get file size in kb/mb/gb etc.
|
|
97
|
-
* @param {number} size File lenth/size
|
|
98
|
-
*/
|
|
99
|
-
getFileSize: (size: number) => string;
|
|
100
|
-
/**
|
|
101
|
-
* A custom hook that builds on useLocation to parse the query string for you.
|
|
102
|
-
*/
|
|
103
|
-
useQuery: () => URLSearchParams;
|
|
104
|
-
/**
|
|
105
|
-
* Sum number array
|
|
106
|
-
* @param {number[]} arr Number array
|
|
107
|
-
*/
|
|
108
|
-
sumArray: (arr: number[]) => number;
|
|
109
|
-
/**
|
|
110
|
-
* Get sorted array by property
|
|
111
|
-
* @param {any[]} arr Array of objects
|
|
112
|
-
* @param {string} key Property/field name to sort
|
|
113
|
-
* @returns {any[]}
|
|
114
|
-
*/
|
|
115
|
-
sortArray<T = any>(arr: T[], key: keyof T): T[];
|
|
116
|
-
/**
|
|
117
|
-
* Replace an item in array with index
|
|
118
|
-
* @param arr Array of objects
|
|
119
|
-
* @param index Index where to replace the item
|
|
120
|
-
* @param newValue New item to be replaced with
|
|
121
|
-
* @returns Array of objects
|
|
122
|
-
*/
|
|
123
|
-
replaceItemAtIndex<T = any>(arr: T[], index: number, newValue: T): T[];
|
|
124
|
-
/**
|
|
125
|
-
* Remove an item from array with index
|
|
126
|
-
* @param arr Array of objects
|
|
127
|
-
* @param index Index which item to be removed
|
|
128
|
-
* @returns Array of object
|
|
129
|
-
*/
|
|
130
|
-
removeItemAtIndex<T = any>(arr: T[], index: number): T[];
|
|
131
|
-
/**
|
|
132
|
-
* Capitalize the words of a string
|
|
133
|
-
* @param {string} value String or value to be capitalized
|
|
134
|
-
* @param {boolean} lower To lowercase other chars
|
|
135
|
-
*/
|
|
136
|
-
capitalize: (value: string | null | undefined, lower?: boolean) => string;
|
|
137
|
-
/**
|
|
138
|
-
* Validate current MongoDB ObjectId
|
|
139
|
-
* @param id Id to check for ObjectId
|
|
140
|
-
*/
|
|
141
|
-
isValidObjectId: (id?: string) => boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs
|
|
144
|
-
* @param {string} Key name to find the value
|
|
145
|
-
* @param {any} data Data/value to be stored
|
|
146
|
-
*/
|
|
147
|
-
sendMessageToAllTabs: (type: string, data?: any) => void;
|
|
148
|
-
/**
|
|
149
|
-
* Check and get new event message, from event object
|
|
150
|
-
* @param {StorageEvent} event Event object received in storage event listener
|
|
151
|
-
*/
|
|
152
|
-
getStorageMessage: (event: StorageEvent) => IStorageMessage | null;
|
|
153
|
-
/**
|
|
154
|
-
* Assign value to an object by key/path name
|
|
155
|
-
* @param obj Object to assign value to
|
|
156
|
-
* @param path key full path
|
|
157
|
-
* @param val value to be assigned
|
|
158
|
-
* @param separator Path separator
|
|
159
|
-
*/
|
|
160
|
-
setNestedKeyValue: (obj: any, path: string, val: any, separator?: string) => void;
|
|
161
|
-
/**
|
|
162
|
-
* Get comma separated address string
|
|
163
|
-
* @param address address object to be converted
|
|
164
|
-
*/
|
|
165
|
-
getAddressString: (address?: IAddress, emptyString?: string) => string;
|
|
166
|
-
/**
|
|
167
|
-
* Get new random UUID
|
|
168
|
-
* @returns {string}
|
|
169
|
-
*/
|
|
170
|
-
uuid: () => string;
|
|
171
|
-
}
|
|
172
|
-
export declare const Utils: UtilsBase;
|
|
173
|
-
export declare function useIsMountedRef(): React.MutableRefObject<boolean | null>;
|
|
174
|
-
export {};
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IAddress } from './Types';
|
|
4
|
+
export declare const StorageMessageKey = "ao-message";
|
|
5
|
+
export interface IStorageMessage extends Record<string, any> {
|
|
6
|
+
type: string;
|
|
7
|
+
t: string;
|
|
8
|
+
domain: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IFormattedNumberOptions {
|
|
11
|
+
decimalPlaces?: number;
|
|
12
|
+
withComma?: boolean;
|
|
13
|
+
useDashForZero?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare class UtilsBase {
|
|
16
|
+
DateRegEx: RegExp;
|
|
17
|
+
NiNoRegEx: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Unique id for the tab (openned browser tab)
|
|
20
|
+
*/
|
|
21
|
+
TabIdKey: string;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Get number from any type/value
|
|
25
|
+
* @param num Value to get number
|
|
26
|
+
*/
|
|
27
|
+
getNumber: (num?: string | number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* Get formatted date in DD/MM/YYYY hh:mm A or DD/MM/YYYY
|
|
30
|
+
* @param date Date to be formatted
|
|
31
|
+
* @param emptyValue Value to return if date is empty or null
|
|
32
|
+
* @param withTime Return date with time
|
|
33
|
+
*/
|
|
34
|
+
getFormattedDate: (date: string | number | Date | Dayjs | undefined, emptyValue?: string, withTime?: boolean, timeZone?: string) => string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get formatted number
|
|
37
|
+
* @param number Number to format
|
|
38
|
+
* @param decimalPlaces Number of decimal places
|
|
39
|
+
* @param withComma Get number with separator
|
|
40
|
+
* @param useDashForZero Use dash for zero
|
|
41
|
+
* @param withCurrency Prepend £ before number
|
|
42
|
+
*/
|
|
43
|
+
getFormattedNumber: (number: any, decimalPlaces?: number, withComma?: boolean, useDashForZero?: boolean, withCurrency?: boolean) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Get formatted number
|
|
46
|
+
* @param number Number to format
|
|
47
|
+
* @param useDashForZero Use dash for zero
|
|
48
|
+
*/
|
|
49
|
+
getFormattedCurrency: (number: any, useDashForZero?: boolean) => string;
|
|
50
|
+
/**
|
|
51
|
+
* Append zero if number is less then 10
|
|
52
|
+
* @param num Number to check
|
|
53
|
+
*/
|
|
54
|
+
appendZero: (num: number) => string | number;
|
|
55
|
+
/**
|
|
56
|
+
* Get formatted time (MM:SS)
|
|
57
|
+
* @param seconds Seconds - to get time
|
|
58
|
+
* @param minutes Minutes - to get time
|
|
59
|
+
*/
|
|
60
|
+
getFormattedTime: (seconds: number, minutes?: number) => string;
|
|
61
|
+
/**
|
|
62
|
+
* Get formatted time from total seconds
|
|
63
|
+
* @param seconds Total seconds to calculate hours and minutes
|
|
64
|
+
* @param ignoreSeconds Skip seconds in output string
|
|
65
|
+
*/
|
|
66
|
+
getFormattedSeconds: (seconds: number, ignoreSeconds?: boolean) => string;
|
|
67
|
+
/**
|
|
68
|
+
* Get a property value from local storage
|
|
69
|
+
* @param {string} Key name to find the value
|
|
70
|
+
*/
|
|
71
|
+
getLocal: (key: string) => any;
|
|
72
|
+
/**
|
|
73
|
+
* Set a property with value to local storage
|
|
74
|
+
* @param {string} Key name to find the value
|
|
75
|
+
* @param {any} data Data/value to be stored
|
|
76
|
+
*/
|
|
77
|
+
setLocal: (key: string, data: any) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Remove a property with value from local storage
|
|
80
|
+
* @param {string} Key name to find the value
|
|
81
|
+
*/
|
|
82
|
+
removeLocal: (key: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Get a property value from session storage
|
|
85
|
+
* @param {string} Key name to find the value
|
|
86
|
+
*/
|
|
87
|
+
getSession: (key: string) => any;
|
|
88
|
+
/**
|
|
89
|
+
* Set a property with value to session storage
|
|
90
|
+
* @param {string} Key name to find the value
|
|
91
|
+
* @param {any} data Data/value to be stored
|
|
92
|
+
*/
|
|
93
|
+
setSession: (key: string, data: any) => void;
|
|
94
|
+
jsonReplacer: (key: string, value: any) => any;
|
|
95
|
+
/**
|
|
96
|
+
* Get file size in kb/mb/gb etc.
|
|
97
|
+
* @param {number} size File lenth/size
|
|
98
|
+
*/
|
|
99
|
+
getFileSize: (size: number) => string;
|
|
100
|
+
/**
|
|
101
|
+
* A custom hook that builds on useLocation to parse the query string for you.
|
|
102
|
+
*/
|
|
103
|
+
useQuery: () => URLSearchParams;
|
|
104
|
+
/**
|
|
105
|
+
* Sum number array
|
|
106
|
+
* @param {number[]} arr Number array
|
|
107
|
+
*/
|
|
108
|
+
sumArray: (arr: number[]) => number;
|
|
109
|
+
/**
|
|
110
|
+
* Get sorted array by property
|
|
111
|
+
* @param {any[]} arr Array of objects
|
|
112
|
+
* @param {string} key Property/field name to sort
|
|
113
|
+
* @returns {any[]}
|
|
114
|
+
*/
|
|
115
|
+
sortArray<T = any>(arr: T[], key: keyof T): T[];
|
|
116
|
+
/**
|
|
117
|
+
* Replace an item in array with index
|
|
118
|
+
* @param arr Array of objects
|
|
119
|
+
* @param index Index where to replace the item
|
|
120
|
+
* @param newValue New item to be replaced with
|
|
121
|
+
* @returns Array of objects
|
|
122
|
+
*/
|
|
123
|
+
replaceItemAtIndex<T = any>(arr: T[], index: number, newValue: T): T[];
|
|
124
|
+
/**
|
|
125
|
+
* Remove an item from array with index
|
|
126
|
+
* @param arr Array of objects
|
|
127
|
+
* @param index Index which item to be removed
|
|
128
|
+
* @returns Array of object
|
|
129
|
+
*/
|
|
130
|
+
removeItemAtIndex<T = any>(arr: T[], index: number): T[];
|
|
131
|
+
/**
|
|
132
|
+
* Capitalize the words of a string
|
|
133
|
+
* @param {string} value String or value to be capitalized
|
|
134
|
+
* @param {boolean} lower To lowercase other chars
|
|
135
|
+
*/
|
|
136
|
+
capitalize: (value: string | null | undefined, lower?: boolean) => string;
|
|
137
|
+
/**
|
|
138
|
+
* Validate current MongoDB ObjectId
|
|
139
|
+
* @param id Id to check for ObjectId
|
|
140
|
+
*/
|
|
141
|
+
isValidObjectId: (id?: string) => boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Set a property with value to local storage and then remove imidiatly, it is usefull to send message to all opened tabs
|
|
144
|
+
* @param {string} Key name to find the value
|
|
145
|
+
* @param {any} data Data/value to be stored
|
|
146
|
+
*/
|
|
147
|
+
sendMessageToAllTabs: (type: string, data?: any) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Check and get new event message, from event object
|
|
150
|
+
* @param {StorageEvent} event Event object received in storage event listener
|
|
151
|
+
*/
|
|
152
|
+
getStorageMessage: (event: StorageEvent) => IStorageMessage | null;
|
|
153
|
+
/**
|
|
154
|
+
* Assign value to an object by key/path name
|
|
155
|
+
* @param obj Object to assign value to
|
|
156
|
+
* @param path key full path
|
|
157
|
+
* @param val value to be assigned
|
|
158
|
+
* @param separator Path separator
|
|
159
|
+
*/
|
|
160
|
+
setNestedKeyValue: (obj: any, path: string, val: any, separator?: string) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Get comma separated address string
|
|
163
|
+
* @param address address object to be converted
|
|
164
|
+
*/
|
|
165
|
+
getAddressString: (address?: IAddress, emptyString?: string) => string;
|
|
166
|
+
/**
|
|
167
|
+
* Get new random UUID
|
|
168
|
+
* @returns {string}
|
|
169
|
+
*/
|
|
170
|
+
uuid: () => string;
|
|
171
|
+
}
|
|
172
|
+
export declare const Utils: UtilsBase;
|
|
173
|
+
export declare function useIsMountedRef(): React.MutableRefObject<boolean | null>;
|
|
174
|
+
export {};
|