@react-fabric/utilities 1.0.0-beta.6 → 1.0.0-beta.61

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 (77) hide show
  1. package/dist/cjs/_ascii.js +34 -9
  2. package/dist/cjs/_boundingBox.js +16 -4
  3. package/dist/cjs/_countries.js +61 -2769
  4. package/dist/cjs/_debounce.js +8 -2
  5. package/dist/cjs/_dedupe.js +48 -2
  6. package/dist/cjs/_fetch.js +12 -7
  7. package/dist/cjs/_fileType.js +16 -0
  8. package/dist/cjs/_format.js +20 -8
  9. package/dist/cjs/_getByPath.js +16 -5
  10. package/dist/cjs/_hash.js +13 -7
  11. package/dist/cjs/_interpolate.js +18 -2
  12. package/dist/cjs/_isEqual.js +40 -6
  13. package/dist/cjs/_isType.js +126 -1
  14. package/dist/cjs/_lonlat.js +102 -0
  15. package/dist/cjs/_mergeRefs.js +11 -0
  16. package/dist/cjs/_tokenize.js +17 -4
  17. package/dist/cjs/getImageColorset.js +17 -2
  18. package/dist/cjs/index.js +5 -0
  19. package/dist/cjs/useLogger.js +9 -1
  20. package/dist/esm/_ascii.js +34 -9
  21. package/dist/esm/_boundingBox.js +16 -4
  22. package/dist/esm/_countries.js +61 -2769
  23. package/dist/esm/_debounce.js +8 -2
  24. package/dist/esm/_dedupe.js +48 -2
  25. package/dist/esm/_fetch.js +12 -7
  26. package/dist/esm/_fileType.js +16 -0
  27. package/dist/esm/_format.js +20 -8
  28. package/dist/esm/_getByPath.js +16 -5
  29. package/dist/esm/_hash.js +13 -7
  30. package/dist/esm/_interpolate.js +18 -2
  31. package/dist/esm/_isEqual.js +41 -7
  32. package/dist/esm/_isType.js +126 -2
  33. package/dist/esm/_lonlat.js +100 -0
  34. package/dist/esm/_mergeRefs.js +11 -0
  35. package/dist/esm/_tokenize.js +17 -4
  36. package/dist/esm/getImageColorset.js +17 -2
  37. package/dist/esm/index.js +2 -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 +87 -60
  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 +112 -3
  52. package/dist/types/_lonlat.d.ts +48 -0
  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/index.d.ts +1 -0
  57. package/dist/types/useLogger.d.ts +9 -1
  58. package/package.json +8 -7
  59. package/src/_ascii.ts +10 -5
  60. package/src/_boundingBox.ts +16 -4
  61. package/src/_countries.ts +63 -2986
  62. package/src/_debounce.ts +8 -2
  63. package/src/_dedupe.ts +51 -5
  64. package/src/_fetch.ts +12 -7
  65. package/src/_fileType.ts +16 -0
  66. package/src/_format.ts +89 -20
  67. package/src/_getByPath.ts +18 -7
  68. package/src/_hash.ts +13 -7
  69. package/src/_interpolate.ts +17 -2
  70. package/src/_isEqual.ts +41 -7
  71. package/src/_isType.ts +116 -2
  72. package/src/_lonlat.ts +135 -0
  73. package/src/_mergeRefs.ts +11 -0
  74. package/src/_tokenize.ts +16 -4
  75. package/src/getImageColorset.ts +17 -2
  76. package/src/index.ts +1 -0
  77. package/src/useLogger.ts +9 -1
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { isEmpty, isArray, isObject, isString } from './_isType.js';
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
+ */
29
+ var convertLatLng = function convertLatLng(lonLat) {
30
+ if (isEmpty(lonLat)) {
31
+ throw Error("Invalid geo coordinates");
32
+ }
33
+ if (isArray(lonLat) && lonLat.length === 2 || isArray(lonLat) && lonLat.length === 3) {
34
+ return [Number(lonLat[0]), Number(lonLat[1])];
35
+ }
36
+ if (isObject(lonLat)) {
37
+ if ("longitude" in lonLat) {
38
+ return [lonLat.longitude, lonLat.latitude];
39
+ }
40
+ return ["lon" in lonLat ? lonLat.lon : lonLat.lng, lonLat.lat];
41
+ }
42
+ if (isString(lonLat)) {
43
+ var _lonLat$split = lonLat.split(","),
44
+ _lonLat$split2 = _slicedToArray(_lonLat$split, 2),
45
+ _lat = _lonLat$split2[0],
46
+ _lon = _lonLat$split2[1];
47
+ if (!isNaN(+_lat) && !isNaN(+_lon)) return [+_lon, +_lat];
48
+ }
49
+ throw Error("Invalid geo coordinates");
50
+ };
51
+
52
+ /**
53
+ * Convert a coordinate to Degrees, Minutes, Seconds (DMS) format.
54
+ * This function takes a coordinate and returns a string in the format "degrees˚minutes'seconds" with direction (N/S or E/W).
55
+ * It handles both latitude and longitude coordinates.
56
+ * This function assumes that the input coordinate is in decimal degrees format.
57
+ * It converts the coordinate to DMS format by calculating the degrees, minutes, and seconds,
58
+ * and then formatting the result as a string.
59
+ *
60
+ * @param {number} coord - The coordinate to convert.
61
+ * @param {boolean} isLat - Whether the coordinate is latitude (default is false for longitude).
62
+ * @returns {string} A string representation of the coordinate in DMS format.
63
+ */
64
+ var convertToDMS = function convertToDMS(coord) {
65
+ var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
66
+ var degree = Math.floor(Math.abs(coord));
67
+ var hour = (Math.abs(coord) - degree) * 60;
68
+ var minute = (hour - Math.floor(hour)) * 60;
69
+ return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
70
+ };
71
+
72
+ /**
73
+ * Convert a latitude and longitude to a human-readable text format.
74
+ * This function takes a latitude and longitude in various formats and
75
+ * returns a string in the format "degrees˚minutes'seconds" with direction (N/S, E/W).
76
+ *
77
+ * This function supports:
78
+ *
79
+ * - Objects with properties `lng`, `lat`, `lon`, or `longitude` and `latitude`
80
+ * - Arrays with two or three elements (e.g., [lon, lat] or [lon, lat, alt])
81
+ * - Strings in the format "lat,lon"
82
+ *
83
+ * @param {LngLatLike} latlon - The latitude and longitude in various formats.
84
+ * @returns {string} A string representation of the location in DMS format.
85
+ *
86
+ * @example
87
+ * ```jsx
88
+ * const location = getLocationAsText({ lat: 40.7128, lng: -74.0060 });
89
+ * console.log(location); // "40˚42'51.36"N, 74˚0'21.60"W"
90
+ * ```
91
+ */
92
+ var getLocationAsText = function getLocationAsText(latlon) {
93
+ var _convertLatLng3 = convertLatLng(latlon),
94
+ _convertLatLng4 = _slicedToArray(_convertLatLng3, 2),
95
+ lon = _convertLatLng4[0],
96
+ lat = _convertLatLng4[1];
97
+ return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
98
+ };
99
+
100
+ export { convertLatLng, getLatitudeLongitude, 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 @@ import { isEmpty, isArray } from './_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 (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");
@@ -45,8 +60,8 @@ var getImageColorset = function getImageColorset(el) {
45
60
  transparent = true;
46
61
  continue;
47
62
  }
48
- if (transparent && data[x - 1] === 1) {
49
- continue;
63
+ if (data[x + 3] < 1) {
64
+ transparent = true;
50
65
  }
51
66
  r = data[x];
52
67
  g = data[x + 1];
package/dist/esm/index.js CHANGED
@@ -12,7 +12,8 @@ export { getByPath, getValue } from './_getByPath.js';
12
12
  export { hash, shortHash, uuid } from './_hash.js';
13
13
  export { interpolate, renderTemplate } from './_interpolate.js';
14
14
  export { compareValues, isEqual, matchString } from './_isEqual.js';
15
- export { isArray, isBoolean, isColor, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
15
+ export { isArray, isBoolean, isColor, isDefined, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
16
+ export { convertLatLng, getLatitudeLongitude, getLocationAsText } from './_lonlat.js';
16
17
  export { mergeRefs } from './_mergeRefs.js';
17
18
  export { iconToken, tokenize } from './_tokenize.js';
18
19
  export { getImageColorset } from './getImageColorset.js';
@@ -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 {
@@ -1,5 +1,10 @@
1
1
  /**
2
- * latin to ascii converter for convenient searching
3
- * @internal
2
+ * Converts a string to its ASCII representation by replacing
3
+ * special characters with their ASCII equivalents.
4
+ * This function is useful for normalizing strings for search or display purposes.
5
+ * It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
6
+ *
7
+ * @param {string} str - The input string to be converted.
8
+ * @returns {string} - The ASCII representation of the input string.
4
9
  */
5
10
  export declare const ascii: (str: string) => string;
@@ -1,10 +1,22 @@
1
1
  /**
2
- * box "x,y,w,h" | [x,y,w,h]
3
- * returns canvas box [x,y,w,h]
2
+ * Get bounding box from a string or array.
3
+ * The box can be in the format "x,y,w,h" or [x,y,w,h].
4
+ * The box is adjusted to ensure that x and y are non-negative.
5
+ * The width and height are adjusted accordingly.
6
+ *
7
+ * @param box "x,y,w,h" | [x,y,w,h]
8
+ * @returns canvas box [x,y,w,h]
4
9
  */
5
10
  export declare const getBox: (box?: string | [number, number, number, number]) => [number, number, number, number];
6
11
  /**
7
- * box "x1,y1,x2,y2" | [x1,y1,x2,y2]
8
- * returns canvas box [x,y,w,h]
12
+ * Get bounding box from a string or array.
13
+ * The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
14
+ * The box is adjusted to ensure that x1 and y1 are non-negative.
15
+ * The width and height are calculated as x2 - x1 and y2 - y1 respectively.
16
+ * If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
17
+ * This is useful for ensuring that the bounding box is always within the canvas area.
18
+ *
19
+ * @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
20
+ * @returns canvas box [x,y,w,h]
9
21
  */
10
22
  export declare const getBoundingBox: (box?: string | [number, number, number, number]) => [number, number, number, number];
@@ -1,85 +1,112 @@
1
- /**
2
- * @internal
3
- */
4
- export interface Country {
5
- continent: string;
6
- iso2: string;
7
- iso3: string;
8
- alt?: string;
9
- name: string;
1
+ import { type Country as _Ctry } from "world-countries";
2
+ export type Country = _Ctry & {
10
3
  alpha: string;
11
- fullname: string;
12
- capital: string;
13
- tld: string;
14
- currency: string;
15
4
  phone: string;
16
- emoji: string;
17
- }
5
+ iconCode: string;
6
+ currency: {
7
+ code: string;
8
+ name?: string;
9
+ symbol?: string;
10
+ };
11
+ };
18
12
  /**
19
- * country list with helper functions
13
+ * Country list with helper functions
14
+ * This is a list of all countries with their details.
15
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
16
+ * This list can be used to retrieve country information based on various codes or names.
17
+ * @type {Country[]}
20
18
  */
21
19
  declare const _default: {
22
20
  /**
23
- * Get iso2 code
24
- * @param code
21
+ * Get ISO2 country code
22
+ *
23
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
24
+ * @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
25
25
  */
26
26
  toIso2(code: string): string | undefined;
27
27
  /**
28
- * Get iso3 code
29
- * @param code
28
+ * Get ISO3 country code
29
+ *
30
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
31
+ * @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
30
32
  */
31
33
  toIso3(code: string): string | undefined;
32
34
  /**
33
- * Country flag emoji
34
- * @param code
35
+ * Get country emoji
36
+ *
37
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
38
+ * @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
35
39
  */
36
40
  emoji(code: string): string;
37
41
  /**
38
42
  * Get country name
39
- * @param code
43
+ *
44
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
45
+ * @return {string} - Returns the name of the country if found, otherwise returns the code itself.
40
46
  */
41
47
  name: (code: string) => string;
42
48
  /**
43
- * Find country by code
44
- * @param code
45
- * @return continent: string;
46
- * @return iso2: string;
47
- * @return iso3: string;
48
- * @return name: string;
49
- * @return fullname: string;
50
- * @return capital: string;
51
- * @return tld: string;
52
- * @return currency: string;
53
- * @return phone: string;
54
- * @return emoji: string;
49
+ * This function searches for a country in the list by its code.
50
+ * It supports various formats:
51
+ * - ISO2 code (e.g., "US")
52
+ * - ISO3 code (e.g., "USA")
53
+ * - Alternative code (e.g., "US", "USA", "United States")
54
+ * It returns the first matching country object or undefined if not found.
55
+ * This function is useful for retrieving country details based on different code formats.
56
+ *
57
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
58
+ * @return {Country | undefined} - Returns the country object if found, otherwise undefined.
55
59
  */
56
60
  find(code: string): Country | undefined;
57
- list: ({
58
- continent: string;
59
- iso2: string;
60
- iso3: string;
61
- alpha: string;
62
- name: string;
63
- fullname: string;
64
- capital: string;
65
- tld: string;
66
- currency: string;
67
- phone: string;
68
- emoji: string;
69
- alt?: undefined;
70
- } | {
71
- continent: string;
72
- iso2: string;
73
- iso3: string;
74
- alt: string;
61
+ /**
62
+ * Country list
63
+ * This is a list of all countries with their details.
64
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
65
+ * This list can be used to retrieve country information based on various codes or names.
66
+ *
67
+ * @type {Country[]}
68
+ */
69
+ list: {
70
+ iconCode: string;
75
71
  alpha: string;
76
- name: string;
77
- fullname: string;
78
- capital: string;
79
- tld: string;
80
- currency: string;
81
72
  phone: string;
82
- emoji: string;
83
- })[];
73
+ currency: {
74
+ code: string;
75
+ name?: string | undefined;
76
+ symbol?: string | undefined;
77
+ };
78
+ name: import("world-countries").CountryName;
79
+ tld: string[];
80
+ cca2: string;
81
+ ccn3: string;
82
+ cca3: string;
83
+ cioc: string;
84
+ independent: boolean;
85
+ status: string;
86
+ unMember: boolean;
87
+ unRegionalGroup: "African Group" | "Asia and the Pacific Group" | "Eastern European Group" | "Latin American and Caribbean Group" | "Western European and Others Group" | "";
88
+ currencies: {
89
+ [currencyCode: string]: import("world-countries").Currency;
90
+ };
91
+ idd: import("world-countries").IntlDirectDialingCode;
92
+ capital: string[];
93
+ altSpellings: string[];
94
+ region: string;
95
+ subregion: string;
96
+ languages: {
97
+ [languageCode: string]: string;
98
+ };
99
+ translations: {
100
+ [languageCode: string]: import("world-countries").OfficialAndCommon;
101
+ };
102
+ latlng: [number, number];
103
+ demonyms: {
104
+ [languageCode: string]: import("world-countries").Demonyms;
105
+ };
106
+ landlocked: boolean;
107
+ borders: string[];
108
+ area: number;
109
+ flag: string;
110
+ }[];
84
111
  };
85
112
  export default _default;
@@ -1,6 +1,12 @@
1
1
  /**
2
- * debounce callback
3
- * @internal
2
+ * Debounce function to limit the rate at which a function can fire.
3
+ * It will delay the execution of the function until after a specified timeout
4
+ * has elapsed since the last time the function was invoked.
5
+ *
6
+ * @param fn - The function to debounce.
7
+ * @param timeout - The number of milliseconds to wait before invoking the function.
8
+ * @returns A debounced version of the function that can be called with any arguments.
9
+ * The debounced function also has a `cancel` method to clear the timeout.
4
10
  */
5
11
  export declare const debounce: (fn: (...rest: any) => any, timeout?: number) => {
6
12
  (...args: any): void;
@@ -1,4 +1,47 @@
1
- export declare const dedupe: (list: any[], key?: string) => any[];
2
- export declare const flatten: (list: any[]) => any[];
3
- export declare const flattenAndDedupe: (list?: any[], key?: string) => any[];
4
- export declare const groupBy: <T extends KeyValue<any>>(list: T[], prop: keyof T, missingKey?: string) => KeyValue<T[]>;
1
+ /**
2
+ * Remove duplicates from a list of objects based on a key or the entire object.
3
+ * If a key is provided, it will deduplicate based on the value of that key.
4
+ * If no key is provided, it will deduplicate based on the entire object.
5
+ * This is useful for normalizing data structures that may have nested arrays or objects.
6
+ *
7
+ * @param list
8
+ * @param key
9
+ * @typedef {T} AnyObject - A generic type representing list items.
10
+ * @returns {T[]} - A new array with duplicates removed.
11
+ */
12
+ export declare const dedupe: <T extends AnyObject>(list: T[], key?: keyof T) => T[];
13
+ /**
14
+ * Flatten a list of objects, removing any empty objects.
15
+ * It will flatten up to 5 levels deep and filter out any empty objects.
16
+ * This is useful for normalizing data structures that may have nested arrays or objects.
17
+ *
18
+ * @param list
19
+ * @typedef {T} AnyObject - A generic type representing list items.
20
+ * @returns {T[]} - A flattened array of objects.
21
+ */
22
+ export declare const flatten: <T extends AnyObject>(list: T[]) => (T extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr : InnerArr : InnerArr : InnerArr : InnerArr : T)[];
23
+ /**
24
+ * Flatten a list of objects and remove duplicates based on a key or the entire object.
25
+ * If a key is provided, it will deduplicate based on the value of that key.
26
+ * If no key is provided, it will deduplicate based on the entire object.
27
+ * This is useful for normalizing data structures that may have nested arrays or objects.
28
+ * Flattening is done first, followed by deduplication.
29
+ *
30
+ * @param list
31
+ * @param key
32
+ * @typedef {T} AnyObject - A generic type representing list items.
33
+ * @returns {T[]} - A new array with duplicates removed.
34
+ */
35
+ export declare const flattenAndDedupe: <T extends AnyObject>(list?: T[][], key?: keyof T) => T[];
36
+ /**
37
+ * Group a list of objects by a specific property.
38
+ * If the property is not present in an object, it will use the `missingKey` value as the key.
39
+ * This is useful for organizing data into categories based on a specific property.
40
+ *
41
+ * @param list
42
+ * @param prop
43
+ * @param missingKey
44
+ * @typedef {T} KeyValue - A generic type representing list items with key-value pairs.
45
+ * @returns {KeyValue<T[]>} - An object mapping keys to arrays of items.
46
+ */
47
+ export declare const groupBy: <T extends KeyValue>(list: T[], prop: keyof T, missingKey?: string) => KeyValue<T[]>;
@@ -5,19 +5,22 @@ declare interface FetchOptions {
5
5
  signal?: string | AbortSignal;
6
6
  }
7
7
  /**
8
- * Fetch helper
9
- * @param method
10
- * @param url
11
- * @param options.headers
12
- * @param options.body
13
- * @param options.signal
14
- * @internal
8
+ * Fetch utility function to make HTTP requests.
9
+ * It supports GET, POST, PUT, and DELETE methods.
10
+ * It automatically handles JSON responses and error codes.
11
+ * It also supports aborting requests using an AbortController.
12
+ *
13
+ * @param method - The HTTP method to use (GET, POST, PUT, DELETE).
14
+ * @param url - The URL to send the request to.
15
+ * @param options.headers - Headers to include in the request.
16
+ * @param options.body - The body of the request (for POST and PUT requests).
17
+ * @param options.signal - An AbortSignal to cancel the request.
18
+ * @returns A promise that resolves to the JSON response from the server.
19
+ * @throws An error if the request fails or if the response contains an error code.
15
20
  */
16
21
  export declare const _fetch: {
17
22
  (method: METHODS, url: string, { headers, body, signal }: FetchOptions): Promise<any>;
18
- /** ***************** attach isAborted helper to fetch method *******************/
19
23
  isAborted({ name }: Error): boolean;
20
- /** ***************** attach abort helper to fetch method *******************/
21
24
  abort(signal: string): void;
22
25
  };
23
26
  export {};
@@ -1,5 +1,21 @@
1
+ /**
2
+ * File type utility to get the file type from a MIME type.
3
+ * This utility provides a mapping of common MIME types to their human-readable names.
4
+ * It can be used to display file types in a user-friendly manner.
5
+ */
1
6
  declare const _default: {
7
+ /**
8
+ * Get the human-readable file type from a MIME type.
9
+ * This method looks up the MIME type in a predefined list
10
+ * and returns a user-friendly name.
11
+ *
12
+ * @param mime MIME type string, e.g. "application/pdf"
13
+ * @returns {string} - The human-readable file type.
14
+ */
2
15
  mime(mime?: string): any;
16
+ /**
17
+ * List of common MIME types and their human-readable names.
18
+ */
3
19
  mimeList: {
4
20
  "application/x-tika-msoffice": string;
5
21
  "application/x-tika-ooxml": string;