@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isEmpty = require('../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
|
+
/**
|
|
32
|
+
* Remove duplicates from a list of objects based on a key or the entire object.
|
|
33
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
34
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
35
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
36
|
+
*
|
|
37
|
+
* @param list
|
|
38
|
+
* @param key
|
|
39
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
40
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
41
|
+
*/
|
|
42
|
+
function dedupe(list, key) {
|
|
43
|
+
var filtered = list.filter(function (i) {
|
|
44
|
+
return !isEmpty.isEmpty(i);
|
|
45
|
+
});
|
|
46
|
+
if (!key) {
|
|
47
|
+
return Array.from(new Set(filtered).values());
|
|
48
|
+
}
|
|
49
|
+
return Array.from(new Map(filtered.map(function (obj) {
|
|
50
|
+
return [obj[key], obj];
|
|
51
|
+
})).values());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.dedupe = dedupe;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isEmpty = require('../matchers/isEmpty.js');
|
|
4
|
+
var dedupe = require('./dedupe.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
|
+
* Flatten a list of objects, removing any empty objects.
|
|
34
|
+
* It will flatten up to 5 levels deep and filter out any empty objects.
|
|
35
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
36
|
+
*
|
|
37
|
+
* @param list
|
|
38
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
39
|
+
* @returns {T[]} - A flattened array of objects.
|
|
40
|
+
*/
|
|
41
|
+
function flatten(list) {
|
|
42
|
+
return list.flat(5).filter(function (i) {
|
|
43
|
+
return !isEmpty.isEmpty(i);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Flatten a list of objects and remove duplicates based on a key or the entire object.
|
|
49
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
50
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
51
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
52
|
+
* Flattening is done first, followed by deduplication.
|
|
53
|
+
*
|
|
54
|
+
* @param list
|
|
55
|
+
* @param key
|
|
56
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
57
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
58
|
+
*/
|
|
59
|
+
function flattenAndDedupe() {
|
|
60
|
+
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
61
|
+
var key = arguments.length > 1 ? arguments[1] : undefined;
|
|
62
|
+
return dedupe.dedupe(flatten(list), key);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.flatten = flatten;
|
|
66
|
+
exports.flattenAndDedupe = flattenAndDedupe;
|
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var isEmpty = require('../matchers/isEmpty.js');
|
|
4
|
+
var nullChecks = require('../matchers/nullChecks.js');
|
|
5
|
+
var typeChecks = require('../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
|
-
if (
|
|
41
|
+
if (nullChecks.isNil(hit)) {
|
|
32
42
|
return undefined;
|
|
33
43
|
}
|
|
34
44
|
/** ***************** return object if property is empty *******************/
|
|
35
45
|
/* istanbul ignore next */
|
|
36
|
-
if (
|
|
46
|
+
if (nullChecks.isNil(field)) {
|
|
37
47
|
return hit;
|
|
38
48
|
}
|
|
39
|
-
if (
|
|
49
|
+
if (typeChecks.isObject(hit) || typeChecks.isArray(hit)) {
|
|
40
50
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
|
-
if (!
|
|
51
|
+
if (!nullChecks.isNil(hit[field])) {
|
|
42
52
|
return hit[field];
|
|
43
53
|
}
|
|
44
54
|
|
|
@@ -58,7 +68,7 @@ var _get = function _get(hit, field) {
|
|
|
58
68
|
currentValue = currentValue[outerPath];
|
|
59
69
|
|
|
60
70
|
/** ***************** check for type array *******************/
|
|
61
|
-
if (
|
|
71
|
+
if (typeChecks.isArray(currentValue)) {
|
|
62
72
|
/** ***************** return value if remaining path found *******************/
|
|
63
73
|
if (currentValue[innerPath]) {
|
|
64
74
|
return {
|
|
@@ -70,7 +80,7 @@ var _get = function _get(hit, field) {
|
|
|
70
80
|
v: currentValue.map(function (val) {
|
|
71
81
|
return _get(val, innerPath);
|
|
72
82
|
}).filter(function (val) {
|
|
73
|
-
return !
|
|
83
|
+
return !isEmpty.isEmpty(val);
|
|
74
84
|
})
|
|
75
85
|
};
|
|
76
86
|
} else {
|
|
@@ -89,37 +99,48 @@ 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
|
-
if (
|
|
117
|
+
if (isEmpty.isEmpty(obj) || isEmpty.isEmpty(path)) {
|
|
102
118
|
return defaultValue;
|
|
103
119
|
}
|
|
104
120
|
var value = _get(obj, path);
|
|
105
|
-
if (!
|
|
121
|
+
if (!nullChecks.isNil(value)) {
|
|
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
|
-
return !
|
|
141
|
+
return !isEmpty.isEmpty(a);
|
|
121
142
|
});
|
|
122
|
-
}
|
|
143
|
+
}
|
|
123
144
|
|
|
124
145
|
exports.getByPath = getByPath;
|
|
125
146
|
exports.getValue = getValue;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
exports.groupBy = groupBy;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getByPath = require('../lists/getByPath.js');
|
|
4
|
+
var ascii = require('../strings/ascii.js');
|
|
5
|
+
var typeChecks = require('./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 && typeChecks.isObject(a) ? getByPath.getByPath(a, key, "") : a;
|
|
51
|
+
var bValue = key && typeChecks.isObject(b) ? getByPath.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 (typeChecks.isNumber(aValue) && typeChecks.isNumber(bValue)) {
|
|
58
|
+
return aValue > bValue ? bigger : smaller;
|
|
59
|
+
}
|
|
60
|
+
// if boolean sort true first
|
|
61
|
+
if (typeChecks.isBoolean(aValue) && typeChecks.isBoolean(bValue)) {
|
|
62
|
+
return aValue ? smaller : bigger;
|
|
63
|
+
}
|
|
64
|
+
var _a = ascii.ascii(aValue).toLowerCase();
|
|
65
|
+
var _b = ascii.ascii(bValue).toLowerCase();
|
|
66
|
+
return _a.localeCompare(_b) === 1 ? bigger : smaller;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.compareValues = compareValues;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
4
|
+
var nullChecks = require('./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 (nullChecks.isNil(val) || val === "") {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(val) && val.filter(nullChecks.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
|
+
exports.isEmpty = isEmpty;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var nullChecks = require('./nullChecks.js');
|
|
4
|
+
var typeChecks = require('./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 (nullChecks.isNil(obj) && nullChecks.isNil(test)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (typeChecks.isString(obj) || typeChecks.isNumber(obj) || typeChecks.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 (typeChecks.isObject(obj) && typeChecks.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
|
+
exports.isEqual = isEqual;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
exports.isDefined = isDefined;
|
|
59
|
+
exports.isNil = isNil;
|
|
60
|
+
exports.isNull = isNull;
|
|
61
|
+
exports.isUndefined = isUndefined;
|