@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.
- package/dist/cjs/_ascii.js +34 -9
- package/dist/cjs/_boundingBox.js +16 -4
- package/dist/cjs/_countries.js +61 -2769
- package/dist/cjs/_debounce.js +8 -2
- package/dist/cjs/_dedupe.js +48 -2
- package/dist/cjs/_fetch.js +12 -7
- package/dist/cjs/_fileType.js +16 -0
- package/dist/cjs/_format.js +20 -8
- package/dist/cjs/_getByPath.js +16 -5
- package/dist/cjs/_hash.js +13 -7
- package/dist/cjs/_interpolate.js +18 -2
- package/dist/cjs/_isEqual.js +40 -6
- package/dist/cjs/_isType.js +126 -1
- package/dist/cjs/_lonlat.js +102 -0
- package/dist/cjs/_mergeRefs.js +11 -0
- package/dist/cjs/_tokenize.js +17 -4
- package/dist/cjs/getImageColorset.js +17 -2
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/useLogger.js +9 -1
- package/dist/esm/_ascii.js +34 -9
- package/dist/esm/_boundingBox.js +16 -4
- package/dist/esm/_countries.js +61 -2769
- package/dist/esm/_debounce.js +8 -2
- package/dist/esm/_dedupe.js +48 -2
- package/dist/esm/_fetch.js +12 -7
- package/dist/esm/_fileType.js +16 -0
- package/dist/esm/_format.js +20 -8
- package/dist/esm/_getByPath.js +16 -5
- package/dist/esm/_hash.js +13 -7
- package/dist/esm/_interpolate.js +18 -2
- package/dist/esm/_isEqual.js +41 -7
- package/dist/esm/_isType.js +126 -2
- package/dist/esm/_lonlat.js +100 -0
- package/dist/esm/_mergeRefs.js +11 -0
- package/dist/esm/_tokenize.js +17 -4
- package/dist/esm/getImageColorset.js +17 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/useLogger.js +9 -1
- package/dist/types/_ascii.d.ts +7 -2
- package/dist/types/_boundingBox.d.ts +16 -4
- package/dist/types/_countries.d.ts +87 -60
- package/dist/types/_debounce.d.ts +8 -2
- package/dist/types/_dedupe.d.ts +47 -4
- package/dist/types/_fetch.d.ts +12 -9
- package/dist/types/_fileType.d.ts +16 -0
- package/dist/types/_format.d.ts +84 -13
- package/dist/types/_getByPath.d.ts +15 -4
- package/dist/types/_hash.d.ts +12 -6
- package/dist/types/_interpolate.d.ts +17 -2
- package/dist/types/_isEqual.d.ts +37 -6
- package/dist/types/_isType.d.ts +112 -3
- package/dist/types/_lonlat.d.ts +48 -0
- package/dist/types/_mergeRefs.d.ts +11 -0
- package/dist/types/_tokenize.d.ts +16 -4
- package/dist/types/getImageColorset.d.ts +15 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/useLogger.d.ts +9 -1
- package/package.json +8 -7
- package/src/_ascii.ts +10 -5
- package/src/_boundingBox.ts +16 -4
- package/src/_countries.ts +63 -2986
- package/src/_debounce.ts +8 -2
- package/src/_dedupe.ts +51 -5
- package/src/_fetch.ts +12 -7
- package/src/_fileType.ts +16 -0
- package/src/_format.ts +89 -20
- package/src/_getByPath.ts +18 -7
- package/src/_hash.ts +13 -7
- package/src/_interpolate.ts +17 -2
- package/src/_isEqual.ts +41 -7
- package/src/_isType.ts +116 -2
- package/src/_lonlat.ts +135 -0
- package/src/_mergeRefs.ts +11 -0
- package/src/_tokenize.ts +16 -4
- package/src/getImageColorset.ts +17 -2
- package/src/index.ts +1 -0
- package/src/useLogger.ts +9 -1
package/dist/types/_format.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
11
|
-
|
|
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
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
-
*
|
|
3
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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;
|
package/dist/types/_hash.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
9
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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
|
-
*
|
|
3
|
-
*
|
|
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;
|
package/dist/types/_isEqual.d.ts
CHANGED
|
@@ -1,15 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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;
|
package/dist/types/_isType.d.ts
CHANGED
|
@@ -1,14 +1,123 @@
|
|
|
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
|
-
|
|
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
|
+
export declare const isDefined: (val: AnyObject) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a value is empty.
|
|
22
|
+
* A value is considered empty if it is:
|
|
23
|
+
* - undefined
|
|
24
|
+
* - null
|
|
25
|
+
* - an empty string
|
|
26
|
+
* - an empty array
|
|
27
|
+
* - an empty object
|
|
28
|
+
* - an empty Map or Set
|
|
29
|
+
* - a boolean, number, or bigint (not empty)
|
|
30
|
+
* @param val - The value to check.
|
|
31
|
+
* @returns true if the value is empty, false otherwise.
|
|
32
|
+
*/
|
|
4
33
|
export declare const isEmpty: (val: AnyObject) => val is undefined;
|
|
5
|
-
|
|
6
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Check if a value is an object.
|
|
36
|
+
* An object is considered valid if it is:
|
|
37
|
+
* - not null or undefined
|
|
38
|
+
* - not a Date instance
|
|
39
|
+
* - of type 'object'
|
|
40
|
+
* - not an array
|
|
41
|
+
* @param val - The value to check.
|
|
42
|
+
* @returns true if the value is an object, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
export declare const isObject: (val: AnyObject) => val is KeyValue;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a value is an array.
|
|
47
|
+
* An array is considered valid if it is:
|
|
48
|
+
* - not null or undefined
|
|
49
|
+
* - an instance of Array
|
|
50
|
+
* @param val - The value to check.
|
|
51
|
+
* @returns true if the value is an array, false otherwise.
|
|
52
|
+
*/
|
|
53
|
+
export declare const isArray: <T = AnyObject>(val: AnyObject) => val is T[];
|
|
54
|
+
/**
|
|
55
|
+
* Check if a value is a string.
|
|
56
|
+
* A string is considered valid if it is:
|
|
57
|
+
* - not null or undefined
|
|
58
|
+
* - of type 'string'
|
|
59
|
+
* @param value - The value to check.
|
|
60
|
+
* @returns true if the value is a string, false otherwise.
|
|
61
|
+
*/
|
|
7
62
|
export declare const isString: (value: AnyObject) => value is string;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a value is a number.
|
|
65
|
+
* A number is considered valid if it is:
|
|
66
|
+
* - not null or undefined
|
|
67
|
+
* - of type 'number'
|
|
68
|
+
* @param value - The value to check.
|
|
69
|
+
* @returns true if the value is a number, false otherwise.
|
|
70
|
+
*/
|
|
8
71
|
export declare const isNumber: (value: AnyObject) => value is number;
|
|
72
|
+
/**
|
|
73
|
+
* Check if a value is a boolean.
|
|
74
|
+
* A boolean is considered valid if it is:
|
|
75
|
+
* - not null or undefined
|
|
76
|
+
* - of type 'boolean'
|
|
77
|
+
*/
|
|
9
78
|
export declare const isBoolean: (value: AnyObject) => value is boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if a value is a true.
|
|
81
|
+
* A value is considered true if it is:
|
|
82
|
+
* - strictly equal to true
|
|
83
|
+
* - equal to 1
|
|
84
|
+
* - a string that is "yes" or "true" (case insensitive)
|
|
85
|
+
*/
|
|
10
86
|
export declare const isTrue: (value?: AnyObject) => value is true;
|
|
87
|
+
/**
|
|
88
|
+
* Check if a value is false.
|
|
89
|
+
* A value is considered false if it is:
|
|
90
|
+
* - strictly equal to false
|
|
91
|
+
* - equal to 0
|
|
92
|
+
* - a string that is "no" or "false" (case insensitive)
|
|
93
|
+
*/
|
|
11
94
|
export declare const isFalse: (value?: AnyObject) => value is false;
|
|
95
|
+
/**
|
|
96
|
+
* Check if a value is a valid color.
|
|
97
|
+
* A color is considered valid if it:
|
|
98
|
+
* - starts with a '#' (hex color)
|
|
99
|
+
* - starts with 'rgb' (RGB color)
|
|
100
|
+
* - starts with 'hsl' (HSL color)
|
|
101
|
+
* - starts with 'lab' (Lab color)
|
|
102
|
+
* - is equal to 'transparent'
|
|
103
|
+
* @param color - The value to check.
|
|
104
|
+
* @returns true if the value is a valid color, false otherwise.
|
|
105
|
+
*/
|
|
12
106
|
export declare const isColor: (color: string) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Check if a value is a valid SVG path.
|
|
109
|
+
* A valid SVG path is a string that:
|
|
110
|
+
* - starts with 'M' or 'm' (move to command)
|
|
111
|
+
* - contains at least one digit or decimal point
|
|
112
|
+
* - ends with 'Z' or 'z' (close path command)
|
|
113
|
+
* @param value - The value to check.
|
|
114
|
+
* @returns true if the value is a valid SVG path, false otherwise.
|
|
115
|
+
*/
|
|
13
116
|
export declare const isSvgPath: (value: AnyObject) => value is string;
|
|
117
|
+
/**
|
|
118
|
+
* Check if the document is in RTL (Right-to-Left) mode.
|
|
119
|
+
* This function checks the computed style of the document's root element
|
|
120
|
+
* to determine if the direction is set to 'rtl'.
|
|
121
|
+
* @returns true if the document is in RTL mode, false otherwise.
|
|
122
|
+
*/
|
|
14
123
|
export declare const isRtl: () => boolean;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type LngLatLike = {
|
|
2
|
+
lng: number;
|
|
3
|
+
lat: number;
|
|
4
|
+
} | {
|
|
5
|
+
lon: number;
|
|
6
|
+
lat: number;
|
|
7
|
+
} | {
|
|
8
|
+
longitude: number;
|
|
9
|
+
latitude: number;
|
|
10
|
+
} | [lon: number | string, lat: number | string] | [lon: number | string, lat: number | string, z: number | string] | string;
|
|
11
|
+
export declare const getLatitudeLongitude: (lonLat: LngLatLike) => {
|
|
12
|
+
latitude: number;
|
|
13
|
+
longitude: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Convert various formats of longitude and latitude to a tuple of [lon, lat].
|
|
17
|
+
* This function supports:
|
|
18
|
+
* - Arrays with two or three elements (e.g., [lon, lat] or [lon, lat, alt])
|
|
19
|
+
* - Objects with properties `lng`, `lat`, `lon`, or `longitude` and `latitude`
|
|
20
|
+
* - Strings in the format "lat,lon"
|
|
21
|
+
* The function will return a tuple of numbers [lon, lat].
|
|
22
|
+
*
|
|
23
|
+
* @param {LngLatLike} lonLat - The input longitude and latitude in various formats.
|
|
24
|
+
* @returns { [lon: number, lat: number] } A tuple of [lon, lat] where lon and lat are numbers.
|
|
25
|
+
* @throws Error if the input is not a valid format.
|
|
26
|
+
*/
|
|
27
|
+
export declare const convertLatLng: (lonLat: LngLatLike) => [lon: number, lat: number];
|
|
28
|
+
/**
|
|
29
|
+
* Convert a latitude and longitude to a human-readable text format.
|
|
30
|
+
* This function takes a latitude and longitude in various formats and
|
|
31
|
+
* returns a string in the format "degrees˚minutes'seconds" with direction (N/S, E/W).
|
|
32
|
+
*
|
|
33
|
+
* This function supports:
|
|
34
|
+
*
|
|
35
|
+
* - Objects with properties `lng`, `lat`, `lon`, or `longitude` and `latitude`
|
|
36
|
+
* - Arrays with two or three elements (e.g., [lon, lat] or [lon, lat, alt])
|
|
37
|
+
* - Strings in the format "lat,lon"
|
|
38
|
+
*
|
|
39
|
+
* @param {LngLatLike} latlon - The latitude and longitude in various formats.
|
|
40
|
+
* @returns {string} A string representation of the location in DMS format.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```jsx
|
|
44
|
+
* const location = getLocationAsText({ lat: 40.7128, lng: -74.0060 });
|
|
45
|
+
* console.log(location); // "40˚42'51.36"N, 74˚0'21.60"W"
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const getLocationAsText: (latlon: LngLatLike) => string;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge multiple refs into a single ref callback.
|
|
3
|
+
* This function allows you to combine multiple refs (either callback refs or React refs)
|
|
4
|
+
* into a single ref callback that can be used in React components.
|
|
5
|
+
* This is particularly useful when you want to assign a single element to multiple refs,
|
|
6
|
+
* such as when using third-party libraries that require refs or when you want to share refs between components.
|
|
7
|
+
* The function iterates over the provided refs and assigns the element to each ref.
|
|
8
|
+
*
|
|
9
|
+
* @param {AnyObject[]} refs - An array of refs to merge.
|
|
10
|
+
* @returns {function} A function that takes an element and assigns it to all provided refs.
|
|
11
|
+
*/
|
|
1
12
|
export declare const mergeRefs: (...refs: AnyObject[]) => (el: AnyObject) => void;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Tokenize a string based on provided keywords.
|
|
3
|
+
* This function splits the input string into tokens, where each token is an array containing
|
|
4
|
+
* the substring before the keyword and the keyword itself.
|
|
5
|
+
* If no keywords are provided, it returns the entire string as a single token.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The string to tokenize.
|
|
8
|
+
* @param {string | string[]} keywords - A string or an array of strings to use as keywords for tokenization.
|
|
9
|
+
* @returns {Array<[string, string]>} An array of tokens, where each token is an array of [substring, keyword].
|
|
6
10
|
*/
|
|
7
11
|
export declare const tokenize: (str: string, keywords?: string | string[]) => string[][];
|
|
12
|
+
/**
|
|
13
|
+
* Generate a token from a string.
|
|
14
|
+
* This function creates a token by taking the first letter of the first word and the first letter of the last word,
|
|
15
|
+
* or the first two letters of the first word if there is no last word.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} str - The string to tokenize.
|
|
18
|
+
* @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.
|
|
19
|
+
*/
|
|
8
20
|
export declare const iconToken: (str: string) => string;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the color set of an image element.
|
|
3
|
+
* This function analyzes the pixel data of an image to determine if it is predominantly light or dark.
|
|
4
|
+
* It returns "light", "dark", or "light_transparent"/"dark_transparent" based on the pixel analysis.
|
|
5
|
+
* It uses a canvas to draw the image and extract pixel data for analysis.
|
|
6
|
+
* * The function calculates the brightness of each pixel using the formula:
|
|
7
|
+
* brightness = 0.2126 * R + 0.7152 * G + 0.0722 * B
|
|
8
|
+
* * It counts the number of light and dark pixels, and determines the overall color set based on the ratio of light to dark pixels.
|
|
9
|
+
* * If the image has transparent pixels, it appends "_transparent" to the result.
|
|
10
|
+
* * This function is useful for determining the color scheme of an image, which can be helpful for UI design,
|
|
11
|
+
* theming, and accessibility considerations.
|
|
12
|
+
*
|
|
13
|
+
* @param {HTMLImageElement} el - The HTMLImageElement to analyze.
|
|
14
|
+
* @returns {string} A string indicating the color set of the image.
|
|
15
|
+
*/
|
|
1
16
|
export declare const getImageColorset: (el: HTMLImageElement) => string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./_hash";
|
|
|
13
13
|
export * from "./_interpolate";
|
|
14
14
|
export * from "./_isEqual";
|
|
15
15
|
export * from "./_isType";
|
|
16
|
+
export * from "./_lonlat";
|
|
16
17
|
export * from "./_mergeRefs";
|
|
17
18
|
export * from "./_tokenize";
|
|
18
19
|
export { getImageColorset } from "./getImageColorset";
|
|
@@ -5,7 +5,15 @@ interface LogDetail {
|
|
|
5
5
|
totalTime?: number;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* useLogger is a custom hook that provides logging functionality.
|
|
9
|
+
* It allows you to log messages with different levels (log, debug, info, error, warning)
|
|
10
|
+
* and also provides a timer function to measure the duration of processes.
|
|
11
|
+
* The logs can include additional details such as the module name, process name, duration, and total time.
|
|
12
|
+
* It is designed to work in both Node.js and browser environments, adapting the log format accordingly.
|
|
13
|
+
* It uses ANSI escape codes for terminal colors in Node.js and CSS styles for console logs in the browser.
|
|
14
|
+
*
|
|
15
|
+
* @param mod - Optional module name to include in the log details.
|
|
16
|
+
* @returns An object with methods for logging messages and a timer function.
|
|
9
17
|
*/
|
|
10
18
|
export declare const useLogger: (mod?: string) => {
|
|
11
19
|
timer(process: string): {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/utilities",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.61",
|
|
4
4
|
"description": "RUF: Utility package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,17 +32,18 @@
|
|
|
32
32
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"date-fns": "
|
|
36
|
-
"libphonenumber-js": "
|
|
37
|
-
"numeral": "
|
|
38
|
-
"
|
|
35
|
+
"date-fns": "~4.1.0",
|
|
36
|
+
"libphonenumber-js": "~1.12.25",
|
|
37
|
+
"numeral": "~2.0.6",
|
|
38
|
+
"world-countries": "~5.1.0",
|
|
39
|
+
"yup": "~1.7.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@types/numeral": "
|
|
42
|
+
"@types/numeral": "~2.0.5"
|
|
42
43
|
},
|
|
43
44
|
"engines": {
|
|
44
45
|
"node": ">=18.12.0",
|
|
45
46
|
"npm": ">=8.19.0"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
|
|
48
49
|
}
|
package/src/_ascii.ts
CHANGED
|
@@ -80,14 +80,19 @@ const conversions = {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
83
|
+
* Converts a string to its ASCII representation by replacing
|
|
84
|
+
* special characters with their ASCII equivalents.
|
|
85
|
+
* This function is useful for normalizing strings for search or display purposes.
|
|
86
|
+
* It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} str - The input string to be converted.
|
|
89
|
+
* @returns {string} - The ASCII representation of the input string.
|
|
85
90
|
*/
|
|
86
91
|
export const ascii = (str: string) => {
|
|
87
92
|
if (isEmpty(str)) return "";
|
|
88
|
-
Object.entries(conversions).forEach((
|
|
89
|
-
const re = new RegExp(
|
|
90
|
-
str = `${str}`.replace(re,
|
|
93
|
+
Object.entries(conversions).forEach((entry) => {
|
|
94
|
+
const re = new RegExp(entry[1], "g");
|
|
95
|
+
str = `${str}`.replace(re, entry[0]);
|
|
91
96
|
});
|
|
92
97
|
return str;
|
|
93
98
|
};
|
package/src/_boundingBox.ts
CHANGED
|
@@ -38,8 +38,13 @@ const _getBox = (
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* box
|
|
42
|
-
*
|
|
41
|
+
* Get bounding box from a string or array.
|
|
42
|
+
* The box can be in the format "x,y,w,h" or [x,y,w,h].
|
|
43
|
+
* The box is adjusted to ensure that x and y are non-negative.
|
|
44
|
+
* The width and height are adjusted accordingly.
|
|
45
|
+
*
|
|
46
|
+
* @param box "x,y,w,h" | [x,y,w,h]
|
|
47
|
+
* @returns canvas box [x,y,w,h]
|
|
43
48
|
*/
|
|
44
49
|
export const getBox = (
|
|
45
50
|
box: string | [number, number, number, number] = "0,0,0,0",
|
|
@@ -55,8 +60,15 @@ export const getBox = (
|
|
|
55
60
|
};
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
|
-
* box
|
|
59
|
-
*
|
|
63
|
+
* Get bounding box from a string or array.
|
|
64
|
+
* The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
|
|
65
|
+
* The box is adjusted to ensure that x1 and y1 are non-negative.
|
|
66
|
+
* The width and height are calculated as x2 - x1 and y2 - y1 respectively.
|
|
67
|
+
* If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
|
|
68
|
+
* This is useful for ensuring that the bounding box is always within the canvas area.
|
|
69
|
+
*
|
|
70
|
+
* @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
|
|
71
|
+
* @returns canvas box [x,y,w,h]
|
|
60
72
|
*/
|
|
61
73
|
export const getBoundingBox = (
|
|
62
74
|
box: string | [number, number, number, number] = "0,0,0,0",
|