@capsitech/react-utilities 0.1.4 → 0.1.6
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
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
declare const deviceIpData: {
|
|
2
|
-
deviceIpString: string;
|
|
3
|
-
deviceIpTimeStamp: string;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* This reset function is valuable only for unit testing
|
|
7
|
-
*/
|
|
8
|
-
export declare const resetDeviceIpString: () => void;
|
|
9
|
-
export declare const resetDeviceIpTimeStamp: () => void;
|
|
10
|
-
/**
|
|
11
|
-
* Function that returns the local IP address as a string as an async promise.
|
|
12
|
-
* It uses RTCPeerConnection object's onicecandidate event handler which gets called
|
|
13
|
-
* automatically when a new Ice Candidate is available.
|
|
14
|
-
* @returns {Promise} Promise to get users devices IP address
|
|
15
|
-
*/
|
|
16
|
-
export declare const getDeviceLocalIPAsString: () => Promise<typeof deviceIpData>;
|
|
17
|
-
/**
|
|
18
|
-
* Function that returns user's browser's all plugin as a comma separated string
|
|
19
|
-
* @returns {string} comma separated user's browser's plugins
|
|
20
|
-
*/
|
|
21
|
-
export declare const getBrowserPluginsAsString: () => string;
|
|
22
|
-
/**
|
|
23
|
-
* Function that returns user's timezone offset relative to UTC
|
|
24
|
-
* @returns {string} UTC concatenated with user's browser's timezone offset
|
|
25
|
-
*/
|
|
26
|
-
export declare const getTimezone: () => string;
|
|
27
|
-
/**
|
|
28
|
-
* Function that validates the user's screen's width value, and then returns it.
|
|
29
|
-
* If it fails validation, it returns null
|
|
30
|
-
* @returns {number | null} validated value of screen width
|
|
31
|
-
*/
|
|
32
|
-
export declare const getScreenWidth: () => number | null;
|
|
33
|
-
/**
|
|
34
|
-
* Function that validates the user's screen's height value, and then returns it.
|
|
35
|
-
* If it fails validation, it returns null
|
|
36
|
-
* @returns {number | null} validated value of screen height
|
|
37
|
-
*/
|
|
38
|
-
export declare const getScreenHeight: () => number | null;
|
|
39
|
-
/**
|
|
40
|
-
* Function that validates the user's device's pixel ratio, and then returns it.
|
|
41
|
-
* If it fails validation, it returns null
|
|
42
|
-
* @returns {number | null} validated value of window's devicePixelRatio
|
|
43
|
-
*/
|
|
44
|
-
export declare const getScreenScalingFactor: () => number | null;
|
|
45
|
-
/**
|
|
46
|
-
* Function that validates the user's screen's colorDepth, and then returns it.
|
|
47
|
-
* If it fails validation, it returns null
|
|
48
|
-
* @returns {number | null} validated value of screen's colorDepth
|
|
49
|
-
*/
|
|
50
|
-
export declare const getScreenColourDepth: () => number | null;
|
|
51
|
-
/**
|
|
52
|
-
* Function that validates the user's window's interior width in pixels, and then returns it.
|
|
53
|
-
* If it fails validation, it returns null
|
|
54
|
-
* @returns {number | null} validated value of window's innerWidth
|
|
55
|
-
*/
|
|
56
|
-
export declare const getWindowWidth: () => number | null;
|
|
57
|
-
/**
|
|
58
|
-
* Function that validates the user's window's interior height in pixels, and then returns it.
|
|
59
|
-
* If it fails validation, it returns null
|
|
60
|
-
* @returns {number | null} validated value of window's innerHeight
|
|
61
|
-
*/
|
|
62
|
-
export declare const getWindowHeight: () => number | null;
|
|
63
|
-
/**
|
|
64
|
-
* The function returns users browser's do not track setting by checking the navigator
|
|
65
|
-
* and window object for the same
|
|
66
|
-
* @returns {string} true or false based on users Do Not Track setting
|
|
67
|
-
*/
|
|
68
|
-
export declare const getBrowserDoNotTrackStatus: () => string;
|
|
69
|
-
/**
|
|
70
|
-
* This function returns user agent by checking the navigator
|
|
71
|
-
* @returns {String} user agent for the current browser
|
|
72
|
-
*/
|
|
73
|
-
export declare const getUserAgent: () => string;
|
|
74
|
-
export {};
|
|
1
|
+
declare const deviceIpData: {
|
|
2
|
+
deviceIpString: string;
|
|
3
|
+
deviceIpTimeStamp: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* This reset function is valuable only for unit testing
|
|
7
|
+
*/
|
|
8
|
+
export declare const resetDeviceIpString: () => void;
|
|
9
|
+
export declare const resetDeviceIpTimeStamp: () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Function that returns the local IP address as a string as an async promise.
|
|
12
|
+
* It uses RTCPeerConnection object's onicecandidate event handler which gets called
|
|
13
|
+
* automatically when a new Ice Candidate is available.
|
|
14
|
+
* @returns {Promise} Promise to get users devices IP address
|
|
15
|
+
*/
|
|
16
|
+
export declare const getDeviceLocalIPAsString: () => Promise<typeof deviceIpData>;
|
|
17
|
+
/**
|
|
18
|
+
* Function that returns user's browser's all plugin as a comma separated string
|
|
19
|
+
* @returns {string} comma separated user's browser's plugins
|
|
20
|
+
*/
|
|
21
|
+
export declare const getBrowserPluginsAsString: () => string;
|
|
22
|
+
/**
|
|
23
|
+
* Function that returns user's timezone offset relative to UTC
|
|
24
|
+
* @returns {string} UTC concatenated with user's browser's timezone offset
|
|
25
|
+
*/
|
|
26
|
+
export declare const getTimezone: () => string;
|
|
27
|
+
/**
|
|
28
|
+
* Function that validates the user's screen's width value, and then returns it.
|
|
29
|
+
* If it fails validation, it returns null
|
|
30
|
+
* @returns {number | null} validated value of screen width
|
|
31
|
+
*/
|
|
32
|
+
export declare const getScreenWidth: () => number | null;
|
|
33
|
+
/**
|
|
34
|
+
* Function that validates the user's screen's height value, and then returns it.
|
|
35
|
+
* If it fails validation, it returns null
|
|
36
|
+
* @returns {number | null} validated value of screen height
|
|
37
|
+
*/
|
|
38
|
+
export declare const getScreenHeight: () => number | null;
|
|
39
|
+
/**
|
|
40
|
+
* Function that validates the user's device's pixel ratio, and then returns it.
|
|
41
|
+
* If it fails validation, it returns null
|
|
42
|
+
* @returns {number | null} validated value of window's devicePixelRatio
|
|
43
|
+
*/
|
|
44
|
+
export declare const getScreenScalingFactor: () => number | null;
|
|
45
|
+
/**
|
|
46
|
+
* Function that validates the user's screen's colorDepth, and then returns it.
|
|
47
|
+
* If it fails validation, it returns null
|
|
48
|
+
* @returns {number | null} validated value of screen's colorDepth
|
|
49
|
+
*/
|
|
50
|
+
export declare const getScreenColourDepth: () => number | null;
|
|
51
|
+
/**
|
|
52
|
+
* Function that validates the user's window's interior width in pixels, and then returns it.
|
|
53
|
+
* If it fails validation, it returns null
|
|
54
|
+
* @returns {number | null} validated value of window's innerWidth
|
|
55
|
+
*/
|
|
56
|
+
export declare const getWindowWidth: () => number | null;
|
|
57
|
+
/**
|
|
58
|
+
* Function that validates the user's window's interior height in pixels, and then returns it.
|
|
59
|
+
* If it fails validation, it returns null
|
|
60
|
+
* @returns {number | null} validated value of window's innerHeight
|
|
61
|
+
*/
|
|
62
|
+
export declare const getWindowHeight: () => number | null;
|
|
63
|
+
/**
|
|
64
|
+
* The function returns users browser's do not track setting by checking the navigator
|
|
65
|
+
* and window object for the same
|
|
66
|
+
* @returns {string} true or false based on users Do Not Track setting
|
|
67
|
+
*/
|
|
68
|
+
export declare const getBrowserDoNotTrackStatus: () => string;
|
|
69
|
+
/**
|
|
70
|
+
* This function returns user agent by checking the navigator
|
|
71
|
+
* @returns {String} user agent for the current browser
|
|
72
|
+
*/
|
|
73
|
+
export declare const getUserAgent: () => string;
|
|
74
|
+
export {};
|
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
const ICE_CANDIDATE_IP_INDEX = 4;
|
|
2
|
-
// store deviceIpString as a global variable as generating it is expensive and often required several times
|
|
3
|
-
const deviceIpData = {
|
|
4
|
-
deviceIpString: '',
|
|
5
|
-
deviceIpTimeStamp: '',
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* This reset function is valuable only for unit testing
|
|
9
|
-
*/
|
|
10
|
-
export const resetDeviceIpString = () => {
|
|
11
|
-
deviceIpData.deviceIpString = '';
|
|
12
|
-
};
|
|
13
|
-
export const resetDeviceIpTimeStamp = () => {
|
|
14
|
-
deviceIpData.deviceIpTimeStamp = '';
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Function that returns the local IP address as a string as an async promise.
|
|
18
|
-
* It uses RTCPeerConnection object's onicecandidate event handler which gets called
|
|
19
|
-
* automatically when a new Ice Candidate is available.
|
|
20
|
-
* @returns {Promise} Promise to get users devices IP address
|
|
21
|
-
*/
|
|
22
|
-
export const getDeviceLocalIPAsString = () => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
if (deviceIpData.deviceIpString !== '' && deviceIpData.deviceIpTimeStamp !== '') {
|
|
25
|
-
resolve(deviceIpData);
|
|
26
|
-
}
|
|
27
|
-
const WebRTCConnection = RTCPeerConnection;
|
|
28
|
-
if (!WebRTCConnection) {
|
|
29
|
-
reject({ message: 'WEBRTC_UNSUPPORTED_BROWSER', error: undefined });
|
|
30
|
-
}
|
|
31
|
-
//RTCPeerConection is supported, so will try to find the IP
|
|
32
|
-
const ip = [];
|
|
33
|
-
let pc;
|
|
34
|
-
try {
|
|
35
|
-
pc = new WebRTCConnection();
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
reject({ message: 'WEBRTC_CONSTRUCTION_FAILED', error: err });
|
|
39
|
-
}
|
|
40
|
-
pc.onicecandidate = (event) => {
|
|
41
|
-
if (!event || !event.candidate) {
|
|
42
|
-
pc.close();
|
|
43
|
-
if (ip.length < 1) {
|
|
44
|
-
reject({ message: 'NO_IP_FOUND', error: undefined });
|
|
45
|
-
}
|
|
46
|
-
deviceIpData.deviceIpString = ip.join(',');
|
|
47
|
-
deviceIpData.deviceIpTimeStamp = new Date().toISOString();
|
|
48
|
-
resolve(deviceIpData);
|
|
49
|
-
}
|
|
50
|
-
else if (event.candidate.candidate) {
|
|
51
|
-
const candidateValues = event.candidate.candidate.split(' ');
|
|
52
|
-
if (candidateValues.length > ICE_CANDIDATE_IP_INDEX) {
|
|
53
|
-
ip.push(candidateValues[ICE_CANDIDATE_IP_INDEX]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
pc.createDataChannel('');
|
|
58
|
-
pc
|
|
59
|
-
.createOffer()
|
|
60
|
-
.then(pc.setLocalDescription.bind(pc))
|
|
61
|
-
.catch((err) => {
|
|
62
|
-
reject({ message: 'CREATE_CONNECTION_ERROR', error: err });
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Function that returns user's browser's all plugin as a comma separated string
|
|
68
|
-
* @returns {string} comma separated user's browser's plugins
|
|
69
|
-
*/
|
|
70
|
-
export const getBrowserPluginsAsString = () => {
|
|
71
|
-
return Array.from(navigator.plugins, (plugin) => plugin && plugin.name)
|
|
72
|
-
.filter((name) => name)
|
|
73
|
-
.join(',');
|
|
74
|
-
};
|
|
75
|
-
const getFormattedOffset = () => {
|
|
76
|
-
// Date().toString() is in format like "Wed Sep 30 2020 23:11:02 GMT+0100 (British Summer Time)"
|
|
77
|
-
// To format the offset, we split on "GMT"
|
|
78
|
-
// and then pick the relevant characters based on their position and reformat with a ":"
|
|
79
|
-
const offset = new Date().toString().split('GMT')[1];
|
|
80
|
-
const hourOffset = `${offset[0]}${offset[1]}${offset[2]}`;
|
|
81
|
-
const minuteOffset = `${offset[3]}${offset[4]}`;
|
|
82
|
-
const formattedUTC = `${hourOffset}:${minuteOffset}`;
|
|
83
|
-
return formattedUTC;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Function that returns user's timezone offset relative to UTC
|
|
87
|
-
* @returns {string} UTC concatenated with user's browser's timezone offset
|
|
88
|
-
*/
|
|
89
|
-
export const getTimezone = () => `UTC${getFormattedOffset()}`;
|
|
90
|
-
const validateAndGetScreenDetail = (value) => {
|
|
91
|
-
if (isNaN(value)) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Function that validates the user's screen's width value, and then returns it.
|
|
100
|
-
* If it fails validation, it returns null
|
|
101
|
-
* @returns {number | null} validated value of screen width
|
|
102
|
-
*/
|
|
103
|
-
export const getScreenWidth = () => validateAndGetScreenDetail(screen.width);
|
|
104
|
-
/**
|
|
105
|
-
* Function that validates the user's screen's height value, and then returns it.
|
|
106
|
-
* If it fails validation, it returns null
|
|
107
|
-
* @returns {number | null} validated value of screen height
|
|
108
|
-
*/
|
|
109
|
-
export const getScreenHeight = () => validateAndGetScreenDetail(screen.height);
|
|
110
|
-
/**
|
|
111
|
-
* Function that validates the user's device's pixel ratio, and then returns it.
|
|
112
|
-
* If it fails validation, it returns null
|
|
113
|
-
* @returns {number | null} validated value of window's devicePixelRatio
|
|
114
|
-
*/
|
|
115
|
-
export const getScreenScalingFactor = () => validateAndGetScreenDetail(window.devicePixelRatio);
|
|
116
|
-
/**
|
|
117
|
-
* Function that validates the user's screen's colorDepth, and then returns it.
|
|
118
|
-
* If it fails validation, it returns null
|
|
119
|
-
* @returns {number | null} validated value of screen's colorDepth
|
|
120
|
-
*/
|
|
121
|
-
export const getScreenColourDepth = () => validateAndGetScreenDetail(screen.colorDepth);
|
|
122
|
-
/**
|
|
123
|
-
* Function that validates the user's window's interior width in pixels, and then returns it.
|
|
124
|
-
* If it fails validation, it returns null
|
|
125
|
-
* @returns {number | null} validated value of window's innerWidth
|
|
126
|
-
*/
|
|
127
|
-
export const getWindowWidth = () => validateAndGetScreenDetail(window.innerWidth);
|
|
128
|
-
/**
|
|
129
|
-
* Function that validates the user's window's interior height in pixels, and then returns it.
|
|
130
|
-
* If it fails validation, it returns null
|
|
131
|
-
* @returns {number | null} validated value of window's innerHeight
|
|
132
|
-
*/
|
|
133
|
-
export const getWindowHeight = () => validateAndGetScreenDetail(window.innerHeight);
|
|
134
|
-
/**
|
|
135
|
-
* The function returns users browser's do not track setting by checking the navigator
|
|
136
|
-
* and window object for the same
|
|
137
|
-
* @returns {string} true or false based on users Do Not Track setting
|
|
138
|
-
*/
|
|
139
|
-
export const getBrowserDoNotTrackStatus = () => {
|
|
140
|
-
const windowVar = window, navigatorVar = navigator;
|
|
141
|
-
const isBrowserDoNotTrack = (windowVar.doNotTrack && windowVar.doNotTrack === '1') ||
|
|
142
|
-
(navigatorVar.doNotTrack && (navigatorVar.doNotTrack === 'yes' || navigatorVar.doNotTrack === '1')) ||
|
|
143
|
-
(navigatorVar.msDoNotTrack && navigatorVar.msDoNotTrack === '1') ||
|
|
144
|
-
(windowVar.external && windowVar.external.msTrackingProtectionEnabled && windowVar.external.msTrackingProtectionEnabled());
|
|
145
|
-
return isBrowserDoNotTrack ? 'true' : 'false';
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* This function returns user agent by checking the navigator
|
|
149
|
-
* @returns {String} user agent for the current browser
|
|
150
|
-
*/
|
|
151
|
-
export const getUserAgent = () => {
|
|
152
|
-
return navigator.userAgent;
|
|
153
|
-
};
|
|
1
|
+
const ICE_CANDIDATE_IP_INDEX = 4;
|
|
2
|
+
// store deviceIpString as a global variable as generating it is expensive and often required several times
|
|
3
|
+
const deviceIpData = {
|
|
4
|
+
deviceIpString: '',
|
|
5
|
+
deviceIpTimeStamp: '',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* This reset function is valuable only for unit testing
|
|
9
|
+
*/
|
|
10
|
+
export const resetDeviceIpString = () => {
|
|
11
|
+
deviceIpData.deviceIpString = '';
|
|
12
|
+
};
|
|
13
|
+
export const resetDeviceIpTimeStamp = () => {
|
|
14
|
+
deviceIpData.deviceIpTimeStamp = '';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Function that returns the local IP address as a string as an async promise.
|
|
18
|
+
* It uses RTCPeerConnection object's onicecandidate event handler which gets called
|
|
19
|
+
* automatically when a new Ice Candidate is available.
|
|
20
|
+
* @returns {Promise} Promise to get users devices IP address
|
|
21
|
+
*/
|
|
22
|
+
export const getDeviceLocalIPAsString = () => {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
if (deviceIpData.deviceIpString !== '' && deviceIpData.deviceIpTimeStamp !== '') {
|
|
25
|
+
resolve(deviceIpData);
|
|
26
|
+
}
|
|
27
|
+
const WebRTCConnection = RTCPeerConnection;
|
|
28
|
+
if (!WebRTCConnection) {
|
|
29
|
+
reject({ message: 'WEBRTC_UNSUPPORTED_BROWSER', error: undefined });
|
|
30
|
+
}
|
|
31
|
+
//RTCPeerConection is supported, so will try to find the IP
|
|
32
|
+
const ip = [];
|
|
33
|
+
let pc;
|
|
34
|
+
try {
|
|
35
|
+
pc = new WebRTCConnection();
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
reject({ message: 'WEBRTC_CONSTRUCTION_FAILED', error: err });
|
|
39
|
+
}
|
|
40
|
+
pc.onicecandidate = (event) => {
|
|
41
|
+
if (!event || !event.candidate) {
|
|
42
|
+
pc.close();
|
|
43
|
+
if (ip.length < 1) {
|
|
44
|
+
reject({ message: 'NO_IP_FOUND', error: undefined });
|
|
45
|
+
}
|
|
46
|
+
deviceIpData.deviceIpString = ip.join(',');
|
|
47
|
+
deviceIpData.deviceIpTimeStamp = new Date().toISOString();
|
|
48
|
+
resolve(deviceIpData);
|
|
49
|
+
}
|
|
50
|
+
else if (event.candidate.candidate) {
|
|
51
|
+
const candidateValues = event.candidate.candidate.split(' ');
|
|
52
|
+
if (candidateValues.length > ICE_CANDIDATE_IP_INDEX) {
|
|
53
|
+
ip.push(candidateValues[ICE_CANDIDATE_IP_INDEX]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
pc.createDataChannel('');
|
|
58
|
+
pc
|
|
59
|
+
.createOffer()
|
|
60
|
+
.then(pc.setLocalDescription.bind(pc))
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
reject({ message: 'CREATE_CONNECTION_ERROR', error: err });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Function that returns user's browser's all plugin as a comma separated string
|
|
68
|
+
* @returns {string} comma separated user's browser's plugins
|
|
69
|
+
*/
|
|
70
|
+
export const getBrowserPluginsAsString = () => {
|
|
71
|
+
return Array.from(navigator.plugins, (plugin) => plugin && plugin.name)
|
|
72
|
+
.filter((name) => name)
|
|
73
|
+
.join(',');
|
|
74
|
+
};
|
|
75
|
+
const getFormattedOffset = () => {
|
|
76
|
+
// Date().toString() is in format like "Wed Sep 30 2020 23:11:02 GMT+0100 (British Summer Time)"
|
|
77
|
+
// To format the offset, we split on "GMT"
|
|
78
|
+
// and then pick the relevant characters based on their position and reformat with a ":"
|
|
79
|
+
const offset = new Date().toString().split('GMT')[1];
|
|
80
|
+
const hourOffset = `${offset[0]}${offset[1]}${offset[2]}`;
|
|
81
|
+
const minuteOffset = `${offset[3]}${offset[4]}`;
|
|
82
|
+
const formattedUTC = `${hourOffset}:${minuteOffset}`;
|
|
83
|
+
return formattedUTC;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Function that returns user's timezone offset relative to UTC
|
|
87
|
+
* @returns {string} UTC concatenated with user's browser's timezone offset
|
|
88
|
+
*/
|
|
89
|
+
export const getTimezone = () => `UTC${getFormattedOffset()}`;
|
|
90
|
+
const validateAndGetScreenDetail = (value) => {
|
|
91
|
+
if (isNaN(value)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Function that validates the user's screen's width value, and then returns it.
|
|
100
|
+
* If it fails validation, it returns null
|
|
101
|
+
* @returns {number | null} validated value of screen width
|
|
102
|
+
*/
|
|
103
|
+
export const getScreenWidth = () => validateAndGetScreenDetail(screen.width);
|
|
104
|
+
/**
|
|
105
|
+
* Function that validates the user's screen's height value, and then returns it.
|
|
106
|
+
* If it fails validation, it returns null
|
|
107
|
+
* @returns {number | null} validated value of screen height
|
|
108
|
+
*/
|
|
109
|
+
export const getScreenHeight = () => validateAndGetScreenDetail(screen.height);
|
|
110
|
+
/**
|
|
111
|
+
* Function that validates the user's device's pixel ratio, and then returns it.
|
|
112
|
+
* If it fails validation, it returns null
|
|
113
|
+
* @returns {number | null} validated value of window's devicePixelRatio
|
|
114
|
+
*/
|
|
115
|
+
export const getScreenScalingFactor = () => validateAndGetScreenDetail(window.devicePixelRatio);
|
|
116
|
+
/**
|
|
117
|
+
* Function that validates the user's screen's colorDepth, and then returns it.
|
|
118
|
+
* If it fails validation, it returns null
|
|
119
|
+
* @returns {number | null} validated value of screen's colorDepth
|
|
120
|
+
*/
|
|
121
|
+
export const getScreenColourDepth = () => validateAndGetScreenDetail(screen.colorDepth);
|
|
122
|
+
/**
|
|
123
|
+
* Function that validates the user's window's interior width in pixels, and then returns it.
|
|
124
|
+
* If it fails validation, it returns null
|
|
125
|
+
* @returns {number | null} validated value of window's innerWidth
|
|
126
|
+
*/
|
|
127
|
+
export const getWindowWidth = () => validateAndGetScreenDetail(window.innerWidth);
|
|
128
|
+
/**
|
|
129
|
+
* Function that validates the user's window's interior height in pixels, and then returns it.
|
|
130
|
+
* If it fails validation, it returns null
|
|
131
|
+
* @returns {number | null} validated value of window's innerHeight
|
|
132
|
+
*/
|
|
133
|
+
export const getWindowHeight = () => validateAndGetScreenDetail(window.innerHeight);
|
|
134
|
+
/**
|
|
135
|
+
* The function returns users browser's do not track setting by checking the navigator
|
|
136
|
+
* and window object for the same
|
|
137
|
+
* @returns {string} true or false based on users Do Not Track setting
|
|
138
|
+
*/
|
|
139
|
+
export const getBrowserDoNotTrackStatus = () => {
|
|
140
|
+
const windowVar = window, navigatorVar = navigator;
|
|
141
|
+
const isBrowserDoNotTrack = (windowVar.doNotTrack && windowVar.doNotTrack === '1') ||
|
|
142
|
+
(navigatorVar.doNotTrack && (navigatorVar.doNotTrack === 'yes' || navigatorVar.doNotTrack === '1')) ||
|
|
143
|
+
(navigatorVar.msDoNotTrack && navigatorVar.msDoNotTrack === '1') ||
|
|
144
|
+
(windowVar.external && windowVar.external.msTrackingProtectionEnabled && windowVar.external.msTrackingProtectionEnabled());
|
|
145
|
+
return isBrowserDoNotTrack ? 'true' : 'false';
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* This function returns user agent by checking the navigator
|
|
149
|
+
* @returns {String} user agent for the current browser
|
|
150
|
+
*/
|
|
151
|
+
export const getUserAgent = () => {
|
|
152
|
+
return navigator.userAgent;
|
|
153
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export interface ICountry {
|
|
2
|
-
name: string;
|
|
3
|
-
dialCode: string;
|
|
4
|
-
code: string;
|
|
5
|
-
code3: string;
|
|
6
|
-
priority: number;
|
|
7
|
-
}
|
|
8
|
-
export declare const AllCountries: ICountry[];
|
|
9
|
-
export declare function getCountries(sortBy?: keyof ICountry): ICountry[];
|
|
10
|
-
export declare function getCountryOptions(): {
|
|
11
|
-
key: string;
|
|
12
|
-
text: string;
|
|
13
|
-
}[];
|
|
14
|
-
export declare function getCountryByPhoneNumber(phoneNumber: string): ICountry | undefined;
|
|
1
|
+
export interface ICountry {
|
|
2
|
+
name: string;
|
|
3
|
+
dialCode: string;
|
|
4
|
+
code: string;
|
|
5
|
+
code3: string;
|
|
6
|
+
priority: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const AllCountries: ICountry[];
|
|
9
|
+
export declare function getCountries(sortBy?: keyof ICountry): ICountry[];
|
|
10
|
+
export declare function getCountryOptions(): {
|
|
11
|
+
key: string;
|
|
12
|
+
text: string;
|
|
13
|
+
}[];
|
|
14
|
+
export declare function getCountryByPhoneNumber(phoneNumber: string): ICountry | undefined;
|