@react-fabric/utilities 1.0.0-beta.50 → 1.0.0-beta.58

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 (75) hide show
  1. package/dist/cjs/_ascii.js +7 -2
  2. package/dist/cjs/_boundingBox.js +16 -4
  3. package/dist/cjs/_countries.js +39 -21
  4. package/dist/cjs/_debounce.js +8 -2
  5. package/dist/cjs/_dedupe.js +47 -0
  6. package/dist/cjs/_fetch.js +12 -7
  7. package/dist/cjs/_fileType.js +16 -0
  8. package/dist/cjs/_format.js +19 -6
  9. package/dist/cjs/_getByPath.js +15 -4
  10. package/dist/cjs/_hash.js +12 -6
  11. package/dist/cjs/_interpolate.js +18 -2
  12. package/dist/cjs/_isEqual.js +37 -6
  13. package/dist/cjs/_isType.js +121 -0
  14. package/dist/cjs/_lonlat.js +62 -4
  15. package/dist/cjs/_mergeRefs.js +11 -0
  16. package/dist/cjs/_tokenize.js +17 -4
  17. package/dist/cjs/getImageColorset.js +15 -0
  18. package/dist/cjs/index.js +1 -0
  19. package/dist/cjs/useLogger.js +9 -1
  20. package/dist/esm/_ascii.js +7 -2
  21. package/dist/esm/_boundingBox.js +16 -4
  22. package/dist/esm/_countries.js +39 -21
  23. package/dist/esm/_debounce.js +8 -2
  24. package/dist/esm/_dedupe.js +47 -0
  25. package/dist/esm/_fetch.js +12 -7
  26. package/dist/esm/_fileType.js +16 -0
  27. package/dist/esm/_format.js +19 -6
  28. package/dist/esm/_getByPath.js +15 -4
  29. package/dist/esm/_hash.js +12 -6
  30. package/dist/esm/_interpolate.js +18 -2
  31. package/dist/esm/_isEqual.js +37 -6
  32. package/dist/esm/_isType.js +121 -0
  33. package/dist/esm/_lonlat.js +62 -5
  34. package/dist/esm/_mergeRefs.js +11 -0
  35. package/dist/esm/_tokenize.js +17 -4
  36. package/dist/esm/getImageColorset.js +15 -0
  37. package/dist/esm/index.js +1 -1
  38. package/dist/esm/useLogger.js +9 -1
  39. package/dist/types/_ascii.d.ts +7 -2
  40. package/dist/types/_boundingBox.d.ts +16 -4
  41. package/dist/types/_countries.d.ts +39 -21
  42. package/dist/types/_debounce.d.ts +8 -2
  43. package/dist/types/_dedupe.d.ts +47 -4
  44. package/dist/types/_fetch.d.ts +12 -9
  45. package/dist/types/_fileType.d.ts +16 -0
  46. package/dist/types/_format.d.ts +84 -13
  47. package/dist/types/_getByPath.d.ts +15 -4
  48. package/dist/types/_hash.d.ts +12 -6
  49. package/dist/types/_interpolate.d.ts +17 -2
  50. package/dist/types/_isEqual.d.ts +37 -6
  51. package/dist/types/_isType.d.ts +110 -2
  52. package/dist/types/_lonlat.d.ts +37 -2
  53. package/dist/types/_mergeRefs.d.ts +11 -0
  54. package/dist/types/_tokenize.d.ts +16 -4
  55. package/dist/types/getImageColorset.d.ts +15 -0
  56. package/dist/types/useLogger.d.ts +9 -1
  57. package/package.json +7 -7
  58. package/src/_ascii.ts +7 -2
  59. package/src/_boundingBox.ts +16 -4
  60. package/src/_countries.ts +39 -21
  61. package/src/_debounce.ts +8 -2
  62. package/src/_dedupe.ts +43 -0
  63. package/src/_fetch.ts +12 -7
  64. package/src/_fileType.ts +16 -0
  65. package/src/_format.ts +87 -18
  66. package/src/_getByPath.ts +15 -4
  67. package/src/_hash.ts +12 -6
  68. package/src/_interpolate.ts +17 -2
  69. package/src/_isEqual.ts +37 -6
  70. package/src/_isType.ts +112 -0
  71. package/src/_lonlat.ts +52 -1
  72. package/src/_mergeRefs.ts +11 -0
  73. package/src/_tokenize.ts +16 -4
  74. package/src/getImageColorset.ts +15 -0
  75. package/src/useLogger.ts +9 -1
