@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.
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,12 +1,12 @@
1
- export interface ICustomEventEmitter<EventNames = string> {
2
- on: (event: EventNames, callback: Function) => void;
3
- off: (event: EventNames, callback: Function) => void;
4
- emit: (event: EventNames, ...params: any) => void;
5
- }
6
- export declare class CustomEventEmitter implements ICustomEventEmitter {
7
- private events;
8
- constructor();
9
- on: (event: string, callback: Function) => void;
10
- off: (event: string, callback: Function) => void;
11
- emit: (event: string, ...params: any[]) => void;
12
- }
1
+ export interface ICustomEventEmitter<EventNames = string> {
2
+ on: (event: EventNames, callback: Function) => void;
3
+ off: (event: EventNames, callback: Function) => void;
4
+ emit: (event: EventNames, ...params: any) => void;
5
+ }
6
+ export declare class CustomEventEmitter implements ICustomEventEmitter {
7
+ private events;
8
+ constructor();
9
+ on: (event: string, callback: Function) => void;
10
+ off: (event: string, callback: Function) => void;
11
+ emit: (event: string, ...params: any[]) => void;
12
+ }
@@ -1,30 +1,30 @@
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
+ 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 +1 @@
1
- export declare function fastCompare(a: any, b: any): boolean;
1
+ export declare function fastCompare(a: any, b: any): boolean;
@@ -1,128 +1,128 @@
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
- }
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
+ }
@@ -1,5 +1,5 @@
1
- export declare class HideablePromise<T = any> extends Promise<T> {
2
- hide?: () => void;
3
- id?: string | number;
4
- cancel(): void;
5
- }
1
+ export declare class HideablePromise<T = any> extends Promise<T> {
2
+ hide?: () => void;
3
+ id?: string | number;
4
+ cancel(): void;
5
+ }
@@ -1,10 +1,10 @@
1
- export class HideablePromise extends Promise {
2
- hide;
3
- id;
4
- //cancel the operation
5
- cancel() {
6
- if (this.hide) {
7
- this.hide();
8
- }
9
- }
10
- }
1
+ export class HideablePromise extends Promise {
2
+ hide;
3
+ id;
4
+ //cancel the operation
5
+ cancel() {
6
+ if (this.hide) {
7
+ this.hide();
8
+ }
9
+ }
10
+ }
@@ -1,9 +1,9 @@
1
- interface ILoadScriptOptions {
2
- type?: string;
3
- charset?: string;
4
- async?: boolean;
5
- attrs?: any[];
6
- text?: string;
7
- }
8
- export declare const LoadScript: (src: string, opts?: ILoadScriptOptions | Function, callback?: Function) => void;
9
- export {};
1
+ interface ILoadScriptOptions {
2
+ type?: string;
3
+ charset?: string;
4
+ async?: boolean;
5
+ attrs?: any[];
6
+ text?: string;
7
+ }
8
+ export declare const LoadScript: (src: string, opts?: ILoadScriptOptions | Function, callback?: Function) => void;
9
+ export {};
@@ -1,51 +1,51 @@
1
- export const LoadScript = (src, opts, callback) => {
2
- var head = document.head || document.getElementsByTagName('head')[0];
3
- var script = document.createElement('script');
4
- if (typeof opts === 'function') {
5
- callback = opts;
6
- opts = {};
7
- }
8
- opts = opts || {};
9
- callback = callback || function () { };
10
- script.type = opts.type || 'text/javascript';
11
- script.charset = opts.charset || 'utf8';
12
- script.async = 'async' in opts ? !!opts.async : true;
13
- script.src = src;
14
- if (opts.attrs) {
15
- for (var attr in opts.attrs) {
16
- script.setAttribute(attr, opts.attrs[attr]);
17
- }
18
- }
19
- if (opts.text) {
20
- script.text = '' + opts.text;
21
- }
22
- var onend = 'onload' in script ? stdOnEnd : ieOnEnd;
23
- onend(script, callback);
24
- // some good legacy browsers (firefox) fail the 'in' detection above
25
- // so as a fallback we always set onload
26
- // old IE will ignore this and new IE will set onload
27
- if (!script.onload) {
28
- stdOnEnd(script, callback);
29
- }
30
- head.appendChild(script);
31
- };
32
- function stdOnEnd(script, callback) {
33
- script.onload = function () {
34
- this.onerror = this.onload = null;
35
- callback(null, script);
36
- };
37
- script.onerror = function () {
38
- // this.onload = null here is necessary
39
- // because even IE9 works not like others
40
- this.onerror = this.onload = null;
41
- callback(new Error('Failed to load ' + this.src), script);
42
- };
43
- }
44
- function ieOnEnd(script, callback) {
45
- script.onreadystatechange = function () {
46
- if (this.readyState !== 'complete' && this.readyState !== 'loaded')
47
- return;
48
- this.onreadystatechange = null;
49
- callback(null, script); // there is no way to catch loading errors in IE8
50
- };
51
- }
1
+ export const LoadScript = (src, opts, callback) => {
2
+ var head = document.head || document.getElementsByTagName('head')[0];
3
+ var script = document.createElement('script');
4
+ if (typeof opts === 'function') {
5
+ callback = opts;
6
+ opts = {};
7
+ }
8
+ opts = opts || {};
9
+ callback = callback || function () { };
10
+ script.type = opts.type || 'text/javascript';
11
+ script.charset = opts.charset || 'utf8';
12
+ script.async = 'async' in opts ? !!opts.async : true;
13
+ script.src = src;
14
+ if (opts.attrs) {
15
+ for (var attr in opts.attrs) {
16
+ script.setAttribute(attr, opts.attrs[attr]);
17
+ }
18
+ }
19
+ if (opts.text) {
20
+ script.text = '' + opts.text;
21
+ }
22
+ var onend = 'onload' in script ? stdOnEnd : ieOnEnd;
23
+ onend(script, callback);
24
+ // some good legacy browsers (firefox) fail the 'in' detection above
25
+ // so as a fallback we always set onload
26
+ // old IE will ignore this and new IE will set onload
27
+ if (!script.onload) {
28
+ stdOnEnd(script, callback);
29
+ }
30
+ head.appendChild(script);
31
+ };
32
+ function stdOnEnd(script, callback) {
33
+ script.onload = function () {
34
+ this.onerror = this.onload = null;
35
+ callback(null, script);
36
+ };
37
+ script.onerror = function () {
38
+ // this.onload = null here is necessary
39
+ // because even IE9 works not like others
40
+ this.onerror = this.onload = null;
41
+ callback(new Error('Failed to load ' + this.src), script);
42
+ };
43
+ }
44
+ function ieOnEnd(script, callback) {
45
+ script.onreadystatechange = function () {
46
+ if (this.readyState !== 'complete' && this.readyState !== 'loaded')
47
+ return;
48
+ this.onreadystatechange = null;
49
+ callback(null, script); // there is no way to catch loading errors in IE8
50
+ };
51
+ }
@@ -1,28 +1,28 @@
1
- interface IHeaderValues {
2
- headers?: Record<string, string>;
3
- errors?: any[];
4
- }
5
- /**
6
- * Enum object of keys for each header in the Map returned by getFraudPreventionHeaders().headers
7
- */
8
- export declare const fraudPreventionHeadersEnum: {
9
- TIMEZONE: string;
10
- SCREENS_DETAILS: string;
11
- WINDOW_SIZE: string;
12
- };
13
- export declare const getScreenDetails: () => {
14
- width: number | null;
15
- height: number | null;
16
- colorDepth: number | null;
17
- scalingFactor: number | null;
18
- };
19
- export declare const windowDetails: () => {
20
- width: number | null;
21
- height: number | null;
22
- };
23
- /**
24
- * Returns Map of HMRC Fraud prevention headers.
25
- * @returns {Promise<IHeaderValues>} with two fields headers and errors - The headers are a Map object and the errors are an array. If there are no errors, the array is empty
26
- */
27
- export declare const getFraudPreventionHeaders: () => Promise<IHeaderValues>;
28
- export {};
1
+ interface IHeaderValues {
2
+ headers?: Record<string, string>;
3
+ errors?: any[];
4
+ }
5
+ /**
6
+ * Enum object of keys for each header in the Map returned by getFraudPreventionHeaders().headers
7
+ */
8
+ export declare const fraudPreventionHeadersEnum: {
9
+ TIMEZONE: string;
10
+ SCREENS_DETAILS: string;
11
+ WINDOW_SIZE: string;
12
+ };
13
+ export declare const getScreenDetails: () => {
14
+ width: number | null;
15
+ height: number | null;
16
+ colorDepth: number | null;
17
+ scalingFactor: number | null;
18
+ };
19
+ export declare const windowDetails: () => {
20
+ width: number | null;
21
+ height: number | null;
22
+ };
23
+ /**
24
+ * Returns Map of HMRC Fraud prevention headers.
25
+ * @returns {Promise<IHeaderValues>} with two fields headers and errors - The headers are a Map object and the errors are an array. If there are no errors, the array is empty
26
+ */
27
+ export declare const getFraudPreventionHeaders: () => Promise<IHeaderValues>;
28
+ export {};