@react-fabric/utilities 1.0.0-beta.9 → 1.0.2
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
package/src/index.ts
CHANGED
|
@@ -1,51 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* React Fabric
|
|
3
|
-
* @version
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
4
6
|
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
5
13
|
*
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
8
16
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
/* istanbul ignore file */
|
|
25
27
|
|
|
26
|
-
export
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
export
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export
|
|
28
|
+
export const UTILITIES_PACKAGE = "@react-fabric/utilities";
|
|
29
|
+
export const UTILITIES_VERSION = "1.0.0";
|
|
30
|
+
|
|
31
|
+
export { getBoundingBox, getBox } from "./css/boundingBox";
|
|
32
|
+
export { cn } from "./css/cn";
|
|
33
|
+
export { getImageColorset } from "./css/imageColorset";
|
|
34
|
+
|
|
35
|
+
export { dedupe } from "./lists/dedupe";
|
|
36
|
+
export { flatten, flattenAndDedupe } from "./lists/flatten";
|
|
37
|
+
export { getByPath, getValue } from "./lists/getByPath";
|
|
38
|
+
export { groupBy } from "./lists/groupBy";
|
|
39
|
+
|
|
40
|
+
export { default as Countries } from "./data/countries";
|
|
41
|
+
export type { Country } from "./data/countries";
|
|
42
|
+
export { default as FileUtil } from "./data/fileType";
|
|
43
|
+
export { Format } from "./data/format";
|
|
44
|
+
|
|
45
|
+
export { debounce } from "./helpers/debounce";
|
|
46
|
+
export { getLogger } from "./helpers/getLogger";
|
|
47
|
+
export { convertToLonLat, getLatitudeLongitude, getLocationAsText } from "./helpers/lonlat";
|
|
48
|
+
export type { LngLatLike } from "./helpers/lonlat";
|
|
49
|
+
|
|
50
|
+
export { compareValues } from "./matchers/compare";
|
|
51
|
+
export { isEmpty } from "./matchers/isEmpty";
|
|
52
|
+
export { isEqual } from "./matchers/isEqual";
|
|
53
|
+
export { isDefined, isNil, isNull, isUndefined } from "./matchers/nullChecks";
|
|
54
|
+
export { isArray, isBoolean, isColor, isFalse, isNumber, isObject, isString, isSvgPath, isTrue } from "./matchers/typeChecks";
|
|
55
|
+
|
|
56
|
+
export { hash, shortHash, uuid } from "./strings/hash";
|
|
57
|
+
export { interpolate } from "./strings/interpolate";
|
|
58
|
+
export { matchString } from "./strings/matchString";
|
|
59
|
+
export { renderTemplate } from "./strings/template";
|
|
60
|
+
export { iconToken, tokenize } from "./strings/tokenize";
|
|
61
|
+
|
|
62
|
+
export { mergeRefs } from "./utils/mergeRefs";
|
|
63
|
+
export { yup } from "./utils/yup";
|
|
46
64
|
|
|
47
65
|
export const EMPTY_ARRAY = [];
|
|
48
66
|
Object.freeze(EMPTY_ARRAY);
|
|
49
67
|
|
|
50
68
|
export const EMPTY_OBJECT = {};
|
|
51
69
|
Object.freeze(EMPTY_OBJECT);
|
|
70
|
+
|
|
71
|
+
export const EMPTY_FC = () => () => null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isEmpty } from "../matchers/isEmpty";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Remove duplicates from a list of objects based on a key or the entire object.
|
|
30
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
31
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
32
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
33
|
+
*
|
|
34
|
+
* @param list
|
|
35
|
+
* @param key
|
|
36
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
37
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
38
|
+
*/
|
|
39
|
+
export function dedupe<T extends AnyObject>(list: T[], key?: keyof T) {
|
|
40
|
+
const filtered = list.filter((i) => !isEmpty(i));
|
|
41
|
+
if (!key) {
|
|
42
|
+
return Array.from(new Set(filtered).values());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Array.from(new Map(filtered.map((obj) => [(obj as KeyValue)[key], obj])).values());
|
|
46
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isEmpty } from "../matchers/isEmpty";
|
|
27
|
+
import { dedupe } from "./dedupe";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Flatten a list of objects, removing any empty objects.
|
|
31
|
+
* It will flatten up to 5 levels deep and filter out any empty objects.
|
|
32
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
33
|
+
*
|
|
34
|
+
* @param list
|
|
35
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
36
|
+
* @returns {T[]} - A flattened array of objects.
|
|
37
|
+
*/
|
|
38
|
+
export function flatten<T extends AnyObject>(list: T[]) {
|
|
39
|
+
return list.flat(5).filter((i) => !isEmpty(i));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Flatten a list of objects and remove duplicates based on a key or the entire object.
|
|
44
|
+
* If a key is provided, it will deduplicate based on the value of that key.
|
|
45
|
+
* If no key is provided, it will deduplicate based on the entire object.
|
|
46
|
+
* This is useful for normalizing data structures that may have nested arrays or objects.
|
|
47
|
+
* Flattening is done first, followed by deduplication.
|
|
48
|
+
*
|
|
49
|
+
* @param list
|
|
50
|
+
* @param key
|
|
51
|
+
* @typedef {T} AnyObject - A generic type representing list items.
|
|
52
|
+
* @returns {T[]} - A new array with duplicates removed.
|
|
53
|
+
*/
|
|
54
|
+
export function flattenAndDedupe<T extends AnyObject>(list: T[][] = [], key?: keyof T) {
|
|
55
|
+
return dedupe(flatten(list) as T[], key);
|
|
56
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isEmpty } from "../matchers/isEmpty";
|
|
27
|
+
import { isNil } from "../matchers/nullChecks";
|
|
28
|
+
import { isArray, isObject } from "../matchers/typeChecks";
|
|
29
|
+
|
|
30
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
31
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
32
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
33
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
34
|
+
|
|
35
|
+
function _get(hit: any, field: string): any {
|
|
36
|
+
/** ***************** return if object is empty *******************/
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
if (isNil(hit)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/** ***************** return object if property is empty *******************/
|
|
42
|
+
/* istanbul ignore next */
|
|
43
|
+
if (isNil(field)) {
|
|
44
|
+
return hit;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isObject(hit) || isArray(hit)) {
|
|
48
|
+
/** ***************** return value if object.property is not empty *******************/
|
|
49
|
+
if (!isNil(hit[field as any])) {
|
|
50
|
+
return hit[field as any];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** ***************** if property name contains `.` separator split to multiple property names *******************/
|
|
54
|
+
if (field.includes(".")) {
|
|
55
|
+
let currentValue: any = hit;
|
|
56
|
+
|
|
57
|
+
const path = field.split(".");
|
|
58
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
59
|
+
/** ***************** when property name is `a.b.c` iterate until property found in object. eg. `a`, `a.b` *******************/
|
|
60
|
+
const outerPath = path.slice(0, i).join(".");
|
|
61
|
+
|
|
62
|
+
/** ***************** join rest of property list *******************/
|
|
63
|
+
const innerPath = path.slice(i).join(".");
|
|
64
|
+
|
|
65
|
+
/** ***************** if current outer path found in object *******************/
|
|
66
|
+
if (outerPath in currentValue) {
|
|
67
|
+
currentValue = currentValue[outerPath];
|
|
68
|
+
|
|
69
|
+
/** ***************** check for type array *******************/
|
|
70
|
+
if (isArray(currentValue)) {
|
|
71
|
+
/** ***************** return value if remaining path found *******************/
|
|
72
|
+
if (currentValue[innerPath as any]) {
|
|
73
|
+
return currentValue[innerPath as any];
|
|
74
|
+
}
|
|
75
|
+
/** ***************** return array map of inner propeties *******************/
|
|
76
|
+
return currentValue.map((val) => _get(val, innerPath)).filter((val) => !isEmpty(val));
|
|
77
|
+
} else {
|
|
78
|
+
/** ***************** return value of remaining path *******************/
|
|
79
|
+
return _get(currentValue, innerPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get a value from an object by a given path.
|
|
91
|
+
* This function allows you to retrieve a value from a nested object structure using a dot-separated path.
|
|
92
|
+
* If the path does not exist or the object is empty, it returns a default value.
|
|
93
|
+
* @param {KeyValue} obj - The object from which to retrieve the value.
|
|
94
|
+
* @param {string} path - The dot-separated path to the value within the object.
|
|
95
|
+
* @param {any} defaultValue - The value to return if the path does not exist or the object is empty.
|
|
96
|
+
* @typedef {T} AnyObject - The type of the value to be returned.
|
|
97
|
+
* @returns {T} The value at the specified path, or the default value if the path does not exist.
|
|
98
|
+
*/
|
|
99
|
+
export function getByPath<T = unknown>(obj: KeyValue, path: string, defaultValue: any = undefined): T {
|
|
100
|
+
/** ***************** if empty object/path return defaultValue *******************/
|
|
101
|
+
if (isEmpty(obj) || isEmpty(path)) {
|
|
102
|
+
return defaultValue;
|
|
103
|
+
}
|
|
104
|
+
const value = _get(obj, path);
|
|
105
|
+
if (!isNil(value)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
return defaultValue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Get the first non-empty value from the provided arguments.
|
|
113
|
+
* This function is useful for finding a default value or fallback when multiple values are provided.
|
|
114
|
+
* It checks each argument in order and returns the first one that is not empty.
|
|
115
|
+
* If all arguments are empty, it returns `undefined`.
|
|
116
|
+
*
|
|
117
|
+
* @param {...any} args - The values to check for non-emptiness.
|
|
118
|
+
* @returns {any} The first non-empty value, or `undefined` if all are empty.
|
|
119
|
+
*/
|
|
120
|
+
export function getValue<T = string>(...args: T[]) {
|
|
121
|
+
return args.find((a) => !isEmpty(a));
|
|
122
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Group a list of objects by a specific property.
|
|
28
|
+
* If the property is not present in an object, it will use the `missingKey` value as the key.
|
|
29
|
+
* This is useful for organizing data into categories based on a specific property.
|
|
30
|
+
*
|
|
31
|
+
* @param list
|
|
32
|
+
* @param prop
|
|
33
|
+
* @param missingKey
|
|
34
|
+
* @typedef {T} KeyValue - A generic type representing list items with key-value pairs.
|
|
35
|
+
* @returns {KeyValue<T[]>} - An object mapping keys to arrays of items.
|
|
36
|
+
*/
|
|
37
|
+
export function groupBy<T extends KeyValue>(list: T[], prop: keyof T, missingKey?: string): KeyValue<T[]> {
|
|
38
|
+
return list.reduce<KeyValue<T[]>>(
|
|
39
|
+
(r, i) => {
|
|
40
|
+
const key = (i[prop] as string) ?? missingKey;
|
|
41
|
+
if (!r[key]) r[key] = [];
|
|
42
|
+
r[key].push(i);
|
|
43
|
+
return r;
|
|
44
|
+
},
|
|
45
|
+
{} as KeyValue<T[]>,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { getByPath } from "../lists/getByPath";
|
|
27
|
+
import { ascii } from "../strings/ascii";
|
|
28
|
+
import { isBoolean, isNumber, isObject } from "./typeChecks";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compare two values for sorting.
|
|
32
|
+
* This function compares two values based on the specified order (ascending or descending).
|
|
33
|
+
* If a key is provided, it compares the values of that key in the objects.
|
|
34
|
+
* It handles various data types such as strings, numbers, booleans, and objects.
|
|
35
|
+
* It returns a comparison function that can be used with array sorting methods.
|
|
36
|
+
* * The comparison is done in a case-insensitive manner for strings,
|
|
37
|
+
* treating special characters as their ASCII equivalents.
|
|
38
|
+
*
|
|
39
|
+
* @param {("asc" | "desc")} order - The order of comparison, either "asc" for ascending or "desc" for descending.
|
|
40
|
+
* @param {string} key - An optional key to compare values within objects.
|
|
41
|
+
* @returns {Function} A comparison function that can be used with array sorting methods.
|
|
42
|
+
*/
|
|
43
|
+
export function compareValues(order: "asc" | "desc" = "asc", key?: string) {
|
|
44
|
+
return (a: unknown, b: unknown) => {
|
|
45
|
+
const aValue: unknown = key && isObject(a) ? getByPath(a, key, "") : a;
|
|
46
|
+
const bValue: unknown = key && isObject(b) ? getByPath(b, key, "") : b;
|
|
47
|
+
|
|
48
|
+
const bigger = order === "asc" ? 1 : -1;
|
|
49
|
+
const smaller = order === "desc" ? 1 : -1;
|
|
50
|
+
// return 0 when equal, allowing for multiple sorting properties
|
|
51
|
+
if (aValue === bValue) return 0;
|
|
52
|
+
// if numbers check greater
|
|
53
|
+
if (isNumber(aValue) && isNumber(bValue)) {
|
|
54
|
+
return aValue > bValue ? bigger : smaller;
|
|
55
|
+
}
|
|
56
|
+
// if boolean sort true first
|
|
57
|
+
if (isBoolean(aValue) && isBoolean(bValue)) {
|
|
58
|
+
return aValue ? smaller : bigger;
|
|
59
|
+
}
|
|
60
|
+
const _a = ascii(aValue as string).toLowerCase();
|
|
61
|
+
const _b = ascii(bValue as string).toLowerCase();
|
|
62
|
+
return _a.localeCompare(_b) === 1 ? bigger : smaller;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isDefined, isNil } from "./nullChecks";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if a value is empty.
|
|
30
|
+
* A value is considered empty if it is:
|
|
31
|
+
* - undefined
|
|
32
|
+
* - null
|
|
33
|
+
* - an empty string
|
|
34
|
+
* - an empty array
|
|
35
|
+
* - an empty object
|
|
36
|
+
* - an empty Map or Set
|
|
37
|
+
* - a boolean, number, or bigint (not empty)
|
|
38
|
+
* @param val - The value to check.
|
|
39
|
+
* @returns true if the value is empty, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
export function isEmpty(val: AnyObject): val is undefined {
|
|
42
|
+
if (val instanceof Date) return false;
|
|
43
|
+
if (isNil(val) || val === "") {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(val) && val.filter(isDefined).length === 0) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
|
50
|
+
if (["boolean", "number", "bigint", "function"].includes(typeof val)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return !!val && typeof val === "object" && Object.entries(val as object).length === 0;
|
|
54
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { isNil } from "./nullChecks";
|
|
27
|
+
import { isBoolean, isNumber, isObject, isString } from "./typeChecks";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Compare two objects or values for equality.
|
|
31
|
+
* This function checks if two values are equal, including nested objects and arrays.
|
|
32
|
+
* It handles various data types such as strings, numbers, booleans, arrays, and objects.
|
|
33
|
+
* If both values are `null` or `undefined`, they are considered equal.
|
|
34
|
+
* If both values are primitive types (string, number, boolean), they are compared directly.
|
|
35
|
+
* If both values are arrays, they are compared element by element.
|
|
36
|
+
* If both values are objects, they are compared by their keys and values.
|
|
37
|
+
* If the values are of different types or structures, they are considered not equal.
|
|
38
|
+
*
|
|
39
|
+
* @param {unknown} obj - The first value to compare.
|
|
40
|
+
* @param {unknown} test - The second value to compare against the first.
|
|
41
|
+
* @returns {boolean} - Returns true if the values are equal, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
export function isEqual(obj: unknown, test: unknown): boolean {
|
|
44
|
+
if (isNil(obj) && isNil(test)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (isString(obj) || isNumber(obj) || isBoolean(obj)) {
|
|
48
|
+
return obj === test;
|
|
49
|
+
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
50
|
+
// if length dont match return false
|
|
51
|
+
if (obj.length !== test.length) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// check if some value is false
|
|
55
|
+
return !obj.some((o, i) => !isEqual(o, test[i]));
|
|
56
|
+
} else if (isObject(obj) && isObject(test)) {
|
|
57
|
+
const okeys = Object.keys(obj);
|
|
58
|
+
const tkeys = Object.keys(test);
|
|
59
|
+
// if keys length dont match return false
|
|
60
|
+
if (okeys.length !== tkeys.length) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
// if keys dont match return false
|
|
64
|
+
if (okeys.some((k) => !tkeys.includes(k))) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// check if some value is false
|
|
68
|
+
return !Object.keys(obj).some((k) => !isEqual(obj[k], test[k]));
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if a value is undefined.
|
|
28
|
+
* @param value - The value to check.
|
|
29
|
+
* @returns true if the value is undefined, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export function isUndefined(value: AnyObject): value is undefined {
|
|
32
|
+
return value === undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if a value is null.
|
|
37
|
+
* @param value - The value to check.
|
|
38
|
+
* @returns true if the value is null, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
export function isNull(value: AnyObject): value is null {
|
|
41
|
+
return value === null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Check if a value is either null or undefined.
|
|
46
|
+
* @param val - The value to check.
|
|
47
|
+
* @returns true if the value is null or undefined, false otherwise.
|
|
48
|
+
*/
|
|
49
|
+
export function isNil(val: AnyObject): val is null | undefined {
|
|
50
|
+
return val === undefined || val === null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function isDefined(val: AnyObject): boolean {
|
|
54
|
+
return !isNil(val) && val !== "";
|
|
55
|
+
}
|