@capsitech/react-utilities 0.1.6 → 0.1.7
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 +74 -0
- package/lib/Hooks/index.d.ts +1 -1
- package/lib/Hooks/useInfiniteScroll.d.ts +1 -1
- package/lib/Utilities/ApiUtility.axios.d.ts +16 -3
- package/lib/Utilities/RouteUtils.d.ts +1 -1
- package/lib/Utilities/Utils.d.ts +1 -1
- package/lib/Utilities/dayjs.d.ts +10 -11
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.js +3461 -3
- package/lib/index.js.map +1 -0
- package/lib/logo.png +0 -0
- package/package.json +17 -7
- package/lib/Components/SuspenseRoute.js +0 -29
- package/lib/Components/index.js +0 -1
- package/lib/Hooks/index.js +0 -98
- package/lib/Hooks/useInfiniteScroll.js +0 -22
- package/lib/Hooks/useNetworkState.js +0 -41
- package/lib/Hooks/useShortcuts.js +0 -91
- package/lib/Utilities/ApiUtility.axios.js +0 -305
- package/lib/Utilities/BrowserInfo.js +0 -153
- package/lib/Utilities/Countries.js +0 -290
- package/lib/Utilities/CustomEventEmitter.js +0 -30
- package/lib/Utilities/FastCompare.js +0 -128
- package/lib/Utilities/HideablePromise.js +0 -10
- package/lib/Utilities/LoadScripts.js +0 -51
- package/lib/Utilities/MTDFraudPrevention.js +0 -157
- package/lib/Utilities/Nationalities.js +0 -245
- package/lib/Utilities/RouteUtils.js +0 -223
- package/lib/Utilities/TimeZones.js +0 -1069
- package/lib/Utilities/Types.js +0 -1
- package/lib/Utilities/Utils.js +0 -331
- package/lib/Utilities/dayjs.js +0 -56
- package/lib/Utilities/index.js +0 -14
|
@@ -1,153 +0,0 @@
|
|
|
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,290 +0,0 @@
|
|
|
1
|
-
import startsWith from 'lodash/startsWith';
|
|
2
|
-
import { Utils } from './Utils';
|
|
3
|
-
export const AllCountries = [
|
|
4
|
-
{ name: 'Afghanistan', dialCode: '93', code: 'AF', code3: 'AFG', priority: 0 },
|
|
5
|
-
{ name: 'Albania', dialCode: '355', code: 'AL', code3: 'ALB', priority: 0 },
|
|
6
|
-
{ name: 'Algeria', dialCode: '213', code: 'DZ', code3: 'DZA', priority: 0 },
|
|
7
|
-
{ name: 'American Samoa', dialCode: '1684', code: 'AS', code3: 'ASM', priority: 0 },
|
|
8
|
-
{ name: 'Andorra', dialCode: '376', code: 'AD', code3: 'AND', priority: 0 },
|
|
9
|
-
{ name: 'Angola', dialCode: '244', code: 'AO', code3: 'AGO', priority: 0 },
|
|
10
|
-
{ name: 'Anguilla', dialCode: '1264', code: 'AI', code3: 'AIA', priority: 0 },
|
|
11
|
-
{ name: 'Antarctica', dialCode: '672', code: 'AQ', code3: 'ATA', priority: 0 },
|
|
12
|
-
{ name: 'Antigua and Barbuda', dialCode: '1268', code: 'AG', code3: 'ATG', priority: 0 },
|
|
13
|
-
{ name: 'Argentina', dialCode: '54', code: 'AR', code3: 'ARG', priority: 0 },
|
|
14
|
-
{ name: 'Armenia', dialCode: '374', code: 'AM', code3: 'ARM', priority: 0 },
|
|
15
|
-
{ name: 'Aruba', dialCode: '297', code: 'AW', code3: 'ABW', priority: 0 },
|
|
16
|
-
{ name: 'Australia', dialCode: '61', code: 'AU', code3: 'AUS', priority: 0 },
|
|
17
|
-
{ name: 'Austria', dialCode: '43', code: 'AT', code3: 'AUT', priority: 0 },
|
|
18
|
-
{ name: 'Azerbaijan', dialCode: '994', code: 'AZ', code3: 'AZE', priority: 0 },
|
|
19
|
-
{ name: 'Bahamas', dialCode: '1242', code: 'BS', code3: 'BHS', priority: 0 },
|
|
20
|
-
{ name: 'Bahrain', dialCode: '973', code: 'BH', code3: 'BHR', priority: 0 },
|
|
21
|
-
{ name: 'Bangladesh', dialCode: '880', code: 'BD', code3: 'BGD', priority: 0 },
|
|
22
|
-
{ name: 'Barbados', dialCode: '1246', code: 'BB', code3: 'BRB', priority: 0 },
|
|
23
|
-
{ name: 'Belarus', dialCode: '375', code: 'BY', code3: 'BLR', priority: 0 },
|
|
24
|
-
{ name: 'Belgium', dialCode: '32', code: 'BE', code3: 'BEL', priority: 0 },
|
|
25
|
-
{ name: 'Belize', dialCode: '501', code: 'BZ', code3: 'BLZ', priority: 0 },
|
|
26
|
-
{ name: 'Benin', dialCode: '229', code: 'BJ', code3: 'BEN', priority: 0 },
|
|
27
|
-
{ name: 'Bermuda', dialCode: '1441', code: 'BM', code3: 'BMU', priority: 0 },
|
|
28
|
-
{ name: 'Bhutan', dialCode: '975', code: 'BT', code3: 'BTN', priority: 0 },
|
|
29
|
-
{ name: 'Bolivia', dialCode: '591', code: 'BO', code3: 'BOL', priority: 0 },
|
|
30
|
-
{ name: 'Bosnia and Herzegovina', dialCode: '387', code: 'BA', code3: 'BIH', priority: 0 },
|
|
31
|
-
{ name: 'Botswana', dialCode: '267', code: 'BW', code3: 'BWA', priority: 0 },
|
|
32
|
-
{ name: 'Brazil', dialCode: '55', code: 'BR', code3: 'BRA', priority: 0 },
|
|
33
|
-
{
|
|
34
|
-
name: 'British Indian Ocean Territory',
|
|
35
|
-
dialCode: '246',
|
|
36
|
-
code: 'IO',
|
|
37
|
-
code3: 'IOT',
|
|
38
|
-
priority: 0,
|
|
39
|
-
},
|
|
40
|
-
{ name: 'British Virgin Islands', dialCode: '1284', code: 'VG', code3: 'VGB', priority: 0 },
|
|
41
|
-
{ name: 'Brunei', dialCode: '673', code: 'BN', code3: 'BRN', priority: 0 },
|
|
42
|
-
{ name: 'Bulgaria', dialCode: '359', code: 'BG', code3: 'BGR', priority: 0 },
|
|
43
|
-
{ name: 'Burkina Faso', dialCode: '226', code: 'BF', code3: 'BFA', priority: 0 },
|
|
44
|
-
{ name: 'Burundi', dialCode: '257', code: 'BI', code3: 'BDI', priority: 0 },
|
|
45
|
-
{ name: 'Cambodia', dialCode: '855', code: 'KH', code3: 'KHM', priority: 0 },
|
|
46
|
-
{ name: 'Cameroon', dialCode: '237', code: 'CM', code3: 'CMR', priority: 0 },
|
|
47
|
-
{ name: 'Canada', dialCode: '1', code: 'CA', code3: 'CAN', priority: 1 },
|
|
48
|
-
{ name: 'Cape Verde', dialCode: '238', code: 'CV', code3: 'CPV', priority: 0 },
|
|
49
|
-
{ name: 'Cayman Islands', dialCode: '1345', code: 'KY', code3: 'CYM', priority: 0 },
|
|
50
|
-
{ name: 'Central African Republic', dialCode: '236', code: 'CF', code3: 'CAF', priority: 0 },
|
|
51
|
-
{ name: 'Chad', dialCode: '235', code: 'TD', code3: 'TCD', priority: 0 },
|
|
52
|
-
{ name: 'Chile', dialCode: '56', code: 'CL', code3: 'CHL', priority: 0 },
|
|
53
|
-
{ name: 'China', dialCode: '86', code: 'CN', code3: 'CHN', priority: 0 },
|
|
54
|
-
{ name: 'Christmas Island', dialCode: '61', code: 'CX', code3: 'CXR', priority: 0 },
|
|
55
|
-
{ name: 'Cocos Islands', dialCode: '61', code: 'CC', code3: 'CCK', priority: 0 },
|
|
56
|
-
{ name: 'Colombia', dialCode: '57', code: 'CO', code3: 'COL', priority: 0 },
|
|
57
|
-
{ name: 'Comoros', dialCode: '269', code: 'KM', code3: 'COM', priority: 0 },
|
|
58
|
-
{ name: 'Cook Islands', dialCode: '682', code: 'CK', code3: 'COK', priority: 0 },
|
|
59
|
-
{ name: 'Costa Rica', dialCode: '506', code: 'CR', code3: 'CRI', priority: 0 },
|
|
60
|
-
{ name: 'Croatia', dialCode: '385', code: 'HR', code3: 'HRV', priority: 0 },
|
|
61
|
-
{ name: 'Cuba', dialCode: '53', code: 'CU', code3: 'CUB', priority: 0 },
|
|
62
|
-
{ name: 'Curacao', dialCode: '599', code: 'CW', code3: 'CUW', priority: 0 },
|
|
63
|
-
{ name: 'Cyprus', dialCode: '357', code: 'CY', code3: 'CYP', priority: 0 },
|
|
64
|
-
{ name: 'Czech Republic', dialCode: '420', code: 'CZ', code3: 'CZE', priority: 0 },
|
|
65
|
-
{
|
|
66
|
-
name: 'Democratic Republic of the Congo',
|
|
67
|
-
dialCode: '243',
|
|
68
|
-
code: 'CD',
|
|
69
|
-
code3: 'COD',
|
|
70
|
-
priority: 0,
|
|
71
|
-
},
|
|
72
|
-
{ name: 'Denmark', dialCode: '45', code: 'DK', code3: 'DNK', priority: 0 },
|
|
73
|
-
{ name: 'Djibouti', dialCode: '253', code: 'DJ', code3: 'DJI', priority: 0 },
|
|
74
|
-
{ name: 'Dominica', dialCode: '1767', code: 'DM', code3: 'DMA', priority: 0 },
|
|
75
|
-
{ name: 'Dominican Republic', dialCode: '18', code: 'DO', code3: 'DOM', priority: 1 }, //'1809, 1829, 1849'
|
|
76
|
-
{ name: 'East Timor', dialCode: '670', code: 'TL', code3: 'TLS', priority: 0 },
|
|
77
|
-
{ name: 'Ecuador', dialCode: '593', code: 'EC', code3: 'ECU', priority: 0 },
|
|
78
|
-
{ name: 'Egypt', dialCode: '20', code: 'EG', code3: 'EGY', priority: 0 },
|
|
79
|
-
{ name: 'England', dialCode: '44', code: 'GB', code3: 'GBR', priority: 0 },
|
|
80
|
-
{ name: 'El Salvador', dialCode: '503', code: 'SV', code3: 'SLV', priority: 0 },
|
|
81
|
-
{ name: 'Equatorial Guinea', dialCode: '240', code: 'GQ', code3: 'GNQ', priority: 0 },
|
|
82
|
-
{ name: 'Eritrea', dialCode: '291', code: 'ER', code3: 'ERI', priority: 0 },
|
|
83
|
-
{ name: 'Estonia', dialCode: '372', code: 'EE', code3: 'EST', priority: 0 },
|
|
84
|
-
{ name: 'Ethiopia', dialCode: '251', code: 'ET', code3: 'ETH', priority: 0 },
|
|
85
|
-
{ name: 'Falkland Islands', dialCode: '500', code: 'FK', code3: 'FLK', priority: 0 },
|
|
86
|
-
{ name: 'Faroe Islands', dialCode: '298', code: 'FO', code3: 'FRO', priority: 0 },
|
|
87
|
-
{ name: 'Fiji', dialCode: '679', code: 'FJ', code3: 'FJI', priority: 0 },
|
|
88
|
-
{ name: 'Finland', dialCode: '358', code: 'FI', code3: 'FIN', priority: 0 },
|
|
89
|
-
{ name: 'France', dialCode: '33', code: 'FR', code3: 'FRA', priority: 0 },
|
|
90
|
-
{ name: 'French Polynesia', dialCode: '689', code: 'PF', code3: 'PYF', priority: 0 },
|
|
91
|
-
{ name: 'Gabon', dialCode: '241', code: 'GA', code3: 'GAB', priority: 0 },
|
|
92
|
-
{ name: 'Gambia', dialCode: '220', code: 'GM', code3: 'GMB', priority: 0 },
|
|
93
|
-
{ name: 'Georgia', dialCode: '995', code: 'GE', code3: 'GEO', priority: 0 },
|
|
94
|
-
{ name: 'Germany', dialCode: '49', code: 'DE', code3: 'DEU', priority: 0 },
|
|
95
|
-
{ name: 'Ghana', dialCode: '233', code: 'GH', code3: 'GHA', priority: 0 },
|
|
96
|
-
{ name: 'Gibraltar', dialCode: '350', code: 'GI', code3: 'GIB', priority: 0 },
|
|
97
|
-
{ name: 'Greece', dialCode: '30', code: 'GR', code3: 'GRC', priority: 0 },
|
|
98
|
-
{ name: 'Greenland', dialCode: '299', code: 'GL', code3: 'GRL', priority: 0 },
|
|
99
|
-
{ name: 'Grenada', dialCode: '1473', code: 'GD', code3: 'GRD', priority: 0 },
|
|
100
|
-
{ name: 'Guam', dialCode: '1671', code: 'GU', code3: 'GUM', priority: 0 },
|
|
101
|
-
{ name: 'Guatemala', dialCode: '502', code: 'GT', code3: 'GTM', priority: 0 },
|
|
102
|
-
{ name: 'Guernsey', dialCode: '441481', code: 'GG', code3: 'GGY', priority: 0 },
|
|
103
|
-
{ name: 'Guinea', dialCode: '224', code: 'GN', code3: 'GIN', priority: 0 },
|
|
104
|
-
{ name: 'GuineaBissau', dialCode: '245', code: 'GW', code3: 'GNB', priority: 0 },
|
|
105
|
-
{ name: 'Guyana', dialCode: '592', code: 'GY', code3: 'GUY', priority: 0 },
|
|
106
|
-
{ name: 'Haiti', dialCode: '509', code: 'HT', code3: 'HTI', priority: 0 },
|
|
107
|
-
{ name: 'Honduras', dialCode: '504', code: 'HN', code3: 'HND', priority: 0 },
|
|
108
|
-
{ name: 'Hong Kong', dialCode: '852', code: 'HK', code3: 'HKG', priority: 0 },
|
|
109
|
-
{ name: 'Hungary', dialCode: '36', code: 'HU', code3: 'HUN', priority: 0 },
|
|
110
|
-
{ name: 'Iceland', dialCode: '354', code: 'IS', code3: 'ISL', priority: 0 },
|
|
111
|
-
{ name: 'India', dialCode: '91', code: 'IN', code3: 'IND', priority: 0 },
|
|
112
|
-
{ name: 'Indonesia', dialCode: '62', code: 'ID', code3: 'IDN', priority: 0 },
|
|
113
|
-
{ name: 'Iran', dialCode: '98', code: 'IR', code3: 'IRN', priority: 0 },
|
|
114
|
-
{ name: 'Iraq', dialCode: '964', code: 'IQ', code3: 'IRQ', priority: 0 },
|
|
115
|
-
{ name: 'Ireland', dialCode: '353', code: 'IE', code3: 'IRL', priority: 0 },
|
|
116
|
-
{ name: 'Isle of Man', dialCode: '441624', code: 'IM', code3: 'IMN', priority: 0 },
|
|
117
|
-
{ name: 'Israel', dialCode: '972', code: 'IL', code3: 'ISR', priority: 0 },
|
|
118
|
-
{ name: 'Italy', dialCode: '39', code: 'IT', code3: 'ITA', priority: 0 },
|
|
119
|
-
{ name: 'Ivory Coast', dialCode: '225', code: 'CI', code3: 'CIV', priority: 0 },
|
|
120
|
-
{ name: 'Jamaica', dialCode: '1876', code: 'JM', code3: 'JAM', priority: 0 },
|
|
121
|
-
{ name: 'Japan', dialCode: '81', code: 'JP', code3: 'JPN', priority: 0 },
|
|
122
|
-
{ name: 'Jersey', dialCode: '441534', code: 'JE', code3: 'JEY', priority: 0 },
|
|
123
|
-
{ name: 'Jordan', dialCode: '962', code: 'JO', code3: 'JOR', priority: 0 },
|
|
124
|
-
{ name: 'Kazakhstan', dialCode: '7', code: 'KZ', code3: 'KAZ', priority: 1 },
|
|
125
|
-
{ name: 'Kenya', dialCode: '254', code: 'KE', code3: 'KEN', priority: 0 },
|
|
126
|
-
{ name: 'Kiribati', dialCode: '686', code: 'KI', code3: 'KIR', priority: 0 },
|
|
127
|
-
{ name: 'Kosovo', dialCode: '383', code: 'XK', code3: 'XKX', priority: 0 },
|
|
128
|
-
{ name: 'Kuwait', dialCode: '965', code: 'KW', code3: 'KWT', priority: 0 },
|
|
129
|
-
{ name: 'Kyrgyzstan', dialCode: '996', code: 'KG', code3: 'KGZ', priority: 0 },
|
|
130
|
-
{ name: 'Laos', dialCode: '856', code: 'LA', code3: 'LAO', priority: 0 },
|
|
131
|
-
{ name: 'Latvia', dialCode: '371', code: 'LV', code3: 'LVA', priority: 0 },
|
|
132
|
-
{ name: 'Lebanon', dialCode: '961', code: 'LB', code3: 'LBN', priority: 0 },
|
|
133
|
-
{ name: 'Lesotho', dialCode: '266', code: 'LS', code3: 'LSO', priority: 0 },
|
|
134
|
-
{ name: 'Liberia', dialCode: '231', code: 'LR', code3: 'LBR', priority: 0 },
|
|
135
|
-
{ name: 'Libya', dialCode: '218', code: 'LY', code3: 'LBY', priority: 0 },
|
|
136
|
-
{ name: 'Liechtenstein', dialCode: '423', code: 'LI', code3: 'LIE', priority: 0 },
|
|
137
|
-
{ name: 'Lithuania', dialCode: '370', code: 'LT', code3: 'LTU', priority: 0 },
|
|
138
|
-
{ name: 'Luxembourg', dialCode: '352', code: 'LU', code3: 'LUX', priority: 0 },
|
|
139
|
-
{ name: 'Macau', dialCode: '853', code: 'MO', code3: 'MAC', priority: 0 },
|
|
140
|
-
{ name: 'Macedonia', dialCode: '389', code: 'MK', code3: 'MKD', priority: 0 },
|
|
141
|
-
{ name: 'Madagascar', dialCode: '261', code: 'MG', code3: 'MDG', priority: 0 },
|
|
142
|
-
{ name: 'Malawi', dialCode: '265', code: 'MW', code3: 'MWI', priority: 0 },
|
|
143
|
-
{ name: 'Malaysia', dialCode: '60', code: 'MY', code3: 'MYS', priority: 0 },
|
|
144
|
-
{ name: 'Maldives', dialCode: '960', code: 'MV', code3: 'MDV', priority: 0 },
|
|
145
|
-
{ name: 'Mali', dialCode: '223', code: 'ML', code3: 'MLI', priority: 0 },
|
|
146
|
-
{ name: 'Malta', dialCode: '356', code: 'MT', code3: 'MLT', priority: 0 },
|
|
147
|
-
{ name: 'Marshall Islands', dialCode: '692', code: 'MH', code3: 'MHL', priority: 0 },
|
|
148
|
-
{ name: 'Mauritania', dialCode: '222', code: 'MR', code3: 'MRT', priority: 0 },
|
|
149
|
-
{ name: 'Mauritius', dialCode: '230', code: 'MU', code3: 'MUS', priority: 0 },
|
|
150
|
-
{ name: 'Mayotte', dialCode: '262', code: 'YT', code3: 'MYT', priority: 0 },
|
|
151
|
-
{ name: 'Mexico', dialCode: '52', code: 'MX', code3: 'MEX', priority: 0 },
|
|
152
|
-
{ name: 'Micronesia', dialCode: '691', code: 'FM', code3: 'FSM', priority: 0 },
|
|
153
|
-
{ name: 'Moldova', dialCode: '373', code: 'MD', code3: 'MDA', priority: 0 },
|
|
154
|
-
{ name: 'Monaco', dialCode: '377', code: 'MC', code3: 'MCO', priority: 0 },
|
|
155
|
-
{ name: 'Mongolia', dialCode: '976', code: 'MN', code3: 'MNG', priority: 0 },
|
|
156
|
-
{ name: 'Montenegro', dialCode: '382', code: 'ME', code3: 'MNE', priority: 0 },
|
|
157
|
-
{ name: 'Montserrat', dialCode: '1664', code: 'MS', code3: 'MSR', priority: 0 },
|
|
158
|
-
{ name: 'Morocco', dialCode: '212', code: 'MA', code3: 'MAR', priority: 0 },
|
|
159
|
-
{ name: 'Mozambique', dialCode: '258', code: 'MZ', code3: 'MOZ', priority: 0 },
|
|
160
|
-
{ name: 'Myanmar', dialCode: '95', code: 'MM', code3: 'MMR', priority: 0 },
|
|
161
|
-
{ name: 'Namibia', dialCode: '264', code: 'NA', code3: 'NAM', priority: 0 },
|
|
162
|
-
{ name: 'Nauru', dialCode: '674', code: 'NR', code3: 'NRU', priority: 0 },
|
|
163
|
-
{ name: 'Nepal', dialCode: '977', code: 'NP', code3: 'NPL', priority: 0 },
|
|
164
|
-
{ name: 'Netherlands', dialCode: '31', code: 'NL', code3: 'NLD', priority: 0 },
|
|
165
|
-
{ name: 'Netherlands Antilles', dialCode: '599', code: 'AN', code3: 'ANT', priority: 1 },
|
|
166
|
-
{ name: 'New Caledonia', dialCode: '687', code: 'NC', code3: 'NCL', priority: 0 },
|
|
167
|
-
{ name: 'New Zealand', dialCode: '64', code: 'NZ', code3: 'NZL', priority: 0 },
|
|
168
|
-
{ name: 'Nicaragua', dialCode: '505', code: 'NI', code3: 'NIC', priority: 0 },
|
|
169
|
-
{ name: 'Niger', dialCode: '227', code: 'NE', code3: 'NER', priority: 0 },
|
|
170
|
-
{ name: 'Nigeria', dialCode: '234', code: 'NG', code3: 'NGA', priority: 0 },
|
|
171
|
-
{ name: 'Niue', dialCode: '683', code: 'NU', code3: 'NIU', priority: 0 },
|
|
172
|
-
{ name: 'North Korea', dialCode: '850', code: 'KP', code3: 'PRK', priority: 0 },
|
|
173
|
-
{ name: 'Northern Mariana Islands', dialCode: '1670', code: 'MP', code3: 'MNP', priority: 0 },
|
|
174
|
-
{ name: 'Northern Ireland', dialCode: '44', code: 'GB', code3: 'GBR', priority: 0 },
|
|
175
|
-
{ name: 'Norway', dialCode: '47', code: 'NO', code3: 'NOR', priority: 0 },
|
|
176
|
-
{ name: 'Oman', dialCode: '968', code: 'OM', code3: 'OMN', priority: 0 },
|
|
177
|
-
{ name: 'Pakistan', dialCode: '92', code: 'PK', code3: 'PAK', priority: 0 },
|
|
178
|
-
{ name: 'Palau', dialCode: '680', code: 'PW', code3: 'PLW', priority: 0 },
|
|
179
|
-
{ name: 'Palestine', dialCode: '970', code: 'PS', code3: 'PSE', priority: 0 },
|
|
180
|
-
{ name: 'Panama', dialCode: '507', code: 'PA', code3: 'PAN', priority: 0 },
|
|
181
|
-
{ name: 'Papua New Guinea', dialCode: '675', code: 'PG', code3: 'PNG', priority: 0 },
|
|
182
|
-
{ name: 'Paraguay', dialCode: '595', code: 'PY', code3: 'PRY', priority: 0 },
|
|
183
|
-
{ name: 'Peru', dialCode: '51', code: 'PE', code3: 'PER', priority: 0 },
|
|
184
|
-
{ name: 'Philippines', dialCode: '63', code: 'PH', code3: 'PHL', priority: 0 },
|
|
185
|
-
{ name: 'Pitcairn', dialCode: '64', code: 'PN', code3: 'PCN', priority: 0 },
|
|
186
|
-
{ name: 'Poland', dialCode: '48', code: 'PL', code3: 'POL', priority: 0 },
|
|
187
|
-
{ name: 'Portugal', dialCode: '351', code: 'PT', code3: 'PRT', priority: 0 },
|
|
188
|
-
{ name: 'Puerto Rico', dialCode: '1', code: 'PR', code3: 'PRI', priority: 2 },
|
|
189
|
-
{ name: 'Qatar', dialCode: '974', code: 'QA', code3: 'QAT', priority: 0 },
|
|
190
|
-
{ name: 'Republic of the Congo', dialCode: '242', code: 'CG', code3: 'COG', priority: 0 },
|
|
191
|
-
{ name: 'Reunion', dialCode: '262', code: 'RE', code3: 'REU', priority: 0 },
|
|
192
|
-
{ name: 'Romania', dialCode: '40', code: 'RO', code3: 'ROU', priority: 0 },
|
|
193
|
-
{ name: 'Russia', dialCode: '7', code: 'RU', code3: 'RUS', priority: 0 },
|
|
194
|
-
{ name: 'Rwanda', dialCode: '250', code: 'RW', code3: 'RWA', priority: 0 },
|
|
195
|
-
{ name: 'Saint Barthelemy', dialCode: '590', code: 'BL', code3: 'BLM', priority: 0 },
|
|
196
|
-
{ name: 'Saint Helena', dialCode: '290', code: 'SH', code3: 'SHN', priority: 0 },
|
|
197
|
-
{ name: 'Saint Kitts and Nevis', dialCode: '1869', code: 'KN', code3: 'KNA', priority: 0 },
|
|
198
|
-
{ name: 'Saint Lucia', dialCode: '1758', code: 'LC', code3: 'LCA', priority: 0 },
|
|
199
|
-
{ name: 'Saint Martin', dialCode: '590', code: 'MF', code3: 'MAF', priority: 0 },
|
|
200
|
-
{ name: 'Saint Pierre and Miquelon', dialCode: '508', code: 'PM', code3: 'SPM', priority: 0 },
|
|
201
|
-
{
|
|
202
|
-
name: 'Saint Vincent and the Grenadines',
|
|
203
|
-
dialCode: '1784',
|
|
204
|
-
code: 'VC',
|
|
205
|
-
code3: 'VCT',
|
|
206
|
-
priority: 0,
|
|
207
|
-
},
|
|
208
|
-
{ name: 'Samoa', dialCode: '685', code: 'WS', code3: 'WSM', priority: 0 },
|
|
209
|
-
{ name: 'San Marino', dialCode: '378', code: 'SM', code3: 'SMR', priority: 0 },
|
|
210
|
-
{ name: 'Sao Tome and Principe', dialCode: '239', code: 'ST', code3: 'STP', priority: 0 },
|
|
211
|
-
{ name: 'Saudi Arabia', dialCode: '966', code: 'SA', code3: 'SAU', priority: 0 },
|
|
212
|
-
{ name: 'Scotland', dialCode: '44', code: 'GB', code3: 'GBR', priority: 0 },
|
|
213
|
-
{ name: 'Senegal', dialCode: '221', code: 'SN', code3: 'SEN', priority: 0 },
|
|
214
|
-
{ name: 'Serbia', dialCode: '381', code: 'RS', code3: 'SRB', priority: 0 },
|
|
215
|
-
{ name: 'Seychelles', dialCode: '248', code: 'SC', code3: 'SYC', priority: 0 },
|
|
216
|
-
{ name: 'Sierra Leone', dialCode: '232', code: 'SL', code3: 'SLE', priority: 0 },
|
|
217
|
-
{ name: 'Singapore', dialCode: '65', code: 'SG', code3: 'SGP', priority: 0 },
|
|
218
|
-
{ name: 'Sint Maarten', dialCode: '1721', code: 'SX', code3: 'SXM', priority: 0 },
|
|
219
|
-
{ name: 'Slovakia', dialCode: '421', code: 'SK', code3: 'SVK', priority: 0 },
|
|
220
|
-
{ name: 'Slovenia', dialCode: '386', code: 'SI', code3: 'SVN', priority: 0 },
|
|
221
|
-
{ name: 'Solomon Islands', dialCode: '677', code: 'SB', code3: 'SLB', priority: 0 },
|
|
222
|
-
{ name: 'Somalia', dialCode: '252', code: 'SO', code3: 'SOM', priority: 0 },
|
|
223
|
-
{ name: 'South Africa', dialCode: '27', code: 'ZA', code3: 'ZAF', priority: 0 },
|
|
224
|
-
{ name: 'South Korea', dialCode: '82', code: 'KR', code3: 'KOR', priority: 0 },
|
|
225
|
-
{ name: 'South Sudan', dialCode: '211', code: 'SS', code3: 'SSD', priority: 0 },
|
|
226
|
-
{ name: 'Spain', dialCode: '34', code: 'ES', code3: 'ESP', priority: 0 },
|
|
227
|
-
{ name: 'Sri Lanka', dialCode: '94', code: 'LK', code3: 'LKA', priority: 0 },
|
|
228
|
-
{ name: 'Sudan', dialCode: '249', code: 'SD', code3: 'SDN', priority: 0 },
|
|
229
|
-
{ name: 'Suriname', dialCode: '597', code: 'SR', code3: 'SUR', priority: 0 },
|
|
230
|
-
{ name: 'Svalbard and Jan Mayen', dialCode: '47', code: 'SJ', code3: 'SJM', priority: 0 },
|
|
231
|
-
{ name: 'Swaziland', dialCode: '268', code: 'SZ', code3: 'SWZ', priority: 0 },
|
|
232
|
-
{ name: 'Sweden', dialCode: '46', code: 'SE', code3: 'SWE', priority: 0 },
|
|
233
|
-
{ name: 'Switzerland', dialCode: '41', code: 'CH', code3: 'CHE', priority: 0 },
|
|
234
|
-
{ name: 'Syria', dialCode: '963', code: 'SY', code3: 'SYR', priority: 0 },
|
|
235
|
-
{ name: 'Taiwan', dialCode: '886', code: 'TW', code3: 'TWN', priority: 0 },
|
|
236
|
-
{ name: 'Tajikistan', dialCode: '992', code: 'TJ', code3: 'TJK', priority: 0 },
|
|
237
|
-
{ name: 'Tanzania', dialCode: '255', code: 'TZ', code3: 'TZA', priority: 0 },
|
|
238
|
-
{ name: 'Thailand', dialCode: '66', code: 'TH', code3: 'THA', priority: 0 },
|
|
239
|
-
{ name: 'Togo', dialCode: '228', code: 'TG', code3: 'TGO', priority: 0 },
|
|
240
|
-
{ name: 'Tokelau', dialCode: '690', code: 'TK', code3: 'TKL', priority: 0 },
|
|
241
|
-
{ name: 'Tonga', dialCode: '676', code: 'TO', code3: 'TON', priority: 0 },
|
|
242
|
-
{ name: 'Trinidad and Tobago', dialCode: '1868', code: 'TT', code3: 'TTO', priority: 0 },
|
|
243
|
-
{ name: 'Tunisia', dialCode: '216', code: 'TN', code3: 'TUN', priority: 0 },
|
|
244
|
-
{ name: 'Turkey', dialCode: '90', code: 'TR', code3: 'TUR', priority: 0 },
|
|
245
|
-
{ name: 'Turkmenistan', dialCode: '993', code: 'TM', code3: 'TKM', priority: 0 },
|
|
246
|
-
{ name: 'Turks and Caicos Islands', dialCode: '1649', code: 'TC', code3: 'TCA', priority: 0 },
|
|
247
|
-
{ name: 'Tuvalu', dialCode: '688', code: 'TV', code3: 'TUV', priority: 0 },
|
|
248
|
-
{ name: 'U.S. Virgin Islands', dialCode: '1340', code: 'VI', code3: 'VIR', priority: 0 },
|
|
249
|
-
{ name: 'Uganda', dialCode: '256', code: 'UG', code3: 'UGA', priority: 0 },
|
|
250
|
-
{ name: 'Ukraine', dialCode: '380', code: 'UA', code3: 'UKR', priority: 0 },
|
|
251
|
-
{ name: 'United Arab Emirates', dialCode: '971', code: 'AE', code3: 'ARE', priority: 0 },
|
|
252
|
-
{ name: 'United Kingdom', dialCode: '44', code: 'GB', code3: 'GBR', priority: 0 },
|
|
253
|
-
{ name: 'United States', dialCode: '1', code: 'US', code3: 'USA', priority: 0 },
|
|
254
|
-
{ name: 'Uruguay', dialCode: '598', code: 'UY', code3: 'URY', priority: 0 },
|
|
255
|
-
{ name: 'Uzbekistan', dialCode: '998', code: 'UZ', code3: 'UZB', priority: 0 },
|
|
256
|
-
{ name: 'Vanuatu', dialCode: '678', code: 'VU', code3: 'VUT', priority: 0 },
|
|
257
|
-
{ name: 'Vatican', dialCode: '39', code: 'VA', code3: 'VAT', priority: 1 },
|
|
258
|
-
{ name: 'Venezuela', dialCode: '58', code: 'VE', code3: 'VEN', priority: 0 },
|
|
259
|
-
{ name: 'Vietnam', dialCode: '84', code: 'VN', code3: 'VNM', priority: 0 },
|
|
260
|
-
{ name: 'Wallis and Futuna', dialCode: '681', code: 'WF', code3: 'WLF', priority: 0 },
|
|
261
|
-
{ name: 'Wales', dialCode: '44', code: 'GB', code3: 'GBR', priority: 0 },
|
|
262
|
-
{ name: 'Western Sahara', dialCode: '212', code: 'EH', code3: 'ESH', priority: 0 },
|
|
263
|
-
{ name: 'Yemen', dialCode: '967', code: 'YE', code3: 'YEM', priority: 0 },
|
|
264
|
-
{ name: 'Zambia', dialCode: '260', code: 'ZM', code3: 'ZMB', priority: 0 },
|
|
265
|
-
{ name: 'Zimbabwe', dialCode: '263', code: 'ZW', code3: 'ZWE', priority: 0 },
|
|
266
|
-
];
|
|
267
|
-
export function getCountries(sortBy) {
|
|
268
|
-
return sortBy && sortBy !== 'name' ? Utils.sortArray(AllCountries, sortBy) : AllCountries;
|
|
269
|
-
}
|
|
270
|
-
export function getCountryOptions() {
|
|
271
|
-
const countries = getCountries();
|
|
272
|
-
return countries.map((v) => ({ key: v.name, text: v.name }));
|
|
273
|
-
}
|
|
274
|
-
export function getCountryByPhoneNumber(phoneNumber) {
|
|
275
|
-
if (!phoneNumber || phoneNumber.trim() === '')
|
|
276
|
-
return;
|
|
277
|
-
phoneNumber = phoneNumber.substring(0, 6);
|
|
278
|
-
const c = AllCountries.reduce((selectedCountry, country) => {
|
|
279
|
-
if (startsWith(phoneNumber, country.dialCode)) {
|
|
280
|
-
if (country.dialCode.length > selectedCountry?.dialCode?.length) {
|
|
281
|
-
return country;
|
|
282
|
-
}
|
|
283
|
-
if (country.dialCode.length === selectedCountry.dialCode.length && country.priority < selectedCountry.priority) {
|
|
284
|
-
return country;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return selectedCountry;
|
|
288
|
-
}, { code: '', code3: '', dialCode: '', name: '', priority: 0 });
|
|
289
|
-
return c.code ? c : undefined;
|
|
290
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export class CustomEventEmitter {
|
|
2
|
-
events;
|
|
3
|
-
constructor() {
|
|
4
|
-
this.events = {};
|
|
5
|
-
}
|
|
6
|
-
on = (event, callback) => {
|
|
7
|
-
if (!this.events[event]) {
|
|
8
|
-
this.events[event] = [];
|
|
9
|
-
}
|
|
10
|
-
this.events[event].push(callback);
|
|
11
|
-
};
|
|
12
|
-
off = (event, callback) => {
|
|
13
|
-
if (!this.events[event]) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const index = this.events[event].indexOf(callback);
|
|
17
|
-
this.events[event].splice(index, 1);
|
|
18
|
-
};
|
|
19
|
-
emit = (event, ...params) => {
|
|
20
|
-
if (!this.events[event]) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
this.events[event].forEach((callback) => {
|
|
24
|
-
//callback(params);
|
|
25
|
-
if (callback) {
|
|
26
|
-
callback.apply(null, params);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
var hasElementType = typeof Element !== 'undefined';
|
|
2
|
-
var hasMap = typeof Map === 'function';
|
|
3
|
-
var hasSet = typeof Set === 'function';
|
|
4
|
-
var hasArrayBuffer = typeof ArrayBuffer === 'function' && !!ArrayBuffer.isView;
|
|
5
|
-
function deepEqual(a, b) {
|
|
6
|
-
// START: fast-deep-equal es6/index.js 3.1.1
|
|
7
|
-
if (a === b)
|
|
8
|
-
return true;
|
|
9
|
-
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
10
|
-
if (a.constructor !== b.constructor)
|
|
11
|
-
return false;
|
|
12
|
-
let length, i;
|
|
13
|
-
if (Array.isArray(a)) {
|
|
14
|
-
length = a.length;
|
|
15
|
-
if (length != b.length)
|
|
16
|
-
return false;
|
|
17
|
-
for (i = length; i-- !== 0;)
|
|
18
|
-
if (!deepEqual(a[i], b[i]))
|
|
19
|
-
return false;
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
// START: Modifications:
|
|
23
|
-
// 1. Extra `has<Type> &&` helpers in initial condition allow es6 code
|
|
24
|
-
// to co-exist with es5.
|
|
25
|
-
// 2. Replace `for of` with es5 compliant iteration using `for`.
|
|
26
|
-
// Basically, take:
|
|
27
|
-
//
|
|
28
|
-
// ```js
|
|
29
|
-
// for (i of a.entries())
|
|
30
|
-
// if (!b.has(i[0])) return false;
|
|
31
|
-
// ```
|
|
32
|
-
//
|
|
33
|
-
// ... and convert to:
|
|
34
|
-
//
|
|
35
|
-
// ```js
|
|
36
|
-
// it = a.entries();
|
|
37
|
-
// while (!(i = it.next()).done)
|
|
38
|
-
// if (!b.has(i.value[0])) return false;
|
|
39
|
-
// ```
|
|
40
|
-
//
|
|
41
|
-
// **Note**: `i` access switches to `i.value`.
|
|
42
|
-
let it;
|
|
43
|
-
if (hasMap && a instanceof Map && b instanceof Map) {
|
|
44
|
-
if (a.size !== b.size)
|
|
45
|
-
return false;
|
|
46
|
-
let it = a.entries();
|
|
47
|
-
while (!(i = it.next()).done)
|
|
48
|
-
if (!b.has(i.value[0]))
|
|
49
|
-
return false;
|
|
50
|
-
it = a.entries();
|
|
51
|
-
while (!(i = it.next()).done)
|
|
52
|
-
if (!deepEqual(i.value[1], b.get(i.value[0])))
|
|
53
|
-
return false;
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (hasSet && a instanceof Set && b instanceof Set) {
|
|
57
|
-
if (a.size !== b.size)
|
|
58
|
-
return false;
|
|
59
|
-
it = a.entries();
|
|
60
|
-
while (!(i = it.next()).done)
|
|
61
|
-
if (!b.has(i.value[0]))
|
|
62
|
-
return false;
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
// END: Modifications
|
|
66
|
-
if (hasArrayBuffer && ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
67
|
-
length = a.length;
|
|
68
|
-
if (length != b.length)
|
|
69
|
-
return false;
|
|
70
|
-
for (i = length; i-- !== 0;)
|
|
71
|
-
if (a[i] !== b[i])
|
|
72
|
-
return false;
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
if (a.constructor === RegExp)
|
|
76
|
-
return a.source === b.source && a.flags === b.flags;
|
|
77
|
-
if (a.valueOf !== Object.prototype.valueOf)
|
|
78
|
-
return a.valueOf() === b.valueOf();
|
|
79
|
-
if (a.toString !== Object.prototype.toString)
|
|
80
|
-
return a.toString() === b.toString();
|
|
81
|
-
const keys = Object.keys(a);
|
|
82
|
-
length = keys.length;
|
|
83
|
-
if (length !== Object.keys(b).length)
|
|
84
|
-
return false;
|
|
85
|
-
for (i = length; i-- !== 0;)
|
|
86
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
|
|
87
|
-
return false;
|
|
88
|
-
// custom handling for DOM elements
|
|
89
|
-
if (hasElementType && a instanceof Element)
|
|
90
|
-
return false;
|
|
91
|
-
// custom handling for React/Preact
|
|
92
|
-
for (i = length; i-- !== 0;) {
|
|
93
|
-
if ((keys[i] === '_owner' || keys[i] === '__v' || keys[i] === '__o') && a.$$typeof) {
|
|
94
|
-
// React-specific: avoid traversing React elements' _owner
|
|
95
|
-
// Preact-specific: avoid traversing Preact elements' __v and __o
|
|
96
|
-
// __v = $_original / $_vnode
|
|
97
|
-
// __o = $_owner
|
|
98
|
-
// These properties contain circular references and are not needed when
|
|
99
|
-
// comparing the actual elements (and not their owners)
|
|
100
|
-
// .$$typeof and ._store on just reasonable markers of elements
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
// all other properties should be traversed as usual
|
|
104
|
-
if (!deepEqual(a[keys[i]], b[keys[i]]))
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
return a !== a && b !== b;
|
|
110
|
-
}
|
|
111
|
-
export function fastCompare(a, b) {
|
|
112
|
-
try {
|
|
113
|
-
return deepEqual(a, b);
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
if ((error.message || '').match(/stack|recursion/i)) {
|
|
117
|
-
// warn on circular references, don't crash
|
|
118
|
-
// browsers give this different errors name and messages:
|
|
119
|
-
// chrome/safari: "RangeError", "Maximum call stack size exceeded"
|
|
120
|
-
// firefox: "InternalError", too much recursion"
|
|
121
|
-
// edge: "Error", "Out of stack space"
|
|
122
|
-
console.warn('react-fast-compare cannot handle circular refs');
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
// some other error. we should definitely know about these
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|