@react-fabric/utilities 1.0.0-beta.5 → 1.0.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_ascii.js +27 -7
- package/dist/cjs/_dedupe.js +1 -2
- package/dist/cjs/_getByPath.js +1 -1
- package/dist/cjs/_hash.js +1 -1
- package/dist/cjs/_isEqual.js +3 -0
- package/dist/cjs/_lonlat.js +41 -0
- package/dist/cjs/getImageColorset.js +2 -2
- package/dist/cjs/index.js +3 -0
- package/dist/esm/_ascii.js +27 -7
- package/dist/esm/_dedupe.js +1 -2
- package/dist/esm/_getByPath.js +1 -1
- package/dist/esm/_hash.js +1 -1
- package/dist/esm/_isEqual.js +4 -1
- package/dist/esm/_lonlat.js +40 -0
- package/dist/esm/getImageColorset.js +2 -2
- package/dist/esm/index.js +1 -0
- package/dist/types/_dedupe.d.ts +3 -3
- package/dist/types/_isType.d.ts +1 -1
- package/dist/types/_lonlat.d.ts +13 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/_ascii.ts +3 -3
- package/src/_dedupe.ts +8 -5
- package/src/_getByPath.ts +3 -3
- package/src/_hash.ts +1 -1
- package/src/_isEqual.ts +4 -1
- package/src/_isType.ts +1 -1
- package/src/_lonlat.ts +80 -0
- package/src/getImageColorset.ts +2 -2
- package/src/index.ts +1 -0
package/dist/cjs/_ascii.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
3
|
var _isType = require('./_isType.js');
|
|
5
4
|
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
/** ***************** latin-ascii conversions *******************/
|
|
7
30
|
var conversions = {
|
|
8
31
|
AE: "Æ|Ǽ",
|
|
@@ -63,12 +86,9 @@ var conversions = {
|
|
|
63
86
|
*/
|
|
64
87
|
var ascii = function ascii(str) {
|
|
65
88
|
if (_isType.isEmpty(str)) return "";
|
|
66
|
-
Object.entries(conversions).forEach(function (
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
l = _ref2[1];
|
|
70
|
-
var re = new RegExp(l, "g");
|
|
71
|
-
str = "".concat(str).replace(re, a);
|
|
89
|
+
Object.entries(conversions).forEach(function (entry) {
|
|
90
|
+
var re = new RegExp(entry[1], "g");
|
|
91
|
+
str = "".concat(str).replace(re, entry[0]);
|
|
72
92
|
});
|
|
73
93
|
return str;
|
|
74
94
|
};
|
package/dist/cjs/_dedupe.js
CHANGED
|
@@ -33,8 +33,7 @@ var dedupe = function dedupe(list, key) {
|
|
|
33
33
|
return Array.from(new Set(filtered).values());
|
|
34
34
|
}
|
|
35
35
|
return Array.from(new Map(filtered.map(function (obj) {
|
|
36
|
-
|
|
37
|
-
return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
|
|
36
|
+
return [obj[key], obj];
|
|
38
37
|
})).values());
|
|
39
38
|
};
|
|
40
39
|
var flatten = function flatten(list) {
|
package/dist/cjs/_getByPath.js
CHANGED
|
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
|
|
|
36
36
|
if (_isType.isNil(field)) {
|
|
37
37
|
return hit;
|
|
38
38
|
}
|
|
39
|
-
if (_isType.isObject(hit)) {
|
|
39
|
+
if (_isType.isObject(hit) || _isType.isArray(hit)) {
|
|
40
40
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
41
|
if (!_isType.isNil(hit[field])) {
|
|
42
42
|
return hit[field];
|
package/dist/cjs/_hash.js
CHANGED
package/dist/cjs/_isEqual.js
CHANGED
|
@@ -32,6 +32,9 @@ var _isType = require('./_isType.js');
|
|
|
32
32
|
* @internal
|
|
33
33
|
*/
|
|
34
34
|
var isEqual = function isEqual(obj, test) {
|
|
35
|
+
if (_isType.isNil(obj) && _isType.isNil(test)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
35
38
|
if (_isType.isString(obj) || _isType.isNumber(obj) || _isType.isBoolean(obj)) {
|
|
36
39
|
return obj === test;
|
|
37
40
|
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var _isType = require('./_isType.js');
|
|
5
|
+
|
|
6
|
+
var convertLatLng = function convertLatLng(lonLat) {
|
|
7
|
+
if (_isType.isArray(lonLat) && lonLat.length === 2 || _isType.isArray(lonLat) && lonLat.length === 3) {
|
|
8
|
+
return [Number(lonLat[0]), Number(lonLat[1])];
|
|
9
|
+
}
|
|
10
|
+
if (_isType.isObject(lonLat)) {
|
|
11
|
+
if ("longitude" in lonLat) {
|
|
12
|
+
return [lonLat.longitude, lonLat.latitude];
|
|
13
|
+
}
|
|
14
|
+
return ["lon" in lonLat ? lonLat.lon : lonLat.lng, lonLat.lat];
|
|
15
|
+
}
|
|
16
|
+
if (_isType.isString(lonLat)) {
|
|
17
|
+
var _lonLat$split = lonLat.split(","),
|
|
18
|
+
_lonLat$split2 = _slicedToArray(_lonLat$split, 2),
|
|
19
|
+
_lat = _lonLat$split2[0],
|
|
20
|
+
_lon = _lonLat$split2[1];
|
|
21
|
+
return [+_lon, +_lat];
|
|
22
|
+
}
|
|
23
|
+
throw Error("Invalid geo coordinates");
|
|
24
|
+
};
|
|
25
|
+
var convertToDMS = function convertToDMS(coord) {
|
|
26
|
+
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
27
|
+
var degree = Math.floor(coord);
|
|
28
|
+
var hour = (coord - degree) * 60;
|
|
29
|
+
var minute = (hour - Math.floor(hour)) * 60;
|
|
30
|
+
return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
|
|
31
|
+
};
|
|
32
|
+
var getLocationAsText = function getLocationAsText(latlon) {
|
|
33
|
+
var _convertLatLng = convertLatLng(latlon),
|
|
34
|
+
_convertLatLng2 = _slicedToArray(_convertLatLng, 2),
|
|
35
|
+
lon = _convertLatLng2[0],
|
|
36
|
+
lat = _convertLatLng2[1];
|
|
37
|
+
return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.convertLatLng = convertLatLng;
|
|
41
|
+
exports.getLocationAsText = getLocationAsText;
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var _hash = require('./_hash.js');
|
|
|
13
13
|
var _interpolate = require('./_interpolate.js');
|
|
14
14
|
var _isEqual = require('./_isEqual.js');
|
|
15
15
|
var _isType = require('./_isType.js');
|
|
16
|
+
var _lonlat = require('./_lonlat.js');
|
|
16
17
|
var _mergeRefs = require('./_mergeRefs.js');
|
|
17
18
|
var _tokenize = require('./_tokenize.js');
|
|
18
19
|
var getImageColorset = require('./getImageColorset.js');
|
|
@@ -106,6 +107,8 @@ exports.isString = _isType.isString;
|
|
|
106
107
|
exports.isSvgPath = _isType.isSvgPath;
|
|
107
108
|
exports.isTrue = _isType.isTrue;
|
|
108
109
|
exports.isUndefined = _isType.isUndefined;
|
|
110
|
+
exports.convertLatLng = _lonlat.convertLatLng;
|
|
111
|
+
exports.getLocationAsText = _lonlat.getLocationAsText;
|
|
109
112
|
exports.mergeRefs = _mergeRefs.mergeRefs;
|
|
110
113
|
exports.iconToken = _tokenize.iconToken;
|
|
111
114
|
exports.tokenize = _tokenize.tokenize;
|
package/dist/esm/_ascii.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
3
|
import { isEmpty } from './_isType.js';
|
|
5
4
|
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
/** ***************** latin-ascii conversions *******************/
|
|
7
30
|
var conversions = {
|
|
8
31
|
AE: "Æ|Ǽ",
|
|
@@ -63,12 +86,9 @@ var conversions = {
|
|
|
63
86
|
*/
|
|
64
87
|
var ascii = function ascii(str) {
|
|
65
88
|
if (isEmpty(str)) return "";
|
|
66
|
-
Object.entries(conversions).forEach(function (
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
l = _ref2[1];
|
|
70
|
-
var re = new RegExp(l, "g");
|
|
71
|
-
str = "".concat(str).replace(re, a);
|
|
89
|
+
Object.entries(conversions).forEach(function (entry) {
|
|
90
|
+
var re = new RegExp(entry[1], "g");
|
|
91
|
+
str = "".concat(str).replace(re, entry[0]);
|
|
72
92
|
});
|
|
73
93
|
return str;
|
|
74
94
|
};
|
package/dist/esm/_dedupe.js
CHANGED
|
@@ -33,8 +33,7 @@ var dedupe = function dedupe(list, key) {
|
|
|
33
33
|
return Array.from(new Set(filtered).values());
|
|
34
34
|
}
|
|
35
35
|
return Array.from(new Map(filtered.map(function (obj) {
|
|
36
|
-
|
|
37
|
-
return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
|
|
36
|
+
return [obj[key], obj];
|
|
38
37
|
})).values());
|
|
39
38
|
};
|
|
40
39
|
var flatten = function flatten(list) {
|
package/dist/esm/_getByPath.js
CHANGED
|
@@ -36,7 +36,7 @@ var _get = function _get(hit, field) {
|
|
|
36
36
|
if (isNil(field)) {
|
|
37
37
|
return hit;
|
|
38
38
|
}
|
|
39
|
-
if (isObject(hit)) {
|
|
39
|
+
if (isObject(hit) || isArray(hit)) {
|
|
40
40
|
/** ***************** return value if object.property is not empty *******************/
|
|
41
41
|
if (!isNil(hit[field])) {
|
|
42
42
|
return hit[field];
|
package/dist/esm/_hash.js
CHANGED
package/dist/esm/_isEqual.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { ascii } from './_ascii.js';
|
|
4
|
-
import { isString, isNumber, isBoolean, isObject } from './_isType.js';
|
|
4
|
+
import { isNil, isString, isNumber, isBoolean, isObject } from './_isType.js';
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* React Fabric
|
|
@@ -32,6 +32,9 @@ import { isString, isNumber, isBoolean, isObject } from './_isType.js';
|
|
|
32
32
|
* @internal
|
|
33
33
|
*/
|
|
34
34
|
var isEqual = function isEqual(obj, test) {
|
|
35
|
+
if (isNil(obj) && isNil(test)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
35
38
|
if (isString(obj) || isNumber(obj) || isBoolean(obj)) {
|
|
36
39
|
return obj === test;
|
|
37
40
|
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import { isArray, isObject, isString } from './_isType.js';
|
|
5
|
+
|
|
6
|
+
var convertLatLng = function convertLatLng(lonLat) {
|
|
7
|
+
if (isArray(lonLat) && lonLat.length === 2 || isArray(lonLat) && lonLat.length === 3) {
|
|
8
|
+
return [Number(lonLat[0]), Number(lonLat[1])];
|
|
9
|
+
}
|
|
10
|
+
if (isObject(lonLat)) {
|
|
11
|
+
if ("longitude" in lonLat) {
|
|
12
|
+
return [lonLat.longitude, lonLat.latitude];
|
|
13
|
+
}
|
|
14
|
+
return ["lon" in lonLat ? lonLat.lon : lonLat.lng, lonLat.lat];
|
|
15
|
+
}
|
|
16
|
+
if (isString(lonLat)) {
|
|
17
|
+
var _lonLat$split = lonLat.split(","),
|
|
18
|
+
_lonLat$split2 = _slicedToArray(_lonLat$split, 2),
|
|
19
|
+
_lat = _lonLat$split2[0],
|
|
20
|
+
_lon = _lonLat$split2[1];
|
|
21
|
+
return [+_lon, +_lat];
|
|
22
|
+
}
|
|
23
|
+
throw Error("Invalid geo coordinates");
|
|
24
|
+
};
|
|
25
|
+
var convertToDMS = function convertToDMS(coord) {
|
|
26
|
+
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
27
|
+
var degree = Math.floor(coord);
|
|
28
|
+
var hour = (coord - degree) * 60;
|
|
29
|
+
var minute = (hour - Math.floor(hour)) * 60;
|
|
30
|
+
return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
|
|
31
|
+
};
|
|
32
|
+
var getLocationAsText = function getLocationAsText(latlon) {
|
|
33
|
+
var _convertLatLng = convertLatLng(latlon),
|
|
34
|
+
_convertLatLng2 = _slicedToArray(_convertLatLng, 2),
|
|
35
|
+
lon = _convertLatLng2[0],
|
|
36
|
+
lat = _convertLatLng2[1];
|
|
37
|
+
return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { convertLatLng, getLocationAsText };
|
package/dist/esm/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { hash, shortHash, uuid } from './_hash.js';
|
|
|
13
13
|
export { interpolate, renderTemplate } from './_interpolate.js';
|
|
14
14
|
export { compareValues, isEqual, matchString } from './_isEqual.js';
|
|
15
15
|
export { isArray, isBoolean, isColor, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
|
|
16
|
+
export { convertLatLng, getLocationAsText } from './_lonlat.js';
|
|
16
17
|
export { mergeRefs } from './_mergeRefs.js';
|
|
17
18
|
export { iconToken, tokenize } from './_tokenize.js';
|
|
18
19
|
export { getImageColorset } from './getImageColorset.js';
|
package/dist/types/_dedupe.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const dedupe: (list:
|
|
2
|
-
export declare const flatten: (list:
|
|
3
|
-
export declare const flattenAndDedupe: (list?:
|
|
1
|
+
export declare const dedupe: <T extends unknown>(list: T[], key?: keyof T) => T[];
|
|
2
|
+
export declare const flatten: <T extends unknown>(list: T[]) => (T extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr extends readonly (infer InnerArr)[] ? InnerArr : InnerArr : InnerArr : InnerArr : InnerArr : T)[];
|
|
3
|
+
export declare const flattenAndDedupe: <T extends unknown>(list?: T[][], key?: keyof T) => T[];
|
|
4
4
|
export declare const groupBy: <T extends KeyValue<any>>(list: T[], prop: keyof T, missingKey?: string) => KeyValue<T[]>;
|
package/dist/types/_isType.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const isUndefined: (value: AnyObject) => value is undefined;
|
|
2
2
|
export declare const isNull: (value: AnyObject) => value is null;
|
|
3
|
-
export declare const isNil: (val: AnyObject) => val is undefined;
|
|
3
|
+
export declare const isNil: (val: AnyObject) => val is null | undefined;
|
|
4
4
|
export declare const isEmpty: (val: AnyObject) => val is undefined;
|
|
5
5
|
export declare const isObject: (val: AnyObject) => val is KeyValue<any>;
|
|
6
6
|
export declare const isArray: <T = any>(val: AnyObject) => val is T[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type LngLatLike = {
|
|
2
|
+
lng: number;
|
|
3
|
+
lat: number;
|
|
4
|
+
} | {
|
|
5
|
+
lon: number;
|
|
6
|
+
lat: number;
|
|
7
|
+
} | {
|
|
8
|
+
longitude: number;
|
|
9
|
+
latitude: number;
|
|
10
|
+
} | [lon: number | string, lat: number | string] | string;
|
|
11
|
+
export declare const convertLatLng: (lonLat: LngLatLike) => [lon: number, lat: number];
|
|
12
|
+
export declare const getLocationAsText: (latlon: LngLatLike) => string;
|
|
13
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./_hash";
|
|
|
13
13
|
export * from "./_interpolate";
|
|
14
14
|
export * from "./_isEqual";
|
|
15
15
|
export * from "./_isType";
|
|
16
|
+
export * from "./_lonlat";
|
|
16
17
|
export * from "./_mergeRefs";
|
|
17
18
|
export * from "./_tokenize";
|
|
18
19
|
export { getImageColorset } from "./getImageColorset";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/utilities",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.50",
|
|
4
4
|
"description": "RUF: Utility package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"date-fns": "^4.
|
|
36
|
-
"libphonenumber-js": "^1.
|
|
35
|
+
"date-fns": "^4.1.0",
|
|
36
|
+
"libphonenumber-js": "^1.12.8",
|
|
37
37
|
"numeral": "^2.0.6",
|
|
38
38
|
"yup": "^1.4.0"
|
|
39
39
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"node": ">=18.12.0",
|
|
45
45
|
"npm": ">=8.19.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "a1b04de4663045f82992bff2aef8db26608eac74"
|
|
48
48
|
}
|
package/src/_ascii.ts
CHANGED
|
@@ -85,9 +85,9 @@ const conversions = {
|
|
|
85
85
|
*/
|
|
86
86
|
export const ascii = (str: string) => {
|
|
87
87
|
if (isEmpty(str)) return "";
|
|
88
|
-
Object.entries(conversions).forEach((
|
|
89
|
-
const re = new RegExp(
|
|
90
|
-
str = `${str}`.replace(re,
|
|
88
|
+
Object.entries(conversions).forEach((entry) => {
|
|
89
|
+
const re = new RegExp(entry[1], "g");
|
|
90
|
+
str = `${str}`.replace(re, entry[0]);
|
|
91
91
|
});
|
|
92
92
|
return str;
|
|
93
93
|
};
|
package/src/_dedupe.ts
CHANGED
|
@@ -23,23 +23,26 @@
|
|
|
23
23
|
|
|
24
24
|
import { isEmpty } from "./_isType";
|
|
25
25
|
|
|
26
|
-
export const dedupe = (list:
|
|
26
|
+
export const dedupe = <T extends AnyObject>(list: T[], key?: keyof T) => {
|
|
27
27
|
const filtered = list.filter((i) => !isEmpty(i));
|
|
28
28
|
if (!key) {
|
|
29
29
|
return Array.from(new Set(filtered).values());
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return Array.from(
|
|
33
|
-
new Map(filtered.map((obj) => [obj[key]
|
|
33
|
+
new Map(filtered.map((obj) => [(obj as KeyValue)[key], obj])).values(),
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const flatten = (list:
|
|
37
|
+
export const flatten = <T extends AnyObject>(list: T[]) => {
|
|
38
38
|
return list.flat(5).filter((i) => !isEmpty(i));
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const flattenAndDedupe =
|
|
42
|
-
|
|
41
|
+
export const flattenAndDedupe = <T extends AnyObject>(
|
|
42
|
+
list: T[][] = [],
|
|
43
|
+
key?: keyof T,
|
|
44
|
+
) => {
|
|
45
|
+
return dedupe(flatten(list) as T[], key);
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
export const groupBy = <T extends KeyValue>(
|
package/src/_getByPath.ts
CHANGED
|
@@ -35,10 +35,10 @@ const _get = (hit: any, field: string): any => {
|
|
|
35
35
|
return hit;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (isObject(hit)) {
|
|
38
|
+
if (isObject(hit) || isArray(hit)) {
|
|
39
39
|
/** ***************** return value if object.property is not empty *******************/
|
|
40
|
-
if (!isNil(hit[field])) {
|
|
41
|
-
return hit[field];
|
|
40
|
+
if (!isNil(hit[field as any])) {
|
|
41
|
+
return hit[field as any];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** ***************** if property name contains `.` separator split to multiple property names *******************/
|
package/src/_hash.ts
CHANGED
package/src/_isEqual.ts
CHANGED
|
@@ -22,13 +22,16 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { ascii } from "./_ascii";
|
|
25
|
-
import { isBoolean, isNumber, isObject, isString } from "./_isType";
|
|
25
|
+
import { isBoolean, isNil, isNumber, isObject, isString } from "./_isType";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* check equality of objects
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
31
|
export const isEqual = (obj: unknown, test: unknown): boolean => {
|
|
32
|
+
if (isNil(obj) && isNil(test)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
32
35
|
if (isString(obj) || isNumber(obj) || isBoolean(obj)) {
|
|
33
36
|
return obj === test;
|
|
34
37
|
} else if (Array.isArray(obj) && Array.isArray(test)) {
|
package/src/_isType.ts
CHANGED
|
@@ -29,7 +29,7 @@ export const isNull = (value: AnyObject): value is null => {
|
|
|
29
29
|
return value === null;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export const isNil = (val: AnyObject): val is undefined => {
|
|
32
|
+
export const isNil = (val: AnyObject): val is null | undefined => {
|
|
33
33
|
return val === undefined || val === null;
|
|
34
34
|
};
|
|
35
35
|
export const isEmpty = (val: AnyObject): val is undefined => {
|
package/src/_lonlat.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { isArray, isObject, isString } from "./_isType";
|
|
25
|
+
|
|
26
|
+
type LngLatLike =
|
|
27
|
+
| {
|
|
28
|
+
lng: number;
|
|
29
|
+
lat: number;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
lon: number;
|
|
33
|
+
lat: number;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
longitude: number;
|
|
37
|
+
latitude: number;
|
|
38
|
+
}
|
|
39
|
+
| [lon: number | string, lat: number | string]
|
|
40
|
+
| string;
|
|
41
|
+
|
|
42
|
+
export const convertLatLng = (
|
|
43
|
+
lonLat: LngLatLike,
|
|
44
|
+
): [lon: number, lat: number] => {
|
|
45
|
+
if (
|
|
46
|
+
(isArray(lonLat) && lonLat.length === 2) ||
|
|
47
|
+
(isArray(lonLat) && lonLat.length === 3)
|
|
48
|
+
) {
|
|
49
|
+
return [Number(lonLat[0]), Number(lonLat[1])];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isObject(lonLat)) {
|
|
53
|
+
if ("longitude" in lonLat) {
|
|
54
|
+
return [lonLat.longitude, lonLat.latitude];
|
|
55
|
+
}
|
|
56
|
+
return ["lon" in lonLat ? lonLat.lon : lonLat.lng, lonLat.lat];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (isString(lonLat)) {
|
|
60
|
+
const [lat, lon] = lonLat.split(",");
|
|
61
|
+
return [+lon, +lat];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
throw Error("Invalid geo coordinates");
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const convertToDMS = (coord: number, isLat = false) => {
|
|
68
|
+
const degree = Math.floor(coord);
|
|
69
|
+
const hour = (coord - degree) * 60;
|
|
70
|
+
const minute = (hour - Math.floor(hour)) * 60;
|
|
71
|
+
|
|
72
|
+
return `${degree}˚${Math.floor(hour)}'${minute.toFixed(2)}"${
|
|
73
|
+
coord < 0 ? (isLat ? "S" : "W") : isLat ? "N" : "E"
|
|
74
|
+
}`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const getLocationAsText = (latlon: LngLatLike) => {
|
|
78
|
+
const [lon, lat] = convertLatLng(latlon);
|
|
79
|
+
return `${convertToDMS(lat, true)}, ${convertToDMS(lon)}`;
|
|
80
|
+
};
|
package/src/getImageColorset.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ export * from "./_hash";
|
|
|
38
38
|
export * from "./_interpolate";
|
|
39
39
|
export * from "./_isEqual";
|
|
40
40
|
export * from "./_isType";
|
|
41
|
+
export * from "./_lonlat";
|
|
41
42
|
export * from "./_mergeRefs";
|
|
42
43
|
export * from "./_tokenize";
|
|
43
44
|
export { getImageColorset } from "./getImageColorset";
|