@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.
- 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 -6
- 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 +121 -0
- package/dist/cjs/_lonlat.js +87 -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 +3 -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 -6
- 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 +121 -0
- package/dist/esm/_lonlat.js +86 -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 +1 -0
- 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 +111 -3
- package/dist/types/_lonlat.d.ts +45 -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 +4 -4
- 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 +87 -18
- 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 +113 -1
- package/src/_lonlat.ts +124 -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/cjs/_ascii.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
3
|
var _isType = require('./_isType.js');
|
|
5
4
|
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
/** ***************** latin-ascii conversions *******************/
|
|
7
30
|
var conversions = {
|
|
8
31
|
AE: "Æ|Ǽ",
|
|
@@ -58,17 +81,19 @@ var conversions = {
|
|
|
58
81
|
};
|
|
59
82
|
|
|
60
83
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
84
|
+
* Converts a string to its ASCII representation by replacing
|
|
85
|
+
* special characters with their ASCII equivalents.
|
|
86
|
+
* This function is useful for normalizing strings for search or display purposes.
|
|
87
|
+
* It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} str - The input string to be converted.
|
|
90
|
+
* @returns {string} - The ASCII representation of the input string.
|
|
63
91
|
*/
|
|
64
92
|
var ascii = function ascii(str) {
|
|
65
93
|
if (_isType.isEmpty(str)) return "";
|
|
66
|
-
Object.entries(conversions).forEach(function (
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
l = _ref2[1];
|
|
70
|
-
var re = new RegExp(l, "g");
|
|
71
|
-
str = "".concat(str).replace(re, a);
|
|
94
|
+
Object.entries(conversions).forEach(function (entry) {
|
|
95
|
+
var re = new RegExp(entry[1], "g");
|
|
96
|
+
str = "".concat(str).replace(re, entry[0]);
|
|
72
97
|
});
|
|
73
98
|
return str;
|
|
74
99
|
};
|
package/dist/cjs/_boundingBox.js
CHANGED
|
@@ -18,8 +18,13 @@ var _getBox = function _getBox(box) {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* box
|
|
22
|
-
*
|
|
21
|
+
* Get bounding box from a string or array.
|
|
22
|
+
* The box can be in the format "x,y,w,h" or [x,y,w,h].
|
|
23
|
+
* The box is adjusted to ensure that x and y are non-negative.
|
|
24
|
+
* The width and height are adjusted accordingly.
|
|
25
|
+
*
|
|
26
|
+
* @param box "x,y,w,h" | [x,y,w,h]
|
|
27
|
+
* @returns canvas box [x,y,w,h]
|
|
23
28
|
*/
|
|
24
29
|
var getBox = function getBox() {
|
|
25
30
|
var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
|
|
@@ -37,8 +42,15 @@ var getBox = function getBox() {
|
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
/**
|
|
40
|
-
* box
|
|
41
|
-
*
|
|
45
|
+
* Get bounding box from a string or array.
|
|
46
|
+
* The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
|
|
47
|
+
* The box is adjusted to ensure that x1 and y1 are non-negative.
|
|
48
|
+
* The width and height are calculated as x2 - x1 and y2 - y1 respectively.
|
|
49
|
+
* If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
|
|
50
|
+
* This is useful for ensuring that the bounding box is always within the canvas area.
|
|
51
|
+
*
|
|
52
|
+
* @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
|
|
53
|
+
* @returns canvas box [x,y,w,h]
|
|
42
54
|
*/
|
|
43
55
|
var getBoundingBox = function getBoundingBox() {
|
|
44
56
|
var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "0,0,0,0";
|
package/dist/cjs/_countries.js
CHANGED
|
@@ -26,32 +26,42 @@
|
|
|
26
26
|
/* istanbul ignore file */
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Country interface
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Country list with helper functions
|
|
34
|
+
* This is a list of all countries with their details.
|
|
35
|
+
* It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
|
|
36
|
+
* This list can be used to retrieve country information based on various codes or names.
|
|
37
|
+
* @type {Country[]}
|
|
34
38
|
*/
|
|
35
39
|
var Countries = {
|
|
36
40
|
/**
|
|
37
|
-
* Get
|
|
38
|
-
*
|
|
41
|
+
* Get ISO2 country code
|
|
42
|
+
*
|
|
43
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
44
|
+
* @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
|
|
39
45
|
*/
|
|
40
46
|
toIso2: function toIso2(code) {
|
|
41
47
|
var ctry = this.find(code);
|
|
42
48
|
return ctry != null ? ctry.iso2 : undefined;
|
|
43
49
|
},
|
|
44
50
|
/**
|
|
45
|
-
* Get
|
|
46
|
-
*
|
|
51
|
+
* Get ISO3 country code
|
|
52
|
+
*
|
|
53
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
54
|
+
* @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
|
|
47
55
|
*/
|
|
48
56
|
toIso3: function toIso3(code) {
|
|
49
57
|
var ctry = this.find(code);
|
|
50
58
|
return ctry != null ? ctry.iso3 : undefined;
|
|
51
59
|
},
|
|
52
60
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
61
|
+
* Get country emoji
|
|
62
|
+
*
|
|
63
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
64
|
+
* @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
|
|
55
65
|
*/
|
|
56
66
|
emoji: function emoji(code) {
|
|
57
67
|
var ctry = this.find(code);
|
|
@@ -59,25 +69,25 @@ var Countries = {
|
|
|
59
69
|
},
|
|
60
70
|
/**
|
|
61
71
|
* Get country name
|
|
62
|
-
*
|
|
72
|
+
*
|
|
73
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
74
|
+
* @return {string} - Returns the name of the country if found, otherwise returns the code itself.
|
|
63
75
|
*/
|
|
64
76
|
name: function name(code) {
|
|
65
77
|
var ctry = this.find(code);
|
|
66
78
|
return ctry != null ? ctry.name : code;
|
|
67
79
|
},
|
|
68
80
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @return
|
|
79
|
-
* @return phone: string;
|
|
80
|
-
* @return emoji: string;
|
|
81
|
+
* This function searches for a country in the list by its code.
|
|
82
|
+
* It supports various formats:
|
|
83
|
+
* - ISO2 code (e.g., "US")
|
|
84
|
+
* - ISO3 code (e.g., "USA")
|
|
85
|
+
* - Alternative code (e.g., "US", "USA", "United States")
|
|
86
|
+
* It returns the first matching country object or undefined if not found.
|
|
87
|
+
* This function is useful for retrieving country details based on different code formats.
|
|
88
|
+
*
|
|
89
|
+
* @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
|
|
90
|
+
* @return {Country | undefined} - Returns the country object if found, otherwise undefined.
|
|
81
91
|
*/
|
|
82
92
|
find: function find(code) {
|
|
83
93
|
return this.list.find(function (ct) {
|
|
@@ -85,6 +95,14 @@ var Countries = {
|
|
|
85
95
|
return ((_ct$alt = ct.alt) !== null && _ct$alt !== void 0 ? _ct$alt : "__").toLowerCase() === code.toLowerCase() || ct.iso3.toLowerCase() === code.toLowerCase() || ct.iso2.toLowerCase() === code.toLowerCase();
|
|
86
96
|
});
|
|
87
97
|
},
|
|
98
|
+
/**
|
|
99
|
+
* Country list
|
|
100
|
+
* This is a list of all countries with their details.
|
|
101
|
+
* It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
|
|
102
|
+
* This list can be used to retrieve country information based on various codes or names.
|
|
103
|
+
*
|
|
104
|
+
* @type {Country[]}
|
|
105
|
+
*/
|
|
88
106
|
list: [{
|
|
89
107
|
continent: "Asia",
|
|
90
108
|
iso2: "AF",
|
package/dist/cjs/_debounce.js
CHANGED
|
@@ -26,8 +26,14 @@
|
|
|
26
26
|
/* istanbul ignore file */
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Debounce function to limit the rate at which a function can fire.
|
|
30
|
+
* It will delay the execution of the function until after a specified timeout
|
|
31
|
+
* has elapsed since the last time the function was invoked.
|
|
32
|
+
*
|
|
33
|
+
* @param fn - The function to debounce.
|
|
34
|
+
* @param timeout - The number of milliseconds to wait before invoking the function.
|
|
35
|
+
* @returns A debounced version of the function that can be called with any arguments.
|
|
36
|
+
* The debounced function also has a `cancel` method to clear the timeout.
|
|
31
37
|
*/
|
|
32
38
|
var debounce = function debounce(fn) {
|
|
33
39
|
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
package/dist/cjs/_dedupe.js
CHANGED
|
@@ -25,6 +25,18 @@ var _isType = require('./_isType.js');
|
|
|
25
25
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Remove duplicates from a list of objects based on a key or the entire object.
|
|
31
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
32
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
33
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
34
|
+
*
|
|
35
|
+
* @param list
|
|
36
|
+
* @param key
|
|
37
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
38
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
39
|
+
*/
|
|
28
40
|
var dedupe = function dedupe(list, key) {
|
|
29
41
|
var filtered = list.filter(function (i) {
|
|
30
42
|
return !_isType.isEmpty(i);
|
|
@@ -33,20 +45,54 @@ var dedupe = function dedupe(list, key) {
|
|
|
33
45
|
return Array.from(new Set(filtered).values());
|
|
34
46
|
}
|
|
35
47
|
return Array.from(new Map(filtered.map(function (obj) {
|
|
36
|
-
|
|
37
|
-
return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
|
|
48
|
+
return [obj[key], obj];
|
|
38
49
|
})).values());
|
|
39
50
|
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Flatten a list of objects, removing any empty objects.
|
|
54
|
+
* It will flatten up to 5 levels deep and filter out any empty objects.
|
|
55
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
56
|
+
*
|
|
57
|
+
* @param list
|
|
58
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
59
|
+
* @returns {T[]} - A flattened array of objects.
|
|
60
|
+
*/
|
|
40
61
|
var flatten = function flatten(list) {
|
|
41
62
|
return list.flat(5).filter(function (i) {
|
|
42
63
|
return !_isType.isEmpty(i);
|
|
43
64
|
});
|
|
44
65
|
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Flatten a list of objects and remove duplicates based on a key or the entire object.
|
|
69
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
70
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
71
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
72
|
+
* Flattening is done first, followed by deduplication.
|
|
73
|
+
*
|
|
74
|
+
* @param list
|
|
75
|
+
* @param key
|
|
76
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
77
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
78
|
+
*/
|
|
45
79
|
var flattenAndDedupe = function flattenAndDedupe() {
|
|
46
80
|
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
47
81
|
var key = arguments.length > 1 ? arguments[1] : undefined;
|
|
48
82
|
return dedupe(flatten(list), key);
|
|
49
83
|
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Group a list of objects by a specific property.
|
|
87
|
+
* If the property is not present in an object, it will use the `missingKey` value as the key.
|
|
88
|
+
* This is useful for organizing data into categories based on a specific property.
|
|
89
|
+
*
|
|
90
|
+
* @param list
|
|
91
|
+
* @param prop
|
|
92
|
+
* @param missingKey
|
|
93
|
+
* @typedef {T} KeyValue - A generic type representing list items with key-value pairs.
|
|
94
|
+
* @returns {KeyValue<T[]>} - An object mapping keys to arrays of items.
|
|
95
|
+
*/
|
|
50
96
|
var groupBy = function groupBy(list, prop, missingKey) {
|
|
51
97
|
return list.reduce(function (r, i) {
|
|
52
98
|
var _i$prop;
|
package/dist/cjs/_fetch.js
CHANGED
|
@@ -10,13 +10,18 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
10
10
|
var _signals = new Map();
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Fetch
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
13
|
+
* Fetch utility function to make HTTP requests.
|
|
14
|
+
* It supports GET, POST, PUT, and DELETE methods.
|
|
15
|
+
* It automatically handles JSON responses and error codes.
|
|
16
|
+
* It also supports aborting requests using an AbortController.
|
|
17
|
+
*
|
|
18
|
+
* @param method - The HTTP method to use (GET, POST, PUT, DELETE).
|
|
19
|
+
* @param url - The URL to send the request to.
|
|
20
|
+
* @param options.headers - Headers to include in the request.
|
|
21
|
+
* @param options.body - The body of the request (for POST and PUT requests).
|
|
22
|
+
* @param options.signal - An AbortSignal to cancel the request.
|
|
23
|
+
* @returns A promise that resolves to the JSON response from the server.
|
|
24
|
+
* @throws An error if the request fails or if the response contains an error code.
|
|
20
25
|
*/
|
|
21
26
|
var _fetch = /*#__PURE__*/function () {
|
|
22
27
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(method, url, _ref) {
|
package/dist/cjs/_fileType.js
CHANGED
|
@@ -27,7 +27,20 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
|
27
27
|
|
|
28
28
|
/* istanbul ignore file */
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* File type utility to get the file type from a MIME type.
|
|
32
|
+
* This utility provides a mapping of common MIME types to their human-readable names.
|
|
33
|
+
* It can be used to display file types in a user-friendly manner.
|
|
34
|
+
*/
|
|
30
35
|
var _fileType = {
|
|
36
|
+
/**
|
|
37
|
+
* Get the human-readable file type from a MIME type.
|
|
38
|
+
* This method looks up the MIME type in a predefined list
|
|
39
|
+
* and returns a user-friendly name.
|
|
40
|
+
*
|
|
41
|
+
* @param mime MIME type string, e.g. "application/pdf"
|
|
42
|
+
* @returns {string} - The human-readable file type.
|
|
43
|
+
*/
|
|
31
44
|
mime: function mime() {
|
|
32
45
|
var mime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
33
46
|
var ret = this.mimeList[mime.split(";")[0]];
|
|
@@ -40,6 +53,9 @@ var _fileType = {
|
|
|
40
53
|
}
|
|
41
54
|
return ret || "Unknown type";
|
|
42
55
|
},
|
|
56
|
+
/**
|
|
57
|
+
* List of common MIME types and their human-readable names.
|
|
58
|
+
*/
|
|
43
59
|
mimeList: {
|
|
44
60
|
"application/x-tika-msoffice": "Microsft Office File",
|
|
45
61
|
"application/x-tika-ooxml": "Open Office File",
|
package/dist/cjs/_format.js
CHANGED
|
@@ -30,10 +30,13 @@ var _isType = require('./_isType.js');
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Format utility functions for various data types.
|
|
35
|
+
* This namespace provides methods to format phone numbers, numbers, bytes, percentages, dates, and durations.
|
|
36
|
+
*/
|
|
33
37
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
34
38
|
exports.Format = void 0;
|
|
35
39
|
(function (_Format) {
|
|
36
|
-
/** ***************** get phone number object using `libphonenumber-js` *******************/
|
|
37
40
|
var getPhone = function getPhone(value, country) {
|
|
38
41
|
var phone = value.match(/^[0+]/) != null ? value.replace(/^00/, "+") : "+".concat(value);
|
|
39
42
|
var number = libphonenumberJs.parsePhoneNumberFromString(phone, country);
|
|
@@ -45,8 +48,6 @@ exports.Format = void 0;
|
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
|
-
|
|
49
|
-
/** ***************** common number format method using `numeral` *******************/
|
|
50
51
|
var numberFormat = function numberFormat(number) {
|
|
51
52
|
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "0,0[.]00a";
|
|
52
53
|
if (_isType.isNil(number)) {
|
|
@@ -66,7 +67,19 @@ exports.Format = void 0;
|
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Format phone number with country flag or emoji.
|
|
72
|
+
* It takes a phone number string, a country code, and a boolean to indicate whether to use CSS classes for flags.
|
|
73
|
+
* If the phone number is empty, less than 6 characters, or does not match the regex for valid phone numbers,
|
|
74
|
+
* it returns the original value.
|
|
75
|
+
* If the phone number is valid, it formats the phone number using `libphonenumber-js` and returns it with the country flag or emoji.
|
|
76
|
+
* The country flag is represented as a CSS class, and the emoji is obtained from the `Countries` module.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} value - The phone number to format.
|
|
79
|
+
* @param {string} country - The country code to use for formatting.
|
|
80
|
+
* @param {boolean} useCss - Whether to use CSS classes for flags.
|
|
81
|
+
* @returns {string} The formatted phone number with country flag or emoji.
|
|
82
|
+
*/
|
|
70
83
|
_Format.phone = function (value) {
|
|
71
84
|
var _phone$country;
|
|
72
85
|
var country = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "AE";
|
|
@@ -86,8 +99,8 @@ exports.Format = void 0;
|
|
|
86
99
|
return numberFormat(number, "0,0[.]00%");
|
|
87
100
|
};
|
|
88
101
|
_Format.date = function (date) {
|
|
89
|
-
var
|
|
90
|
-
return date ? dateFns.format(new Date(date),
|
|
102
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "d-M-y";
|
|
103
|
+
return date ? dateFns.format(new Date(date), format) : "";
|
|
91
104
|
};
|
|
92
105
|
_Format.duration = function (number, isFraction) {
|
|
93
106
|
if (_isType.isNil(number)) {
|
package/dist/cjs/_getByPath.js
CHANGED
|
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
|
|
|
36
36
|
if (_isType.isNil(field)) {
|
|
37
37
|
return hit;
|
|
38
38
|
}
|
|
39
|
-
if (_isType.isObject(hit)) {
|
|
39
|
+
if (_isType.isObject(hit) || _isType.isArray(hit)) {
|
|
40
40
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
41
|
if (!_isType.isNil(hit[field])) {
|
|
42
42
|
return hit[field];
|
|
@@ -92,8 +92,14 @@ var _get = function _get(hit, field) {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
95
|
+
* Get a value from an object by a given path.
|
|
96
|
+
* This function allows you to retrieve a value from a nested object structure using a dot-separated path.
|
|
97
|
+
* If the path does not exist or the object is empty, it returns a default value.
|
|
98
|
+
* @param {KeyValue} obj - The object from which to retrieve the value.
|
|
99
|
+
* @param {string} path - The dot-separated path to the value within the object.
|
|
100
|
+
* @param {any} defaultValue - The value to return if the path does not exist or the object is empty.
|
|
101
|
+
* @typedef {T} AnyObject - The type of the value to be returned.
|
|
102
|
+
* @returns {T} The value at the specified path, or the default value if the path does not exist.
|
|
97
103
|
*/
|
|
98
104
|
var getByPath = function getByPath(obj, path) {
|
|
99
105
|
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
@@ -109,8 +115,13 @@ var getByPath = function getByPath(obj, path) {
|
|
|
109
115
|
};
|
|
110
116
|
|
|
111
117
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
118
|
+
* Get the first non-empty value from the provided arguments.
|
|
119
|
+
* This function is useful for finding a default value or fallback when multiple values are provided.
|
|
120
|
+
* It checks each argument in order and returns the first one that is not empty.
|
|
121
|
+
* If all arguments are empty, it returns `undefined`.
|
|
122
|
+
*
|
|
123
|
+
* @param {...any} args - The values to check for non-emptiness.
|
|
124
|
+
* @returns {any} The first non-empty value, or `undefined` if all are empty.
|
|
114
125
|
*/
|
|
115
126
|
var getValue = function getValue() {
|
|
116
127
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
package/dist/cjs/_hash.js
CHANGED
|
@@ -27,9 +27,11 @@ var _isType = require('./_isType.js');
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Generate a hash from a string.
|
|
31
|
+
* This function computes a simple hash by iterating over each character in the string,
|
|
32
|
+
* performing bitwise operations to produce a 32-bit integer hash.
|
|
31
33
|
* @param str
|
|
32
|
-
* @
|
|
34
|
+
* @returns {number} A 32-bit integer hash of the input string.
|
|
33
35
|
*/
|
|
34
36
|
var hash = function hash(str) {
|
|
35
37
|
var hash = 0;
|
|
@@ -45,16 +47,20 @@ var hash = function hash(str) {
|
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
+
* Generate a short hash using the current timestamp and a random number.
|
|
51
|
+
* This function creates a unique identifier by combining the current time in milliseconds
|
|
52
|
+
* with a random number, and then converting it to a base-36 string.
|
|
53
|
+
* @returns {string} A short hash string.
|
|
50
54
|
*/
|
|
51
55
|
var shortHash = function shortHash() {
|
|
52
|
-
return (new Date().getTime()
|
|
56
|
+
return (new Date().getTime() * Math.random()).toString(36);
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
60
|
+
* Generate a UUID (Universally Unique Identifier).
|
|
61
|
+
* This function creates a version 4 UUID by generating random numbers
|
|
62
|
+
* and formatting them according to the UUID standard.
|
|
63
|
+
* @returns {string} A UUID string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
|
|
58
64
|
*/
|
|
59
65
|
var uuid = function uuid() {
|
|
60
66
|
return [1e7, 1e3, 4e3, 8e3, 1e11].join("-").replace(/[018]/g, function (c) {
|
package/dist/cjs/_interpolate.js
CHANGED
|
@@ -27,8 +27,13 @@ var _getByPath = require('./_getByPath.js');
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* Interpolate a string with values from a model.
|
|
31
|
+
* This function replaces placeholders in the format ${key} with corresponding values from the model object.
|
|
32
|
+
* If the value is not a string or number, it returns an empty string.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} str - The string to interpolate.
|
|
35
|
+
* @param {KeyValue} model - The model object containing key-value pairs for interpolation.
|
|
36
|
+
* @returns {string} The interpolated string with placeholders replaced by values from the model.
|
|
32
37
|
*/
|
|
33
38
|
var interpolate = function interpolate(str, model) {
|
|
34
39
|
return str.replace(/\${([^{}]*)}/g, function (a, b) {
|
|
@@ -36,6 +41,17 @@ var interpolate = function interpolate(str, model) {
|
|
|
36
41
|
return typeof r === "string" || typeof r === "number" ? "".concat(r) : "";
|
|
37
42
|
});
|
|
38
43
|
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Render a template string with values from a model.
|
|
47
|
+
* This function replaces placeholders in the format {{key}} with corresponding values from the model object.
|
|
48
|
+
* If the value is not a string or number, it returns an empty string.
|
|
49
|
+
* This is similar to the interpolate function but for handlebar templates.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} str - The template string to render.
|
|
52
|
+
* @param {KeyValue} model - The model object containing key-value pairs for rendering the template.
|
|
53
|
+
* @returns {string} The rendered template string with placeholders replaced by values from the model.
|
|
54
|
+
*/
|
|
39
55
|
var renderTemplate = function renderTemplate(str, model) {
|
|
40
56
|
return str.replace(/{{([^{}]*)}}/g, function (a, b) {
|
|
41
57
|
var r = _getByPath.getByPath(model, b);
|
package/dist/cjs/_isEqual.js
CHANGED
|
@@ -28,10 +28,23 @@ var _isType = require('./_isType.js');
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Compare two objects or values for equality.
|
|
32
|
+
* This function checks if two values are equal, including nested objects and arrays.
|
|
33
|
+
* It handles various data types such as strings, numbers, booleans, arrays, and objects.
|
|
34
|
+
* If both values are `null` or `undefined`, they are considered equal.
|
|
35
|
+
* If both values are primitive types (string, number, boolean), they are compared directly.
|
|
36
|
+
* If both values are arrays, they are compared element by element.
|
|
37
|
+
* If both values are objects, they are compared by their keys and values.
|
|
38
|
+
* If the values are of different types or structures, they are considered not equal.
|
|
39
|
+
*
|
|
40
|
+
* @param {unknown} obj - The first value to compare.
|
|
41
|
+
* @param {unknown} test - The second value to compare against the first.
|
|
42
|
+
* @returns {boolean} - Returns true if the values are equal, false otherwise.
|
|
33
43
|
*/
|
|
34
44
|
var isEqual = function isEqual(obj, test) {
|
|
45
|
+
if (_isType.isNil(obj) && _isType.isNil(test)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
35
48
|
if (_isType.isString(obj) || _isType.isNumber(obj) || _isType.isBoolean(obj)) {
|
|
36
49
|
return obj === test;
|
|
37
50
|
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
@@ -65,8 +78,20 @@ var isEqual = function isEqual(obj, test) {
|
|
|
65
78
|
};
|
|
66
79
|
|
|
67
80
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
81
|
+
* Match a string against another string with options for equality.
|
|
82
|
+
* This function checks if the base string starts with, includes, or is equal to the match string,
|
|
83
|
+
* based on the specified equality condition.
|
|
84
|
+
* It normalizes both strings to lowercase and ASCII format before comparison.
|
|
85
|
+
* This is useful for case-insensitive and ASCII-only comparisons,
|
|
86
|
+
* such as when filtering or searching through text data.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} base - The base string to match against.
|
|
89
|
+
* @param {string} match - The string to match with the base string.
|
|
90
|
+
* @param {("start" | boolean)} equality - The type of match to perform:
|
|
91
|
+
* - "start": checks if the base string starts with the match string.
|
|
92
|
+
* - true: checks for exact equality.
|
|
93
|
+
* - false (default): checks if the base string includes the match string.
|
|
94
|
+
* @returns {boolean} - Returns true if the base string matches the conditions specified by the match string and equality.
|
|
70
95
|
*/
|
|
71
96
|
var matchString = function matchString(base, match) {
|
|
72
97
|
var equality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -76,8 +101,17 @@ var matchString = function matchString(base, match) {
|
|
|
76
101
|
};
|
|
77
102
|
|
|
78
103
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
104
|
+
* Compare two values for sorting.
|
|
105
|
+
* This function compares two values based on the specified order (ascending or descending).
|
|
106
|
+
* If a key is provided, it compares the values of that key in the objects.
|
|
107
|
+
* It handles various data types such as strings, numbers, booleans, and objects.
|
|
108
|
+
* It returns a comparison function that can be used with array sorting methods.
|
|
109
|
+
* * The comparison is done in a case-insensitive manner for strings,
|
|
110
|
+
* treating special characters as their ASCII equivalents.
|
|
111
|
+
*
|
|
112
|
+
* @param {("asc" | "desc")} order - The order of comparison, either "asc" for ascending or "desc" for descending.
|
|
113
|
+
* @param {string} key - An optional key to compare values within objects.
|
|
114
|
+
* @returns {Function} A comparison function that can be used with array sorting methods.
|
|
81
115
|
*/
|
|
82
116
|
var compareValues = function compareValues() {
|
|
83
117
|
var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "asc";
|