@react-fabric/utilities 1.0.0-beta.5 → 1.0.0-beta.52

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 +39 -21
  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 +19 -6
  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 +121 -0
  14. package/dist/cjs/_lonlat.js +87 -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 +3 -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 +39 -21
  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 +19 -6
  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 +121 -0
  33. package/dist/esm/_lonlat.js +86 -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 +1 -0
  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 +111 -3
  52. package/dist/types/_lonlat.d.ts +45 -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 +4 -4
  59. package/src/_ascii.ts +10 -5
  60. package/src/_boundingBox.ts +16 -4
  61. package/src/_countries.ts +39 -21
  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 +87 -18
  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 +113 -1
  72. package/src/_lonlat.ts +124 -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
@@ -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,5 +1,5 @@
1
1
  /**
2
- * @internal
2
+ * Country interface
3
3
  */
4
4
  export interface Country {
5
5
  continent: string;
@@ -16,44 +16,62 @@ export interface Country {
16
16
  emoji: string;
17
17
  }
18
18
  /**
19
- * country list with helper functions
19
+ * Country list with helper functions
20
+ * This is a list of all countries with their details.
21
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
22
+ * This list can be used to retrieve country information based on various codes or names.
23
+ * @type {Country[]}
20
24
  */
21
25
  declare const _default: {
22
26
  /**
23
- * Get iso2 code
24
- * @param code
27
+ * Get ISO2 country code
28
+ *
29
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
30
+ * @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
25
31
  */
26
32
  toIso2(code: string): string | undefined;
27
33
  /**
28
- * Get iso3 code
29
- * @param code
34
+ * Get ISO3 country code
35
+ *
36
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
37
+ * @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
30
38
  */
31
39
  toIso3(code: string): string | undefined;
32
40
  /**
33
- * Country flag emoji
34
- * @param code
41
+ * Get country emoji
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} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
35
45
  */
36
46
  emoji(code: string): string;
37
47
  /**
38
48
  * Get country name
39
- * @param code
49
+ *
50
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
51
+ * @return {string} - Returns the name of the country if found, otherwise returns the code itself.
40
52
  */
41
53
  name: (code: string) => string;
42
54
  /**
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;
55
+ * This function searches for a country in the list by its code.
56
+ * It supports various formats:
57
+ * - ISO2 code (e.g., "US")
58
+ * - ISO3 code (e.g., "USA")
59
+ * - Alternative code (e.g., "US", "USA", "United States")
60
+ * It returns the first matching country object or undefined if not found.
61
+ * This function is useful for retrieving country details based on different code formats.
62
+ *
63
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
64
+ * @return {Country | undefined} - Returns the country object if found, otherwise undefined.
55
65
  */
56
66
  find(code: string): Country | undefined;
67
+ /**
68
+ * Country list
69
+ * This is a list of all countries with their details.
70
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
71
+ * This list can be used to retrieve country information based on various codes or names.
72
+ *
73
+ * @type {Country[]}
74
+ */
57
75
  list: ({
58
76
  continent: string;
59
77
  iso2: string;
@@ -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;
@@ -1,27 +1,98 @@
1
+ /**
2
+ * Format utility functions for various data types.
3
+ * This namespace provides methods to format phone numbers, numbers, bytes, percentages, dates, and durations.
4
+ */
1
5
  export declare namespace Format {
2
- /** ***************** format phone number using `libphonenumber-js` *******************/
6
+ /**
7
+ * Format phone number with country flag or emoji.
8
+ * It takes a phone number string, a country code, and a boolean to indicate whether to use CSS classes for flags.
9
+ * If the phone number is empty, less than 6 characters, or does not match the regex for valid phone numbers,
10
+ * it returns the original value.
11
+ * If the phone number is valid, it formats the phone number using `libphonenumber-js` and returns it with the country flag or emoji.
12
+ * The country flag is represented as a CSS class, and the emoji is obtained from the `Countries` module.
13
+ *
14
+ * @param {string} value - The phone number to format.
15
+ * @param {string} country - The country code to use for formatting.
16
+ * @param {boolean} useCss - Whether to use CSS classes for flags.
17
+ * @returns {string} The formatted phone number with country flag or emoji.
18
+ */
3
19
  const phone: (value?: string, country?: string, useCss?: boolean) => string | undefined;
4
- /** ***************** format whole number using `numeral` *******************/
20
+ /**
21
+ * Format number using `numeral`.
22
+ * It takes a number or string and a format string, and returns the formatted number.
23
+ * If the number is undefined or null, it returns an empty string.
24
+ * If the number starts with a '+', it retains the '+' sign in the formatted output.
25
+ * This function is useful for displaying numbers in a human-readable format,
26
+ * such as for financial data, statistics, or any numerical representation.
27
+ *
28
+ * @param {string | number} number - number or string to format
29
+ * @param {string} [format] - optional format string, defaults to "0,0[.]00a"
30
+ * @returns {string} formatted number
31
+ */
5
32
  const number: (number?: string | number, format?: string) => string;
6
- /** ***************** format bytes using `numeral` *******************/
33
+ /**
34
+ * Format bytes using `numeral`.
35
+ * It takes a number or string and returns the formatted bytes.
36
+ * If the number is undefined or null, it returns an empty string.
37
+ * If the number starts with a '+', it retains the '+' sign in the formatted output.
38
+ * This function is useful for displaying file sizes or data transfer amounts in a human-readable format.
39
+ *
40
+ * @param {string | number} number - number or string to format
41
+ * @returns {string} formatted bytes
42
+ */
7
43
  const bytes: (number?: string | number) => string;
8
- /** ***************** format percentage using `numeral` *******************/
44
+ /**
45
+ * Format percentage using `numeral`.
46
+ * It takes a number or string and returns the formatted percentage.
47
+ * If the number is undefined or null, it returns an empty string.
48
+ * If the number starts with a '+', it retains the '+' sign in the formatted output.
49
+ *
50
+ * @param {string | number} number - number or string to format
51
+ * @returns {string} formatted percentage
52
+ */
9
53
  const percent: (number?: string | number) => string;
10
- /** ***************** format date using `date-fns` *******************/
11
- const date: (date?: Date | string | number, fmt?: string) => string;
54
+ /**
55
+ * Format date using `date-fns`.
56
+ * It takes a date (as a Date object, string, or number) and a format string.
57
+ * If the date is undefined or null, it returns an empty string.
58
+ * If the date is a valid date, it formats it using the provided format string.
59
+ * Format defaults to "d-M-y" if not provided.
60
+ *
61
+ * @param {date | string | number} date - Date object, string, or number to format
62
+ * @typedef {string} format - Optional format string, defaults to "d-M-y"
63
+ * @returns {string} - Formatted date string
64
+ */
65
+ const date: (date?: Date | string | number, format?: string) => string;
12
66
  /** ***************** format time duration from total seconds/milliseconds *******************/
13
67
  /**
14
68
  * Format time duration with milliseconds
15
- * @param number
16
- * @param isFraction
17
- * @returns
69
+ * This function takes a number or string representing a duration in seconds or milliseconds,
70
+ * and returns a formatted string in the format "HH:mm:ss.SSS".
71
+ * If the input is undefined or null, it returns "00:00.000".
72
+ * If the input is Infinity, it returns "∞".
73
+ * The function also accepts an optional boolean parameter `isFraction` to indicate whether the input is in seconds (true) or milliseconds (false).
74
+ * If `isFraction` is true, the input is multiplied by 1000 to convert seconds to milliseconds.
75
+ * The function uses the `makeDuration` helper function to format the duration.
76
+ *
77
+ * @param {string | number} number - The duration to format, can be a string or number.
78
+ * @param {boolean} isFraction - Optional parameter to indicate if the input is in seconds (true) or milliseconds (false).
79
+ * @returns {string} - The formatted duration string.
18
80
  */
19
81
  const duration: (number?: string | number, isFraction?: boolean) => string | undefined;
20
82
  /**
21
- * Format time duration without milliseconds
22
- * @param number
23
- * @param isFraction
24
- * @returns
83
+ * Format time duration in seconds
84
+ * This function takes a number or string representing a duration in seconds,
85
+ * and returns a formatted string in the format "HH:mm:ss".
86
+ * If the input is undefined or null, it returns "00:00".
87
+ * If the input is Infinity, it returns "∞".
88
+ * The function also accepts an optional boolean parameter `isFraction` to indicate whether the input is in seconds (true) or milliseconds (false).
89
+ * If `isFraction` is true, the input is multiplied by 1000 to convert seconds to milliseconds.
90
+ * The function uses the `makeDuration` helper function to format the duration.
91
+ * This function is useful for displaying durations in a human-readable format, such as for timers or elapsed time.
92
+ *
93
+ * @param {string | number} number - The duration to format, can be a string or number.
94
+ * @param {boolean} isFraction - Optional parameter to indicate if the input is in seconds (true) or milliseconds (false).
95
+ * @returns {string} - The formatted duration string.
25
96
  */
26
97
  const durationSeconds: (number?: string | number, isFraction?: boolean) => string | undefined;
27
98
  }
@@ -1,10 +1,21 @@
1
1
  /**
2
- * get property value by path
3
- * @internal
2
+ * Get a value from an object by a given path.
3
+ * This function allows you to retrieve a value from a nested object structure using a dot-separated path.
4
+ * If the path does not exist or the object is empty, it returns a default value.
5
+ * @param {KeyValue} obj - The object from which to retrieve the value.
6
+ * @param {string} path - The dot-separated path to the value within the object.
7
+ * @param {any} defaultValue - The value to return if the path does not exist or the object is empty.
8
+ * @typedef {T} AnyObject - The type of the value to be returned.
9
+ * @returns {T} The value at the specified path, or the default value if the path does not exist.
4
10
  */
5
11
  export declare const getByPath: <T = any>(obj: KeyValue, path: string, defaultValue?: any) => T;
6
12
  /**
7
- * get first available value in list
8
- * @internal
13
+ * Get the first non-empty value from the provided arguments.
14
+ * This function is useful for finding a default value or fallback when multiple values are provided.
15
+ * It checks each argument in order and returns the first one that is not empty.
16
+ * If all arguments are empty, it returns `undefined`.
17
+ *
18
+ * @param {...any} args - The values to check for non-emptiness.
19
+ * @returns {any} The first non-empty value, or `undefined` if all are empty.
9
20
  */
10
21
  export declare const getValue: (...args: any[]) => any;
@@ -1,16 +1,22 @@
1
1
  /**
2
- * calculate hash from string
2
+ * Generate a hash from a string.
3
+ * This function computes a simple hash by iterating over each character in the string,
4
+ * performing bitwise operations to produce a 32-bit integer hash.
3
5
  * @param str
4
- * @internal
6
+ * @returns {number} A 32-bit integer hash of the input string.
5
7
  */
6
8
  export declare const hash: (str: string) => number;
7
9
  /**
8
- * generate short hash from current time
9
- * @internal
10
+ * Generate a short hash using the current timestamp and a random number.
11
+ * This function creates a unique identifier by combining the current time in milliseconds
12
+ * with a random number, and then converting it to a base-36 string.
13
+ * @returns {string} A short hash string.
10
14
  */
11
15
  export declare const shortHash: () => string;
12
16
  /**
13
- * generate uuid using `crypto.getRandomValues`
14
- * @internal
17
+ * Generate a UUID (Universally Unique Identifier).
18
+ * This function creates a version 4 UUID by generating random numbers
19
+ * and formatting them according to the UUID standard.
20
+ * @returns {string} A UUID string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
15
21
  */
16
22
  export declare const uuid: () => string;
@@ -1,6 +1,21 @@
1
1
  /**
2
- * interpolate string template using model
3
- * @internal
2
+ * Interpolate a string with values from a model.
3
+ * This function replaces placeholders in the format ${key} with corresponding values from the model object.
4
+ * If the value is not a string or number, it returns an empty string.
5
+ *
6
+ * @param {string} str - The string to interpolate.
7
+ * @param {KeyValue} model - The model object containing key-value pairs for interpolation.
8
+ * @returns {string} The interpolated string with placeholders replaced by values from the model.
4
9
  */
5
10
  export declare const interpolate: (str: string, model: KeyValue) => string;
11
+ /**
12
+ * Render a template string with values from a model.
13
+ * This function replaces placeholders in the format {{key}} with corresponding values from the model object.
14
+ * If the value is not a string or number, it returns an empty string.
15
+ * This is similar to the interpolate function but for handlebar templates.
16
+ *
17
+ * @param {string} str - The template string to render.
18
+ * @param {KeyValue} model - The model object containing key-value pairs for rendering the template.
19
+ * @returns {string} The rendered template string with placeholders replaced by values from the model.
20
+ */
6
21
  export declare const renderTemplate: (str: string, model: KeyValue) => string;
@@ -1,15 +1,46 @@
1
1
  /**
2
- * check equality of objects
3
- * @internal
2
+ * Compare two objects or values for equality.
3
+ * This function checks if two values are equal, including nested objects and arrays.
4
+ * It handles various data types such as strings, numbers, booleans, arrays, and objects.
5
+ * If both values are `null` or `undefined`, they are considered equal.
6
+ * If both values are primitive types (string, number, boolean), they are compared directly.
7
+ * If both values are arrays, they are compared element by element.
8
+ * If both values are objects, they are compared by their keys and values.
9
+ * If the values are of different types or structures, they are considered not equal.
10
+ *
11
+ * @param {unknown} obj - The first value to compare.
12
+ * @param {unknown} test - The second value to compare against the first.
13
+ * @returns {boolean} - Returns true if the values are equal, false otherwise.
4
14
  */
5
15
  export declare const isEqual: (obj: unknown, test: unknown) => boolean;
6
16
  /**
7
- * match strings
8
- * @internal
17
+ * Match a string against another string with options for equality.
18
+ * This function checks if the base string starts with, includes, or is equal to the match string,
19
+ * based on the specified equality condition.
20
+ * It normalizes both strings to lowercase and ASCII format before comparison.
21
+ * This is useful for case-insensitive and ASCII-only comparisons,
22
+ * such as when filtering or searching through text data.
23
+ *
24
+ * @param {string} base - The base string to match against.
25
+ * @param {string} match - The string to match with the base string.
26
+ * @param {("start" | boolean)} equality - The type of match to perform:
27
+ * - "start": checks if the base string starts with the match string.
28
+ * - true: checks for exact equality.
29
+ * - false (default): checks if the base string includes the match string.
30
+ * @returns {boolean} - Returns true if the base string matches the conditions specified by the match string and equality.
9
31
  */
10
32
  export declare const matchString: (base: string, match: string, equality?: "start" | boolean) => boolean;
11
33
  /**
12
- * compare values
13
- * @internal
34
+ * Compare two values for sorting.
35
+ * This function compares two values based on the specified order (ascending or descending).
36
+ * If a key is provided, it compares the values of that key in the objects.
37
+ * It handles various data types such as strings, numbers, booleans, and objects.
38
+ * It returns a comparison function that can be used with array sorting methods.
39
+ * * The comparison is done in a case-insensitive manner for strings,
40
+ * treating special characters as their ASCII equivalents.
41
+ *
42
+ * @param {("asc" | "desc")} order - The order of comparison, either "asc" for ascending or "desc" for descending.
43
+ * @param {string} key - An optional key to compare values within objects.
44
+ * @returns {Function} A comparison function that can be used with array sorting methods.
14
45
  */
15
46
  export declare const compareValues: (order?: "asc" | "desc", key?: string) => (a: unknown, b: unknown) => 0 | 1 | -1;
@@ -1,14 +1,122 @@
1
+ /**
2
+ * Check if a value is undefined.
3
+ * @param value - The value to check.
4
+ * @returns true if the value is undefined, false otherwise.
5
+ */
1
6
  export declare const isUndefined: (value: AnyObject) => value is undefined;
7
+ /**
8
+ * Check if a value is null.
9
+ * @param value - The value to check.
10
+ * @returns true if the value is null, false otherwise.
11
+ */
2
12
  export declare const isNull: (value: AnyObject) => value is null;
3
- export declare const isNil: (val: AnyObject) => val is undefined;
13
+ /**
14
+ * Check if a value is either null or undefined.
15
+ * @param val - The value to check.
16
+ * @returns true if the value is null or undefined, false otherwise.
17
+ */
18
+ export declare const isNil: (val: AnyObject) => val is null | undefined;
19
+ /**
20
+ * Check if a value is empty.
21
+ * A value is considered empty if it is:
22
+ * - undefined
23
+ * - null
24
+ * - an empty string
25
+ * - an empty array
26
+ * - an empty object
27
+ * - an empty Map or Set
28
+ * - a boolean, number, or bigint (not empty)
29
+ * @param val - The value to check.
30
+ * @returns true if the value is empty, false otherwise.
31
+ */
4
32
  export declare const isEmpty: (val: AnyObject) => val is undefined;
5
- export declare const isObject: (val: AnyObject) => val is KeyValue<any>;
6
- export declare const isArray: <T = any>(val: AnyObject) => val is T[];
33
+ /**
34
+ * Check if a value is an object.
35
+ * An object is considered valid if it is:
36
+ * - not null or undefined
37
+ * - not a Date instance
38
+ * - of type 'object'
39
+ * - not an array
40
+ * @param val - The value to check.
41
+ * @returns true if the value is an object, false otherwise.
42
+ */
43
+ export declare const isObject: (val: AnyObject) => val is KeyValue;
44
+ /**
45
+ * Check if a value is an array.
46
+ * An array is considered valid if it is:
47
+ * - not null or undefined
48
+ * - an instance of Array
49
+ * @param val - The value to check.
50
+ * @returns true if the value is an array, false otherwise.
51
+ */
52
+ export declare const isArray: <T = AnyObject>(val: AnyObject) => val is T[];
53
+ /**
54
+ * Check if a value is a string.
55
+ * A string is considered valid if it is:
56
+ * - not null or undefined
57
+ * - of type 'string'
58
+ * @param value - The value to check.
59
+ * @returns true if the value is a string, false otherwise.
60
+ */
7
61
  export declare const isString: (value: AnyObject) => value is string;
62
+ /**
63
+ * Check if a value is a number.
64
+ * A number is considered valid if it is:
65
+ * - not null or undefined
66
+ * - of type 'number'
67
+ * @param value - The value to check.
68
+ * @returns true if the value is a number, false otherwise.
69
+ */
8
70
  export declare const isNumber: (value: AnyObject) => value is number;
71
+ /**
72
+ * Check if a value is a boolean.
73
+ * A boolean is considered valid if it is:
74
+ * - not null or undefined
75
+ * - of type 'boolean'
76
+ */
9
77
  export declare const isBoolean: (value: AnyObject) => value is boolean;
78
+ /**
79
+ * Check if a value is a true.
80
+ * A value is considered true if it is:
81
+ * - strictly equal to true
82
+ * - equal to 1
83
+ * - a string that is "yes" or "true" (case insensitive)
84
+ */
10
85
  export declare const isTrue: (value?: AnyObject) => value is true;
86
+ /**
87
+ * Check if a value is false.
88
+ * A value is considered false if it is:
89
+ * - strictly equal to false
90
+ * - equal to 0
91
+ * - a string that is "no" or "false" (case insensitive)
92
+ */
11
93
  export declare const isFalse: (value?: AnyObject) => value is false;
94
+ /**
95
+ * Check if a value is a valid color.
96
+ * A color is considered valid if it:
97
+ * - starts with a '#' (hex color)
98
+ * - starts with 'rgb' (RGB color)
99
+ * - starts with 'hsl' (HSL color)
100
+ * - starts with 'lab' (Lab color)
101
+ * - is equal to 'transparent'
102
+ * @param color - The value to check.
103
+ * @returns true if the value is a valid color, false otherwise.
104
+ */
12
105
  export declare const isColor: (color: string) => boolean;
106
+ /**
107
+ * Check if a value is a valid SVG path.
108
+ * A valid SVG path is a string that:
109
+ * - starts with 'M' or 'm' (move to command)
110
+ * - contains at least one digit or decimal point
111
+ * - ends with 'Z' or 'z' (close path command)
112
+ * @param value - The value to check.
113
+ * @returns true if the value is a valid SVG path, false otherwise.
114
+ */
13
115
  export declare const isSvgPath: (value: AnyObject) => value is string;
116
+ /**
117
+ * Check if the document is in RTL (Right-to-Left) mode.
118
+ * This function checks the computed style of the document's root element
119
+ * to determine if the direction is set to 'rtl'.
120
+ * @returns true if the document is in RTL mode, false otherwise.
121
+ */
14
122
  export declare const isRtl: () => boolean;