@react-fabric/utilities 1.0.0-beta.8 → 1.0.1
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/css/boundingBox.js +72 -0
- package/dist/cjs/css/cn.js +39 -0
- package/dist/cjs/css/imageColorset.js +96 -0
- package/dist/cjs/data/countries.js +98 -0
- package/dist/cjs/{_fileType.js → data/fileType.js} +37 -19
- package/dist/cjs/data/format.js +136 -0
- package/dist/cjs/helpers/debounce.js +63 -0
- package/dist/cjs/{useLogger.js → helpers/getLogger.js} +96 -96
- package/dist/cjs/helpers/lonlat.js +99 -0
- package/dist/cjs/index.js +99 -76
- package/dist/cjs/lists/dedupe.js +54 -0
- package/dist/cjs/lists/flatten.js +66 -0
- package/dist/cjs/{_getByPath.js → lists/getByPath.js} +58 -37
- package/dist/cjs/lists/groupBy.js +49 -0
- package/dist/cjs/matchers/compare.js +70 -0
- package/dist/cjs/matchers/isEmpty.js +34 -0
- package/dist/cjs/matchers/isEqual.js +82 -0
- package/dist/cjs/matchers/nullChecks.js +61 -0
- package/dist/cjs/matchers/typeChecks.js +127 -0
- package/dist/cjs/strings/ascii.js +105 -0
- package/dist/cjs/strings/hash.js +75 -0
- package/dist/cjs/strings/interpolate.js +47 -0
- package/dist/cjs/strings/matchString.js +54 -0
- package/dist/cjs/strings/template.js +48 -0
- package/dist/cjs/strings/tokenize.js +83 -0
- package/dist/cjs/utils/mergeRefs.js +56 -0
- package/dist/esm/css/boundingBox.js +71 -0
- package/dist/esm/css/cn.js +39 -0
- package/dist/esm/css/imageColorset.js +96 -0
- package/dist/esm/data/countries.js +98 -0
- package/dist/esm/{_fileType.js → data/fileType.js} +37 -19
- package/dist/esm/data/format.js +138 -0
- package/dist/esm/helpers/debounce.js +63 -0
- package/dist/esm/{useLogger.js → helpers/getLogger.js} +96 -96
- package/dist/esm/helpers/lonlat.js +97 -0
- package/dist/esm/index.js +54 -36
- package/dist/esm/lists/dedupe.js +54 -0
- package/dist/esm/lists/flatten.js +65 -0
- package/dist/esm/{_getByPath.js → lists/getByPath.js} +50 -29
- package/dist/esm/lists/groupBy.js +49 -0
- package/dist/esm/matchers/compare.js +70 -0
- package/dist/esm/matchers/isEmpty.js +34 -0
- package/dist/esm/matchers/isEqual.js +82 -0
- package/dist/esm/matchers/nullChecks.js +58 -0
- package/dist/esm/matchers/typeChecks.js +119 -0
- package/dist/esm/strings/ascii.js +105 -0
- package/dist/esm/strings/hash.js +73 -0
- package/dist/esm/strings/interpolate.js +47 -0
- package/dist/esm/strings/matchString.js +54 -0
- package/dist/esm/strings/template.js +48 -0
- package/dist/esm/strings/tokenize.js +82 -0
- package/dist/esm/utils/mergeRefs.js +56 -0
- package/dist/types/css/boundingBox.d.ts +46 -0
- package/dist/types/css/cn.d.ts +26 -0
- package/dist/types/css/imageColorset.d.ts +37 -0
- package/dist/types/data/countries.d.ts +136 -0
- package/dist/types/{_fileType.d.ts → data/fileType.d.ts} +41 -1
- package/dist/types/data/format.d.ts +122 -0
- package/dist/types/helpers/debounce.d.ts +38 -0
- package/dist/types/helpers/getLogger.d.ts +49 -0
- package/dist/types/helpers/lonlat.d.ts +48 -0
- package/dist/types/index.d.ts +54 -20
- package/dist/types/lists/dedupe.d.ts +36 -0
- package/dist/types/lists/flatten.d.ts +47 -0
- package/dist/types/lists/getByPath.d.ts +45 -0
- package/dist/types/lists/groupBy.d.ts +36 -0
- package/dist/types/matchers/compare.d.ts +38 -0
- package/dist/types/matchers/isEmpty.d.ts +38 -0
- package/dist/types/matchers/isEqual.d.ts +39 -0
- package/dist/types/matchers/nullChecks.d.ts +43 -0
- package/dist/types/matchers/typeChecks.d.ts +107 -0
- package/dist/types/strings/ascii.d.ts +34 -0
- package/dist/types/strings/hash.d.ts +46 -0
- package/dist/types/strings/interpolate.d.ts +34 -0
- package/dist/types/strings/matchString.d.ts +41 -0
- package/dist/types/strings/template.d.ts +35 -0
- package/dist/types/strings/tokenize.d.ts +44 -0
- package/dist/types/utils/mergeRefs.d.ts +36 -0
- package/package.json +13 -11
- package/src/css/boundingBox.ts +80 -0
- package/src/css/cn.ts +32 -0
- package/src/css/imageColorset.ts +97 -0
- package/src/data/countries.ts +126 -0
- package/src/{_fileType.ts → data/fileType.ts} +72 -89
- package/src/data/format.ts +192 -0
- package/src/helpers/debounce.ts +49 -0
- package/src/{useLogger.ts → helpers/getLogger.ts} +52 -101
- package/src/helpers/lonlat.ts +124 -0
- package/src/index.ts +57 -37
- package/src/lists/dedupe.ts +46 -0
- package/src/lists/flatten.ts +56 -0
- package/src/lists/getByPath.ts +122 -0
- package/src/lists/groupBy.ts +47 -0
- package/src/matchers/compare.ts +64 -0
- package/src/matchers/isEmpty.ts +54 -0
- package/src/matchers/isEqual.ts +71 -0
- package/src/matchers/nullChecks.ts +55 -0
- package/src/matchers/typeChecks.ts +146 -0
- package/src/strings/ascii.ts +100 -0
- package/src/strings/hash.ts +68 -0
- package/src/strings/interpolate.ts +42 -0
- package/src/strings/matchString.ts +49 -0
- package/src/strings/template.ts +43 -0
- package/src/strings/tokenize.ts +77 -0
- package/src/utils/mergeRefs.ts +47 -0
- package/src/{yup.ts → utils/yup.ts} +3 -3
- package/dist/cjs/_ascii.js +0 -76
- package/dist/cjs/_boundingBox.js +0 -59
- package/dist/cjs/_countries.js +0 -2805
- package/dist/cjs/_debounce.js +0 -53
- package/dist/cjs/_dedupe.js +0 -63
- package/dist/cjs/_fetch.js +0 -128
- package/dist/cjs/_format.js +0 -118
- package/dist/cjs/_hash.js +0 -67
- package/dist/cjs/_interpolate.js +0 -47
- package/dist/cjs/_isEqual.js +0 -108
- package/dist/cjs/_isType.js +0 -98
- package/dist/cjs/_mergeRefs.js +0 -40
- package/dist/cjs/_tokenize.js +0 -67
- package/dist/cjs/getImageColorset.js +0 -70
- package/dist/esm/_ascii.js +0 -76
- package/dist/esm/_boundingBox.js +0 -58
- package/dist/esm/_countries.js +0 -2805
- package/dist/esm/_debounce.js +0 -53
- package/dist/esm/_dedupe.js +0 -60
- package/dist/esm/_fetch.js +0 -128
- package/dist/esm/_format.js +0 -120
- package/dist/esm/_hash.js +0 -65
- package/dist/esm/_interpolate.js +0 -46
- package/dist/esm/_isEqual.js +0 -106
- package/dist/esm/_isType.js +0 -85
- package/dist/esm/_mergeRefs.js +0 -40
- package/dist/esm/_tokenize.js +0 -66
- package/dist/esm/getImageColorset.js +0 -70
- package/dist/types/_ascii.d.ts +0 -5
- package/dist/types/_boundingBox.d.ts +0 -10
- package/dist/types/_countries.d.ts +0 -85
- package/dist/types/_debounce.d.ts +0 -8
- package/dist/types/_dedupe.d.ts +0 -4
- package/dist/types/_fetch.d.ts +0 -23
- package/dist/types/_format.d.ts +0 -27
- package/dist/types/_getByPath.d.ts +0 -10
- package/dist/types/_hash.d.ts +0 -16
- package/dist/types/_interpolate.d.ts +0 -6
- package/dist/types/_isEqual.d.ts +0 -15
- package/dist/types/_isType.d.ts +0 -14
- package/dist/types/_mergeRefs.d.ts +0 -1
- package/dist/types/_tokenize.d.ts +0 -8
- package/dist/types/getImageColorset.d.ts +0 -1
- package/dist/types/useLogger.d.ts +0 -25
- package/src/_ascii.ts +0 -93
- package/src/_boundingBox.ts +0 -72
- package/src/_countries.ts +0 -3046
- package/src/_debounce.ts +0 -42
- package/src/_dedupe.ts +0 -56
- package/src/_fetch.ts +0 -109
- package/src/_format.ts +0 -141
- package/src/_getByPath.ts +0 -108
- package/src/_hash.ts +0 -62
- package/src/_interpolate.ts +0 -42
- package/src/_isEqual.ts +0 -102
- package/src/_isType.ts +0 -105
- package/src/_mergeRefs.ts +0 -33
- package/src/_tokenize.ts +0 -69
- package/src/getImageColorset.ts +0 -81
- /package/dist/cjs/{yup.js → utils/yup.js} +0 -0
- /package/dist/esm/{yup.js → utils/yup.js} +0 -0
- /package/dist/types/{yup.d.ts → utils/yup.d.ts} +0 -0
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { isEmpty
|
|
3
|
+
import { isEmpty } from '../matchers/isEmpty.js';
|
|
4
|
+
import { isNil } from '../matchers/nullChecks.js';
|
|
5
|
+
import { isObject, isArray } from '../matchers/typeChecks.js';
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
/**
|
|
6
8
|
* React Fabric
|
|
7
|
-
* @version
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* The MIT License (MIT)
|
|
11
|
-
* Copyright (c) 2024 Adarsh Pastakia
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
* @license MIT
|
|
11
|
+
* @copyright 2024 Adarsh Pastakia
|
|
12
12
|
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* and associated documentation files (the "Software"), to deal
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
18
19
|
*
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
-
* portions of the Software.
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
21
22
|
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
-
* TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
|
|
33
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
34
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
35
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
36
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
37
|
+
|
|
38
|
+
function _get(hit, field) {
|
|
29
39
|
/** ***************** return if object is empty *******************/
|
|
30
40
|
/* istanbul ignore next */
|
|
31
41
|
if (isNil(hit)) {
|
|
@@ -36,7 +46,7 @@ var _get = function _get(hit, field) {
|
|
|
36
46
|
if (isNil(field)) {
|
|
37
47
|
return hit;
|
|
38
48
|
}
|
|
39
|
-
if (isObject(hit)) {
|
|
49
|
+
if (isObject(hit) || isArray(hit)) {
|
|
40
50
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
51
|
if (!isNil(hit[field])) {
|
|
42
52
|
return hit[field];
|
|
@@ -89,13 +99,19 @@ var _get = function _get(hit, field) {
|
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
return undefined;
|
|
92
|
-
}
|
|
102
|
+
}
|
|
93
103
|
|
|
94
104
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
105
|
+
* Get a value from an object by a given path.
|
|
106
|
+
* This function allows you to retrieve a value from a nested object structure using a dot-separated path.
|
|
107
|
+
* If the path does not exist or the object is empty, it returns a default value.
|
|
108
|
+
* @param {KeyValue} obj - The object from which to retrieve the value.
|
|
109
|
+
* @param {string} path - The dot-separated path to the value within the object.
|
|
110
|
+
* @param {any} defaultValue - The value to return if the path does not exist or the object is empty.
|
|
111
|
+
* @typedef {T} AnyObject - The type of the value to be returned.
|
|
112
|
+
* @returns {T} The value at the specified path, or the default value if the path does not exist.
|
|
97
113
|
*/
|
|
98
|
-
|
|
114
|
+
function getByPath(obj, path) {
|
|
99
115
|
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
100
116
|
/** ***************** if empty object/path return defaultValue *******************/
|
|
101
117
|
if (isEmpty(obj) || isEmpty(path)) {
|
|
@@ -106,19 +122,24 @@ var getByPath = function getByPath(obj, path) {
|
|
|
106
122
|
return value;
|
|
107
123
|
}
|
|
108
124
|
return defaultValue;
|
|
109
|
-
}
|
|
125
|
+
}
|
|
110
126
|
|
|
111
127
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
128
|
+
* Get the first non-empty value from the provided arguments.
|
|
129
|
+
* This function is useful for finding a default value or fallback when multiple values are provided.
|
|
130
|
+
* It checks each argument in order and returns the first one that is not empty.
|
|
131
|
+
* If all arguments are empty, it returns `undefined`.
|
|
132
|
+
*
|
|
133
|
+
* @param {...any} args - The values to check for non-emptiness.
|
|
134
|
+
* @returns {any} The first non-empty value, or `undefined` if all are empty.
|
|
114
135
|
*/
|
|
115
|
-
|
|
136
|
+
function getValue() {
|
|
116
137
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
117
138
|
args[_key] = arguments[_key];
|
|
118
139
|
}
|
|
119
140
|
return args.find(function (a) {
|
|
120
141
|
return !isEmpty(a);
|
|
121
142
|
});
|
|
122
|
-
}
|
|
143
|
+
}
|
|
123
144
|
|
|
124
145
|
export { getByPath, getValue };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @copyright 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Group a list of objects by a specific property.
|
|
30
|
+
* If the property is not present in an object, it will use the `missingKey` value as the key.
|
|
31
|
+
* This is useful for organizing data into categories based on a specific property.
|
|
32
|
+
*
|
|
33
|
+
* @param list
|
|
34
|
+
* @param prop
|
|
35
|
+
* @param missingKey
|
|
36
|
+
* @typedef {T} KeyValue - A generic type representing list items with key-value pairs.
|
|
37
|
+
* @returns {KeyValue<T[]>} - An object mapping keys to arrays of items.
|
|
38
|
+
*/
|
|
39
|
+
function groupBy(list, prop, missingKey) {
|
|
40
|
+
return list.reduce(function (r, i) {
|
|
41
|
+
var _ref;
|
|
42
|
+
var key = (_ref = i[prop]) !== null && _ref !== void 0 ? _ref : missingKey;
|
|
43
|
+
if (!r[key]) r[key] = [];
|
|
44
|
+
r[key].push(i);
|
|
45
|
+
return r;
|
|
46
|
+
}, {});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { groupBy };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { getByPath } from '../lists/getByPath.js';
|
|
4
|
+
import { ascii } from '../strings/ascii.js';
|
|
5
|
+
import { isObject, isNumber, isBoolean } from './typeChecks.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* React Fabric
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
* @license MIT
|
|
11
|
+
* @copyright 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
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.
|
|
45
|
+
*/
|
|
46
|
+
function compareValues() {
|
|
47
|
+
var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "asc";
|
|
48
|
+
var key = arguments.length > 1 ? arguments[1] : undefined;
|
|
49
|
+
return function (a, b) {
|
|
50
|
+
var aValue = key && isObject(a) ? getByPath(a, key, "") : a;
|
|
51
|
+
var bValue = key && isObject(b) ? getByPath(b, key, "") : b;
|
|
52
|
+
var bigger = order === "asc" ? 1 : -1;
|
|
53
|
+
var smaller = order === "desc" ? 1 : -1;
|
|
54
|
+
// return 0 when equal, allowing for multiple sorting properties
|
|
55
|
+
if (aValue === bValue) return 0;
|
|
56
|
+
// if numbers check greater
|
|
57
|
+
if (isNumber(aValue) && isNumber(bValue)) {
|
|
58
|
+
return aValue > bValue ? bigger : smaller;
|
|
59
|
+
}
|
|
60
|
+
// if boolean sort true first
|
|
61
|
+
if (isBoolean(aValue) && isBoolean(bValue)) {
|
|
62
|
+
return aValue ? smaller : bigger;
|
|
63
|
+
}
|
|
64
|
+
var _a = ascii(aValue).toLowerCase();
|
|
65
|
+
var _b = ascii(bValue).toLowerCase();
|
|
66
|
+
return _a.localeCompare(_b) === 1 ? bigger : smaller;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { compareValues };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
4
|
+
import { isNil, isDefined } from './nullChecks.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if a value is empty.
|
|
8
|
+
* A value is considered empty if it is:
|
|
9
|
+
* - undefined
|
|
10
|
+
* - null
|
|
11
|
+
* - an empty string
|
|
12
|
+
* - an empty array
|
|
13
|
+
* - an empty object
|
|
14
|
+
* - an empty Map or Set
|
|
15
|
+
* - a boolean, number, or bigint (not empty)
|
|
16
|
+
* @param val - The value to check.
|
|
17
|
+
* @returns true if the value is empty, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
function isEmpty(val) {
|
|
20
|
+
if (val instanceof Date) return false;
|
|
21
|
+
if (isNil(val) || val === "") {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(val) && val.filter(isDefined).length === 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
|
28
|
+
if (["boolean", "number", "bigint", "function"].includes(_typeof(val))) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return !!val && _typeof(val) === "object" && Object.entries(val).length === 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { isEmpty };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { isNil } from './nullChecks.js';
|
|
4
|
+
import { isString, isNumber, isBoolean, isObject } from './typeChecks.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React Fabric
|
|
8
|
+
* @version 1.0.0
|
|
9
|
+
* @license MIT
|
|
10
|
+
* @copyright 2024 Adarsh Pastakia
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Compare two objects or values for equality.
|
|
34
|
+
* This function checks if two values are equal, including nested objects and arrays.
|
|
35
|
+
* It handles various data types such as strings, numbers, booleans, arrays, and objects.
|
|
36
|
+
* If both values are `null` or `undefined`, they are considered equal.
|
|
37
|
+
* If both values are primitive types (string, number, boolean), they are compared directly.
|
|
38
|
+
* If both values are arrays, they are compared element by element.
|
|
39
|
+
* If both values are objects, they are compared by their keys and values.
|
|
40
|
+
* If the values are of different types or structures, they are considered not equal.
|
|
41
|
+
*
|
|
42
|
+
* @param {unknown} obj - The first value to compare.
|
|
43
|
+
* @param {unknown} test - The second value to compare against the first.
|
|
44
|
+
* @returns {boolean} - Returns true if the values are equal, false otherwise.
|
|
45
|
+
*/
|
|
46
|
+
function isEqual(obj, test) {
|
|
47
|
+
if (isNil(obj) && isNil(test)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (isString(obj) || isNumber(obj) || isBoolean(obj)) {
|
|
51
|
+
return obj === test;
|
|
52
|
+
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
53
|
+
// if length dont match return false
|
|
54
|
+
if (obj.length !== test.length) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// check if some value is false
|
|
58
|
+
return !obj.some(function (o, i) {
|
|
59
|
+
return !isEqual(o, test[i]);
|
|
60
|
+
});
|
|
61
|
+
} else if (isObject(obj) && isObject(test)) {
|
|
62
|
+
var okeys = Object.keys(obj);
|
|
63
|
+
var tkeys = Object.keys(test);
|
|
64
|
+
// if keys length dont match return false
|
|
65
|
+
if (okeys.length !== tkeys.length) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// if keys dont match return false
|
|
69
|
+
if (okeys.some(function (k) {
|
|
70
|
+
return !tkeys.includes(k);
|
|
71
|
+
})) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// check if some value is false
|
|
75
|
+
return !Object.keys(obj).some(function (k) {
|
|
76
|
+
return !isEqual(obj[k], test[k]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { isEqual };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version 1.0.0
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @copyright 2024 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if a value is undefined.
|
|
30
|
+
* @param value - The value to check.
|
|
31
|
+
* @returns true if the value is undefined, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
function isUndefined(value) {
|
|
34
|
+
return value === undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Check if a value is null.
|
|
39
|
+
* @param value - The value to check.
|
|
40
|
+
* @returns true if the value is null, false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
function isNull(value) {
|
|
43
|
+
return value === null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Check if a value is either null or undefined.
|
|
48
|
+
* @param val - The value to check.
|
|
49
|
+
* @returns true if the value is null or undefined, false otherwise.
|
|
50
|
+
*/
|
|
51
|
+
function isNil(val) {
|
|
52
|
+
return val === undefined || val === null;
|
|
53
|
+
}
|
|
54
|
+
function isDefined(val) {
|
|
55
|
+
return !isNil(val) && val !== "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { isDefined, isNil, isNull, isUndefined };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
4
|
+
import { isNil } from './nullChecks.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if a value is an object.
|
|
8
|
+
* An object is considered valid if it is:
|
|
9
|
+
* - not null or undefined
|
|
10
|
+
* - not a Date instance
|
|
11
|
+
* - of type 'object'
|
|
12
|
+
* - not an array
|
|
13
|
+
* @param val - The value to check.
|
|
14
|
+
* @returns true if the value is an object, false otherwise.
|
|
15
|
+
*/
|
|
16
|
+
function isObject(val) {
|
|
17
|
+
return !isNil(val) && !(val instanceof Date) && _typeof(val) === "object" && !Array.isArray(val);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if a value is an array.
|
|
22
|
+
* An array is considered valid if it is:
|
|
23
|
+
* - not null or undefined
|
|
24
|
+
* - an instance of Array
|
|
25
|
+
* @param val - The value to check.
|
|
26
|
+
* @returns true if the value is an array, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
function isArray(val) {
|
|
29
|
+
return Array.isArray(val);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Check if a value is a string.
|
|
34
|
+
* A string is considered valid if it is:
|
|
35
|
+
* - not null or undefined
|
|
36
|
+
* - of type 'string'
|
|
37
|
+
* @param value - The value to check.
|
|
38
|
+
* @returns true if the value is a string, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
function isString(value) {
|
|
41
|
+
return typeof value === "string";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Check if a value is a number.
|
|
46
|
+
* A number is considered valid if it is:
|
|
47
|
+
* - not null or undefined
|
|
48
|
+
* - of type 'number'
|
|
49
|
+
* @param value - The value to check.
|
|
50
|
+
* @returns true if the value is a number, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
function isNumber(value) {
|
|
53
|
+
return typeof value === "number";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Check if a value is a boolean.
|
|
58
|
+
* A boolean is considered valid if it is:
|
|
59
|
+
* - not null or undefined
|
|
60
|
+
* - of type 'boolean'
|
|
61
|
+
*/
|
|
62
|
+
function isBoolean(value) {
|
|
63
|
+
return typeof value === "boolean";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Check if a value is a true.
|
|
68
|
+
* A value is considered true if it is:
|
|
69
|
+
* - strictly equal to true
|
|
70
|
+
* - equal to 1
|
|
71
|
+
* - a string that is "yes" or "true" (case insensitive)
|
|
72
|
+
*/
|
|
73
|
+
function isTrue() {
|
|
74
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
75
|
+
return value === true || value === 1 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "yes" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "true";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value is false.
|
|
80
|
+
* A value is considered false if it is:
|
|
81
|
+
* - strictly equal to false
|
|
82
|
+
* - equal to 0
|
|
83
|
+
* - a string that is "no" or "false" (case insensitive)
|
|
84
|
+
*/
|
|
85
|
+
function isFalse() {
|
|
86
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
87
|
+
return value === false || value === 0 || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "no" || (value === null || value === void 0 ? void 0 : value.toString().toLowerCase()) === "false";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check if a value is a valid color.
|
|
92
|
+
* A color is considered valid if it:
|
|
93
|
+
* - starts with a '#' (hex color)
|
|
94
|
+
* - starts with 'rgb' (RGB color)
|
|
95
|
+
* - starts with 'hsl' (HSL color)
|
|
96
|
+
* - starts with 'lab' (Lab color)
|
|
97
|
+
* - is equal to 'transparent'
|
|
98
|
+
* @param color - The value to check.
|
|
99
|
+
* @returns true if the value is a valid color, false otherwise.
|
|
100
|
+
*/
|
|
101
|
+
function isColor(color) {
|
|
102
|
+
var _color$startsWith, _color$startsWith2, _color$startsWith3, _color$startsWith4;
|
|
103
|
+
return ((_color$startsWith = color.startsWith) === null || _color$startsWith === void 0 ? void 0 : _color$startsWith.call(color, "#")) || ((_color$startsWith2 = color.startsWith) === null || _color$startsWith2 === void 0 ? void 0 : _color$startsWith2.call(color, "rgb")) || ((_color$startsWith3 = color.startsWith) === null || _color$startsWith3 === void 0 ? void 0 : _color$startsWith3.call(color, "hsl")) || ((_color$startsWith4 = color.startsWith) === null || _color$startsWith4 === void 0 ? void 0 : _color$startsWith4.call(color, "lab")) || color === "transparent";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Check if a value is a valid SVG path.
|
|
108
|
+
* A valid SVG path is a string that:
|
|
109
|
+
* - starts with 'M' or 'm' (move to command)
|
|
110
|
+
* - contains at least one digit or decimal point
|
|
111
|
+
* - ends with 'Z' or 'z' (close path command)
|
|
112
|
+
* @param value - The value to check.
|
|
113
|
+
* @returns true if the value is a valid SVG path, false otherwise.
|
|
114
|
+
*/
|
|
115
|
+
function isSvgPath(value) {
|
|
116
|
+
return typeof value === "string" && value.match(/^[Mm][\d.].*[\dzZ]$/) !== null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { isArray, isBoolean, isColor, isFalse, isNumber, isObject, isString, isSvgPath, isTrue };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { isEmpty } from '../matchers/isEmpty.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license MIT
|
|
9
|
+
* @copyright 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
* in the Software without restriction, including without limitation the rights
|
|
14
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
* furnished to do so, subject to the following conditions:
|
|
17
|
+
*
|
|
18
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
* copies or substantial portions of the Software.
|
|
20
|
+
*
|
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
* SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/* istanbul ignore file */
|
|
32
|
+
|
|
33
|
+
/** ***************** latin-ascii conversions *******************/
|
|
34
|
+
var conversions = {
|
|
35
|
+
AE: "Æ|Ǽ",
|
|
36
|
+
Ae: "Ä",
|
|
37
|
+
ae: "ä|æ|ǽ",
|
|
38
|
+
OE: "Œ",
|
|
39
|
+
Oe: "Ö",
|
|
40
|
+
oe: "ö|œ",
|
|
41
|
+
Ue: "Ü",
|
|
42
|
+
ue: "ü",
|
|
43
|
+
IJ: "IJ",
|
|
44
|
+
ij: "ij",
|
|
45
|
+
ss: "ß",
|
|
46
|
+
A: "À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ",
|
|
47
|
+
a: "à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª",
|
|
48
|
+
C: "Ç|Ć|Ĉ|Ċ|Č",
|
|
49
|
+
c: "ç|ć|ĉ|ċ|č",
|
|
50
|
+
D: "Ð|Ď|Đ",
|
|
51
|
+
d: "ð|ď|đ",
|
|
52
|
+
E: "È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě",
|
|
53
|
+
e: "è|é|ê|ë|ē|ĕ|ė|ę|ě",
|
|
54
|
+
G: "Ĝ|Ğ|Ġ|Ģ",
|
|
55
|
+
g: "ĝ|ğ|ġ|ģ",
|
|
56
|
+
H: "Ĥ|Ħ",
|
|
57
|
+
h: "ĥ|ħ",
|
|
58
|
+
I: "Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ",
|
|
59
|
+
i: "ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı",
|
|
60
|
+
J: "Ĵ",
|
|
61
|
+
j: "ĵ",
|
|
62
|
+
K: "Ķ",
|
|
63
|
+
k: "ķ",
|
|
64
|
+
L: "Ĺ|Ļ|Ľ|Ŀ|Ł",
|
|
65
|
+
l: "ĺ|ļ|ľ|ŀ|ł",
|
|
66
|
+
N: "Ñ|Ń|Ņ|Ň",
|
|
67
|
+
n: "ñ|ń|ņ|ň|ʼn",
|
|
68
|
+
O: "Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ",
|
|
69
|
+
o: "ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º",
|
|
70
|
+
R: "Ŕ|Ŗ|Ř",
|
|
71
|
+
r: "ŕ|ŗ|ř",
|
|
72
|
+
S: "Ś|Ŝ|Ş|Š",
|
|
73
|
+
s: "ś|ŝ|ş|š|ſ",
|
|
74
|
+
T: "Ţ|Ť|Ŧ",
|
|
75
|
+
t: "ţ|ť|ŧ",
|
|
76
|
+
U: "Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ",
|
|
77
|
+
u: "ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ",
|
|
78
|
+
Y: "Ý|Ÿ|Ŷ",
|
|
79
|
+
y: "ý|ÿ|ŷ",
|
|
80
|
+
W: "Ŵ",
|
|
81
|
+
w: "ŵ",
|
|
82
|
+
Z: "Ź|Ż|Ž",
|
|
83
|
+
z: "ź|ż|ž",
|
|
84
|
+
f: "ƒ"
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Converts a string to its ASCII representation by replacing
|
|
89
|
+
* special characters with their ASCII equivalents.
|
|
90
|
+
* This function is useful for normalizing strings for search or display purposes.
|
|
91
|
+
* It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} str - The input string to be converted.
|
|
94
|
+
* @returns {string} - The ASCII representation of the input string.
|
|
95
|
+
*/
|
|
96
|
+
function ascii(str) {
|
|
97
|
+
if (isEmpty(str)) return "";
|
|
98
|
+
Object.entries(conversions).forEach(function (entry) {
|
|
99
|
+
var re = new RegExp(entry[1], "g");
|
|
100
|
+
str = "".concat(str).replace(re, entry[0]);
|
|
101
|
+
});
|
|
102
|
+
return str;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { ascii };
|