@@ -25,15 +25,46 @@ var _typeof = require('@babel/runtime/helpers/typeof');
25
25
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
26
  */
27
27
 
28
+ /**
29
+ * Check if a value is undefined.
30
+ * @param value - The value to check.
31
+ * @returns true if the value is undefined, false otherwise.
32
+ */
28
33
  var isUndefined = function isUndefined(value) {
29
34
  return value === undefined;
30
35
  };
36
+
37
+ /**
38
+ * Check if a value is null.
39
+ * @param value - The value to check.
40
+ * @returns true if the value is null, false otherwise.
41
+ */
31
42
  var isNull = function isNull(value) {
32
43
  return value === null;
33
44
  };
45
+
46
+ /**
47
+ * Check if a value is either null or undefined.
48
+ * @param val - The value to check.
49
+ * @returns true if the value is null or undefined, false otherwise.
50
+ */
34
51
  var isNil = function isNil(val) {
35
52
  return val === undefined || val === null;
36
53
  };
54
+
55
+ /**
56
+ * Check if a value is empty.
57
+ * A value is considered empty if it is:
58
+ * - undefined
59
+ * - null
60
+ * - an empty string
61
+ * - an empty array
62
+ * - an empty object
63
+ * - an empty Map or Set
64
+ * - a boolean, number, or bigint (not empty)
65
+ * @param val - The value to check.
66
+ * @returns true if the value is empty, false otherwise.
67
+ */
37
68
  var isEmpty = function isEmpty(val) {
38
69
  if (val instanceof Date) return false;
39
70
  if (isNil(val) || val === "") {
@@ -48,36 +79,126 @@ var isEmpty = function isEmpty(val) {
48
79
  }
49
80
  return !!val && _typeof(val) === "object" && Object.entries(val).length === 0;
50
81
  };
82
+
83
+ /**
84
+ * Check if a value is an object.
85
+ * An object is considered valid if it is:
86
+ * - not null or undefined
87
+ * - not a Date instance
88
+ * - of type 'object'
89
+ * - not an array
90
+ * @param val - The value to check.
91
+ * @returns true if the value is an object, false otherwise.
92
+ */
51
93
  var isObject = function isObject(val) {
52
94
  return !isNil(val) && !(val instanceof Date) && _typeof(val) === "object" && !Array.isArray(val);
53
95
  };
96
+
97
+ /**
98
+ * Check if a value is an array.
99
+ * An array is considered valid if it is:
100
+ * - not null or undefined
101
+ * - an instance of Array
102
+ * @param val - The value to check.
103
+ * @returns true if the value is an array, false otherwise.
104
+ */
54
105
  var isArray = function isArray(val) {
55
106
  return Array.isArray(val);
56
107
  };
108
+
109
+ /**
110
+ * Check if a value is a string.
111
+ * A string is considered valid if it is:
112
+ * - not null or undefined
113
+ * - of type 'string'
114
+ * @param value - The value to check.
115
+ * @returns true if the value is a string, false otherwise.
116
+ */
57
117
  var isString = function isString(value) {
58
118
  return typeof value === "string";
59
119
  };
120
+
121
+ /**
122
+ * Check if a value is a number.
123
+ * A number is considered valid if it is:
124
+ * - not null or undefined
125
+ * - of type 'number'
126
+ * @param value - The value to check.
127
+ * @returns true if the value is a number, false otherwise.
128
+ */
60
129
  var isNumber = function isNumber(value) {
61
130
  return typeof value === "number";
62
131
  };
132
+
133
+ /**
134
+ * Check if a value is a boolean.
135
+ * A boolean is considered valid if it is:
136
+ * - not null or undefined
137
+ * - of type 'boolean'
138
+ */
63
139
  var isBoolean = function isBoolean(value) {
64
140
  return typeof value === "boolean";
65
141
  };
142
+
143
+ /**
144
+ * Check if a value is a true.
145
+ * A value is considered true if it is:
146
+ * - strictly equal to true
147
+ * - equal to 1
148
+ * - a string that is "yes" or "true" (case insensitive)
149
+ */
66
150
  var isTrue = function isTrue() {
67
151
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
68
152
  return value === true || value === 1 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "yes" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "true";
69
153
  };
154
+
155
+ /**
156
+ * Check if a value is false.
157
+ * A value is considered false if it is:
158
+ * - strictly equal to false
159
+ * - equal to 0
160
+ * - a string that is "no" or "false" (case insensitive)
161
+ */
70
162
  var isFalse = function isFalse() {
71
163
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
72
164
  return value === false || value === 0 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "no" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "false";
73
165
  };
166
+
167
+ /**
168
+ * Check if a value is a valid color.
169
+ * A color is considered valid if it:
170
+ * - starts with a '#' (hex color)
171
+ * - starts with 'rgb' (RGB color)
172
+ * - starts with 'hsl' (HSL color)
173
+ * - starts with 'lab' (Lab color)
174
+ * - is equal to 'transparent'
175
+ * @param color - The value to check.
176
+ * @returns true if the value is a valid color, false otherwise.
177
+ */
74
178
  var isColor = function isColor(color) {
75
179
  var _color$startsWith, _color$startsWith2, _color$startsWith3, _color$startsWith4;
76
180
  return ((_color$startsWith = color.startsWith) === null || _color$startsWith === void 0 ? void 0 : _color$startsWith.call(color, "#")) || ((_color$startsWith2 = color.startsWith) === null || _color$startsWith2 === void 0 ? void 0 : _color$startsWith2.call(color, "rgb")) || ((_color$startsWith3 = color.startsWith) === null || _color$startsWith3 === void 0 ? void 0 : _color$startsWith3.call(color, "hsl")) || ((_color$startsWith4 = color.startsWith) === null || _color$startsWith4 === void 0 ? void 0 : _color$startsWith4.call(color, "lab")) || color === "transparent";
77
181
  };
182
+
183
+ /**
184
+ * Check if a value is a valid SVG path.
185
+ * A valid SVG path is a string that:
186
+ * - starts with 'M' or 'm' (move to command)
187
+ * - contains at least one digit or decimal point
188
+ * - ends with 'Z' or 'z' (close path command)
189
+ * @param value - The value to check.
190
+ * @returns true if the value is a valid SVG path, false otherwise.
191
+ */
78
192
  var isSvgPath = function isSvgPath(value) {
79
193
  return typeof value === "string" && value.match(/^[Mm][\d.].*[\dzZ]$/) !== null;
80
194
  };
195
+
196
+ /**
197
+ * Check if the document is in RTL (Right-to-Left) mode.
198
+ * This function checks the computed style of the document's root element
199
+ * to determine if the direction is set to 'rtl'.
200
+ * @returns true if the document is in RTL mode, false otherwise.
201
+ */
81
202
  var isRtl = function isRtl() {
82
203
  return getComputedStyle(document.documentElement).direction === "rtl";
83
204
  };
@@ -3,6 +3,29 @@
3
3
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
4
  var _isType = require('./_isType.js');
5
5
 
6
+ var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
7
+ var _convertLatLng = convertLatLng(lonLat),
8
+ _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
9
+ lon = _convertLatLng2[0],
10
+ lat = _convertLatLng2[1];
11
+ return {
12
+ latitude: lat,
13
+ longitude: lon
14
+ };
15
+ };
16
+
17
+ /**
18
+ * Convert various formats of longitude and latitude to a tuple of [lon, lat].
19
+ * This function supports:
20
+ * - Arrays with two or three elements (e.g., [lon, lat] or [lon, lat, alt])
21
+ * - Objects with properties `lng`, `lat`, `lon`, or `longitude` and `latitude`
22
+ * - Strings in the format "lat,lon"
23
+ * The function will return a tuple of numbers [lon, lat].
24
+ *
25
+ * @param {LngLatLike} lonLat - The input longitude and latitude in various formats.
26
+ * @returns { [lon: number, lat: number] } A tuple of [lon, lat] where lon and lat are numbers.
27
+ * @throws Error if the input is not a valid format.
28
+ */
6
29
  var convertLatLng = function convertLatLng(lonLat) {
7
30
  if (_isType.isArray(lonLat) && lonLat.length === 2 || _isType.isArray(lonLat) && lonLat.length === 3) {
8
31
  return [Number(lonLat[0]), Number(lonLat[1])];
@@ -22,6 +45,19 @@ var convertLatLng = function convertLatLng(lonLat) {
22
45
  }
23
46
  throw Error("Invalid geo coordinates");
24
47
  };
48
+
49
+ /**
50
+ * Convert a coordinate to Degrees, Minutes, Seconds (DMS) format.
51
+ * This function takes a coordinate and returns a string in the format "degrees˚minutes'seconds" with direction (N/S or E/W).
52
+ * It handles both latitude and longitude coordinates.
53
+ * This function assumes that the input coordinate is in decimal degrees format.
54
+ * It converts the coordinate to DMS format by calculating the degrees, minutes, and seconds,
55
+ * and then formatting the result as a string.
56
+ *
57
+ * @param {number} coord - The coordinate to convert.
58
+ * @param {boolean} isLat - Whether the coordinate is latitude (default is false for longitude).
59
+ * @returns {string} A string representation of the coordinate in DMS format.
60
+ */
25
61
  var convertToDMS = function convertToDMS(coord) {
26
62
  var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
27
63
  var degree = Math.floor(coord);
@@ -29,13 +65,35 @@ var convertToDMS = function convertToDMS(coord) {
29
65
  var minute = (hour - Math.floor(hour)) * 60;
30
66
  return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
31
67
  };
68
+
69
+ /**
70
+ * Convert a latitude and longitude to a human-readable text format.
71
+ * This function takes a latitude and longitude in various formats and
72
+ * returns a string in the format "degrees˚minutes'seconds" with direction (N/S, E/W).
73
+ *
74
+ * This function supports:
75
+ *
76
+ * - Objects with properties `lng`, `lat`, `lon`, or `longitude` and `latitude`
77
+ * - Arrays with two or three elements (e.g., [lon, lat] or [lon, lat, alt])
78
+ * - Strings in the format "lat,lon"
79
+ *
80
+ * @param {LngLatLike} latlon - The latitude and longitude in various formats.
81
+ * @returns {string} A string representation of the location in DMS format.
82
+ *
83
+ * @example
84
+ * ```jsx
85
+ * const location = getLocationAsText({ lat: 40.7128, lng: -74.0060 });
86
+ * console.log(location); // "40˚42'51.36"N, 74˚0'21.60"W"
87
+ * ```
88
+ */
32
89
  var getLocationAsText = function getLocationAsText(latlon) {
33
- var _convertLatLng = convertLatLng(latlon),
34
- _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
35
- lon = _convertLatLng2[0],
36
- lat = _convertLatLng2[1];
90
+ var _convertLatLng3 = convertLatLng(latlon),
91
+ _convertLatLng4 = _slicedToArray(_convertLatLng3, 2),
92
+ lon = _convertLatLng4[0],
93
+ lat = _convertLatLng4[1];
37
94
  return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
38
95
  };
39
96
 
40
97
  exports.convertLatLng = convertLatLng;
98
+ exports.getLatitudeLongitude = getLatitudeLongitude;
41
99
  exports.getLocationAsText = getLocationAsText;
@@ -25,6 +25,17 @@
25
25
 
26
26
  /* istanbul ignore file */
27
27
 
28
+ /**
29
+ * Merge multiple refs into a single ref callback.
30
+ * This function allows you to combine multiple refs (either callback refs or React refs)
31
+ * into a single ref callback that can be used in React components.
32
+ * This is particularly useful when you want to assign a single element to multiple refs,
33
+ * such as when using third-party libraries that require refs or when you want to share refs between components.
34
+ * The function iterates over the provided refs and assigns the element to each ref.
35
+ *
36
+ * @param {AnyObject[]} refs - An array of refs to merge.
37
+ * @returns {function} A function that takes an element and assigns it to all provided refs.
38
+ */
28
39
  var mergeRefs = function mergeRefs() {
29
40
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
30
41
  refs[_key] = arguments[_key];
@@ -27,10 +27,14 @@ var _isType = require('./_isType.js');
27
27
 
28
28
 
29
29
  /**
30
- * split text into array of tokens by word boundaries
31
- * @param str
32
- * @param keywords
33
- * @internal
30
+ * Tokenize a string based on provided keywords.
31
+ * This function splits the input string into tokens, where each token is an array containing
32
+ * the substring before the keyword and the keyword itself.
33
+ * If no keywords are provided, it returns the entire string as a single token.
34
+ *
35
+ * @param {string} str - The string to tokenize.
36
+ * @param {string | string[]} keywords - A string or an array of strings to use as keywords for tokenization.
37
+ * @returns {Array<[string, string]>} An array of tokens, where each token is an array of [substring, keyword].
34
38
  */
35
39
  var tokenize = function tokenize(str, keywords) {
36
40
  if (_isType.isEmpty(keywords)) {
@@ -56,6 +60,15 @@ var tokenize = function tokenize(str, keywords) {
56
60
  tokens.push([str.substring(lastIndex), ""]);
57
61
  return tokens;
58
62
  };
63
+
64
+ /**
65
+ * Generate a token from a string.
66
+ * This function creates a token by taking the first letter of the first word and the first letter of the last word,
67
+ * or the first two letters of the first word if there is no last word.
68
+ *
69
+ * @param {string} str - The string to tokenize.
70
+ * @returns {string} A string token consisting of the first letters of the first and last words, or the first two letters of the first word.
71
+ */
59
72
  var iconToken = function iconToken(str) {
60
73
  var split = str.trim().split(" ");
61
74
  var first = split[0];
@@ -25,6 +25,21 @@
25
25
 
26
26
  /* istanbul ignore file */
27
27
 
28
+ /**
29
+ * Get the color set of an image element.
30
+ * This function analyzes the pixel data of an image to determine if it is predominantly light or dark.
31
+ * It returns "light", "dark", or "light_transparent"/"dark_transparent" based on the pixel analysis.
32
+ * It uses a canvas to draw the image and extract pixel data for analysis.
33
+ * * The function calculates the brightness of each pixel using the formula:
34
+ * brightness = 0.2126 * R + 0.7152 * G + 0.0722 * B
35
+ * * It counts the number of light and dark pixels, and determines the overall color set based on the ratio of light to dark pixels.
36
+ * * If the image has transparent pixels, it appends "_transparent" to the result.
37
+ * * This function is useful for determining the color scheme of an image, which can be helpful for UI design,
38
+ * theming, and accessibility considerations.
39
+ *
40
+ * @param {HTMLImageElement} el - The HTMLImageElement to analyze.
41
+ * @returns {string} A string indicating the color set of the image.
42
+ */
28
43
  var getImageColorset = function getImageColorset(el) {
29
44
  // create canvas
30
45
  var canvas = document.createElement("canvas");
package/dist/cjs/index.js CHANGED
@@ -108,6 +108,7 @@ exports.isSvgPath = _isType.isSvgPath;
108
108
  exports.isTrue = _isType.isTrue;
109
109
  exports.isUndefined = _isType.isUndefined;
110
110
  exports.convertLatLng = _lonlat.convertLatLng;
111
+ exports.getLatitudeLongitude = _lonlat.getLatitudeLongitude;
111
112
  exports.getLocationAsText = _lonlat.getLocationAsText;
112
113
  exports.mergeRefs = _mergeRefs.mergeRefs;
113
114
  exports.iconToken = _tokenize.iconToken;
@@ -207,7 +207,15 @@ var logger = function logger() {
207
207
  };
208
208
 
209
209
  /**
210
- * @internal
210
+ * useLogger is a custom hook that provides logging functionality.
211
+ * It allows you to log messages with different levels (log, debug, info, error, warning)
212
+ * and also provides a timer function to measure the duration of processes.
213
+ * The logs can include additional details such as the module name, process name, duration, and total time.
214
+ * It is designed to work in both Node.js and browser environments, adapting the log format accordingly.
215
+ * It uses ANSI escape codes for terminal colors in Node.js and CSS styles for console logs in the browser.
216
+ *
217
+ * @param mod - Optional module name to include in the log details.
218
+ * @returns An object with methods for logging messages and a timer function.
211
219
  */
212
220
  var useLogger = function useLogger(mod) {
213
221
  return {
@@ -81,8 +81,13 @@ var conversions = {
81
81
  };
82
82
 
83
83
  /**
84
- * latin to ascii converter for convenient searching
85
- * @internal
84
+ * Converts a string to its ASCII representation by replacing
85
+ * special characters with their ASCII equivalents.
86
+ * This function is useful for normalizing strings for search or display purposes.
87
+ * It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
88
+ *
89
+ * @param {string} str - The input string to be converted.
90
+ * @returns {string} - The ASCII representation of the input string.
86
91
  */
87
92
  var ascii = function ascii(str) {
88
93
  if (isEmpty(str)) return "";
@@ -18,8 +18,13 @@ var _getBox = function _getBox(box) {
18
18
  };
19
19
 
20
20
  /**
21
- * box "x,y,w,h" | [x,y,w,h]
22
- * returns canvas box [x,y,w,h]
21
+ * Get bounding box from a string or array.
22
+ * The box can be in the format "x,y,w,h" or [x,y,w,h].
23
+ * The box is adjusted to ensure that x and y are non-negative.
24
+ * The width and height are adjusted accordingly.
25
+ *
26
+ * @param box "x,y,w,h" | [x,y,w,h]
27
+ * @returns canvas box [x,y,w,h]
23
28
  */
24
29
  var getBox = function getBox() {
25
30
  var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
@@ -37,8 +42,15 @@ var getBox = function getBox() {
37
42
  };
38
43
 
39
44
  /**
40
- * box "x1,y1,x2,y2" | [x1,y1,x2,y2]
41
- * returns canvas box [x,y,w,h]
45
+ * Get bounding box from a string or array.
46
+ * The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
47
+ * The box is adjusted to ensure that x1 and y1 are non-negative.
48
+ * The width and height are calculated as x2 - x1 and y2 - y1 respectively.
49
+ * If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
50
+ * This is useful for ensuring that the bounding box is always within the canvas area.
51
+ *
52
+ * @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
53
+ * @returns canvas box [x,y,w,h]
42
54
  */
43
55
  var getBoundingBox = function getBoundingBox() {
44
56
  var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
@@ -26,32 +26,42 @@
26
26
  /* istanbul ignore file */
27
27
 
28
28
  /**
29
- * @internal
29
+ * Country interface
30
30
  */
31
31
 
32
32
  /**
33
- * country list with helper functions
33
+ * Country list with helper functions
34
+ * This is a list of all countries with their details.
35
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
36
+ * This list can be used to retrieve country information based on various codes or names.
37
+ * @type {Country[]}
34
38
  */
35
39
  var Countries = {
36
40
  /**
37
- * Get iso2 code
38
- * @param code
41
+ * Get ISO2 country code
42
+ *
43
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
44
+ * @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
39
45
  */
40
46
  toIso2: function toIso2(code) {
41
47
  var ctry = this.find(code);
42
48
  return ctry != null ? ctry.iso2 : undefined;
43
49
  },
44
50
  /**
45
- * Get iso3 code
46
- * @param code
51
+ * Get ISO3 country code
52
+ *
53
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
54
+ * @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
47
55
  */
48
56
  toIso3: function toIso3(code) {
49
57
  var ctry = this.find(code);
50
58
  return ctry != null ? ctry.iso3 : undefined;
51
59
  },
52
60
  /**
53
- * Country flag emoji
54
- * @param code
61
+ * Get country emoji
62
+ *
63
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
64
+ * @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
55
65
  */
56
66
  emoji: function emoji(code) {
57
67
  var ctry = this.find(code);
@@ -59,25 +69,25 @@ var Countries = {
59
69
  },
60
70
  /**
61
71
  * Get country name
62
- * @param code
72
+ *
73
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
74
+ * @return {string} - Returns the name of the country if found, otherwise returns the code itself.
63
75
  */
64
76
  name: function name(code) {
65
77
  var ctry = this.find(code);
66
78
  return ctry != null ? ctry.name : code;
67
79
  },
68
80
  /**
69
- * Find country by code
70
- * @param code
71
- * @return continent: string;
72
- * @return iso2: string;
73
- * @return iso3: string;
74
- * @return name: string;
75
- * @return fullname: string;
76
- * @return capital: string;
77
- * @return tld: string;
78
- * @return currency: string;
79
- * @return phone: string;
80
- * @return emoji: string;
81
+ * This function searches for a country in the list by its code.
82
+ * It supports various formats:
83
+ * - ISO2 code (e.g., "US")
84
+ * - ISO3 code (e.g., "USA")
85
+ * - Alternative code (e.g., "US", "USA", "United States")
86
+ * It returns the first matching country object or undefined if not found.
87
+ * This function is useful for retrieving country details based on different code formats.
88
+ *
89
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
90
+ * @return {Country | undefined} - Returns the country object if found, otherwise undefined.
81
91
  */
82
92
  find: function find(code) {
83
93
  return this.list.find(function (ct) {
@@ -85,6 +95,14 @@ var Countries = {
85
95
  return ((_ct$alt = ct.alt) !== null && _ct$alt !== void 0 ? _ct$alt : "__").toLowerCase() === code.toLowerCase() || ct.iso3.toLowerCase() === code.toLowerCase() || ct.iso2.toLowerCase() === code.toLowerCase();
86
96
  });
87
97
  },
98
+ /**
99
+ * Country list
100
+ * This is a list of all countries with their details.
101
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
102
+ * This list can be used to retrieve country information based on various codes or names.
103
+ *
104
+ * @type {Country[]}
105
+ */
88
106
  list: [{
89
107
  continent: "Asia",
90
108
  iso2: "AF",
@@ -26,8 +26,14 @@
26
26
  /* istanbul ignore file */
27
27
 
28
28
  /**
29
- * debounce callback
30
- * @internal
29
+ * Debounce function to limit the rate at which a function can fire.
30
+ * It will delay the execution of the function until after a specified timeout
31
+ * has elapsed since the last time the function was invoked.
32
+ *
33
+ * @param fn - The function to debounce.
34
+ * @param timeout - The number of milliseconds to wait before invoking the function.
35
+ * @returns A debounced version of the function that can be called with any arguments.
36
+ * The debounced function also has a `cancel` method to clear the timeout.
31
37
  */
32
38
  var debounce = function debounce(fn) {
33
39
  var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
@@ -25,6 +25,18 @@ import { isEmpty } from './_isType.js';
25
25
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
26
  */
27
27
 
28
+
29
+ /**
30
+ * Remove duplicates from a list of objects based on a key or the entire object.
31
+ * If a key is provided, it will deduplicate based on the value of that key.
32
+ * If no key is provided, it will deduplicate based on the entire object.
33
+ * This is useful for normalizing data structures that may have nested arrays or objects.
34
+ *
35
+ * @param list
36
+ * @param key
37
+ * @typedef {T} AnyObject - A generic type representing list items.
38
+ * @returns {T[]} - A new array with duplicates removed.
39
+ */
28
40
  var dedupe = function dedupe(list, key) {
29
41
  var filtered = list.filter(function (i) {
30
42
  return !isEmpty(i);
@@ -36,16 +48,51 @@ var dedupe = function dedupe(list, key) {
36
48
  return [obj[key], obj];
37
49
  })).values());
38
50
  };
51
+
52
+ /**
53
+ * Flatten a list of objects, removing any empty objects.
54
+ * It will flatten up to 5 levels deep and filter out any empty objects.
55
+ * This is useful for normalizing data structures that may have nested arrays or objects.
56
+ *
57
+ * @param list
58
+ * @typedef {T} AnyObject - A generic type representing list items.
59
+ * @returns {T[]} - A flattened array of objects.
60
+ */
39
61
  var flatten = function flatten(list) {
40
62
  return list.flat(5).filter(function (i) {
41
63
  return !isEmpty(i);
42
64
  });
43
65
  };
66
+
67
+ /**
68
+ * Flatten a list of objects and remove duplicates based on a key or the entire object.
69
+ * If a key is provided, it will deduplicate based on the value of that key.
70
+ * If no key is provided, it will deduplicate based on the entire object.
71
+ * This is useful for normalizing data structures that may have nested arrays or objects.
72
+ * Flattening is done first, followed by deduplication.
73
+ *
74
+ * @param list
75
+ * @param key
76
+ * @typedef {T} AnyObject - A generic type representing list items.
77
+ * @returns {T[]} - A new array with duplicates removed.
78
+ */
44
79
  var flattenAndDedupe = function flattenAndDedupe() {
45
80
  var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
46
81
  var key = arguments.length > 1 ? arguments[1] : undefined;
47
82
  return dedupe(flatten(list), key);
48
83
  };
84
+
85
+ /**
86
+ * Group a list of objects by a specific property.
87
+ * If the property is not present in an object, it will use the `missingKey` value as the key.
88
+ * This is useful for organizing data into categories based on a specific property.
89
+ *
90
+ * @param list
91
+ * @param prop
92
+ * @param missingKey
93
+ * @typedef {T} KeyValue - A generic type representing list items with key-value pairs.
94
+ * @returns {KeyValue<T[]>} - An object mapping keys to arrays of items.
95
+ */
49
96
  var groupBy = function groupBy(list, prop, missingKey) {
50
97
  return list.reduce(function (r, i) {
51
98
  var _i$prop;
@@ -10,13 +10,18 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
10
  var _signals = new Map();
11
11
 
12
12
  /**
13
- * Fetch helper
14
- * @param method
15
- * @param url
16
- * @param options.headers
17
- * @param options.body
18
- * @param options.signal
19
- * @internal
13
+ * Fetch utility function to make HTTP requests.
14
+ * It supports GET, POST, PUT, and DELETE methods.
15
+ * It automatically handles JSON responses and error codes.
16
+ * It also supports aborting requests using an AbortController.
17
+ *
18
+ * @param method - The HTTP method to use (GET, POST, PUT, DELETE).
19
+ * @param url - The URL to send the request to.
20
+ * @param options.headers - Headers to include in the request.
21
+ * @param options.body - The body of the request (for POST and PUT requests).
22
+ * @param options.signal - An AbortSignal to cancel the request.
23
+ * @returns A promise that resolves to the JSON response from the server.
24
+ * @throws An error if the request fails or if the response contains an error code.
20
25
  */
21
26
  var _fetch = /*#__PURE__*/function () {
22
27
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(method, url, _ref) {
@@ -27,7 +27,20 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
27
27
 
28
28
  /* istanbul ignore file */
29
29
 
30
+ /**
31
+ * File type utility to get the file type from a MIME type.
32
+ * This utility provides a mapping of common MIME types to their human-readable names.
33
+ * It can be used to display file types in a user-friendly manner.
34
+ */
30
35
  var _fileType = {
36
+ /**
37
+ * Get the human-readable file type from a MIME type.
38
+ * This method looks up the MIME type in a predefined list
39
+ * and returns a user-friendly name.
40
+ *
41
+ * @param mime MIME type string, e.g. "application/pdf"
42
+ * @returns {string} - The human-readable file type.
43
+ */
31
44
  mime: function mime() {
32
45
  var mime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
33
46
  var ret = this.mimeList[mime.split(";")[0]];
@@ -40,6 +53,9 @@ var _fileType = {
40
53
  }
41
54
  return ret || "Unknown type";
42
55
  },
56
+ /**
57
+ * List of common MIME types and their human-readable names.
58
+ */
43
59
  mimeList: {
44
60
  "application/x-tika-msoffice": "Microsft Office File",
45
61
  "application/x-tika-ooxml": "Open Office File",