@react-fabric/utilities 1.0.0-beta.6 → 1.0.0-beta.60
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 +39 -21
- 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 +19 -7
- 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 +39 -21
- 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 +19 -7
- 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 +39 -21
- 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 +7 -7
- package/src/_ascii.ts +10 -5
- package/src/_boundingBox.ts +16 -4
- package/src/_countries.ts +39 -21
- 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 +88 -19
- 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/esm/_mergeRefs.js
CHANGED
|
@@ -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];
|
package/dist/esm/_tokenize.js
CHANGED
|
@@ -27,10 +27,14 @@ import { isEmpty, isArray } from './_isType.js';
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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 (
|
|
49
|
-
|
|
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';
|
package/dist/esm/useLogger.js
CHANGED
|
@@ -207,7 +207,15 @@ var logger = function logger() {
|
|
|
207
207
|
};
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
*
|
|
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 {
|
package/dist/types/_ascii.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
|
3
|
-
*
|
|
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
|
|
8
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
24
|
-
*
|
|
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
|
|
29
|
-
*
|
|
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
|
-
*
|
|
34
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @return
|
|
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
|
-
*
|
|
3
|
-
*
|
|
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;
|
package/dist/types/_dedupe.d.ts
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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[]>;
|
package/dist/types/_fetch.d.ts
CHANGED
|
@@ -5,19 +5,22 @@ declare interface FetchOptions {
|
|
|
5
5
|
signal?: string | AbortSignal;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Fetch
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
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;
|
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;
|