@react-fabric/utilities 1.0.0-beta.58 → 1.0.0-beta.59
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/_isType.js +5 -1
- package/dist/cjs/_lonlat.js +6 -3
- package/dist/cjs/index.js +1 -0
- package/dist/esm/_isType.js +5 -2
- package/dist/esm/_lonlat.js +7 -4
- package/dist/esm/index.js +1 -1
- package/dist/types/_isType.d.ts +1 -0
- package/dist/types/_lonlat.d.ts +1 -1
- package/package.json +2 -2
- package/src/_isType.ts +3 -1
- package/src/_lonlat.ts +8 -4
package/dist/cjs/_isType.js
CHANGED
|
@@ -51,6 +51,9 @@ var isNull = function isNull(value) {
|
|
|
51
51
|
var isNil = function isNil(val) {
|
|
52
52
|
return val === undefined || val === null;
|
|
53
53
|
};
|
|
54
|
+
var isDefined = function isDefined(val) {
|
|
55
|
+
return !isNil(val) && val !== "";
|
|
56
|
+
};
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Check if a value is empty.
|
|
@@ -70,7 +73,7 @@ var isEmpty = function isEmpty(val) {
|
|
|
70
73
|
if (isNil(val) || val === "") {
|
|
71
74
|
return true;
|
|
72
75
|
}
|
|
73
|
-
if (Array.isArray(val) && val.filter(
|
|
76
|
+
if (Array.isArray(val) && val.filter(isDefined).length === 0) {
|
|
74
77
|
return true;
|
|
75
78
|
}
|
|
76
79
|
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
|
@@ -206,6 +209,7 @@ var isRtl = function isRtl() {
|
|
|
206
209
|
exports.isArray = isArray;
|
|
207
210
|
exports.isBoolean = isBoolean;
|
|
208
211
|
exports.isColor = isColor;
|
|
212
|
+
exports.isDefined = isDefined;
|
|
209
213
|
exports.isEmpty = isEmpty;
|
|
210
214
|
exports.isFalse = isFalse;
|
|
211
215
|
exports.isNil = isNil;
|
package/dist/cjs/_lonlat.js
CHANGED
|
@@ -27,6 +27,9 @@ var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
|
|
|
27
27
|
* @throws Error if the input is not a valid format.
|
|
28
28
|
*/
|
|
29
29
|
var convertLatLng = function convertLatLng(lonLat) {
|
|
30
|
+
if (_isType.isEmpty(lonLat)) {
|
|
31
|
+
throw Error("Invalid geo coordinates");
|
|
32
|
+
}
|
|
30
33
|
if (_isType.isArray(lonLat) && lonLat.length === 2 || _isType.isArray(lonLat) && lonLat.length === 3) {
|
|
31
34
|
return [Number(lonLat[0]), Number(lonLat[1])];
|
|
32
35
|
}
|
|
@@ -41,7 +44,7 @@ var convertLatLng = function convertLatLng(lonLat) {
|
|
|
41
44
|
_lonLat$split2 = _slicedToArray(_lonLat$split, 2),
|
|
42
45
|
_lat = _lonLat$split2[0],
|
|
43
46
|
_lon = _lonLat$split2[1];
|
|
44
|
-
return [+_lon, +_lat];
|
|
47
|
+
if (!isNaN(+_lat) && !isNaN(+_lon)) return [+_lon, +_lat];
|
|
45
48
|
}
|
|
46
49
|
throw Error("Invalid geo coordinates");
|
|
47
50
|
};
|
|
@@ -60,8 +63,8 @@ var convertLatLng = function convertLatLng(lonLat) {
|
|
|
60
63
|
*/
|
|
61
64
|
var convertToDMS = function convertToDMS(coord) {
|
|
62
65
|
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
63
|
-
var degree = Math.floor(coord);
|
|
64
|
-
var hour = (coord - degree) * 60;
|
|
66
|
+
var degree = Math.floor(Math.abs(coord));
|
|
67
|
+
var hour = (Math.abs(coord) - degree) * 60;
|
|
65
68
|
var minute = (hour - Math.floor(hour)) * 60;
|
|
66
69
|
return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
|
|
67
70
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -96,6 +96,7 @@ exports.matchString = _isEqual.matchString;
|
|
|
96
96
|
exports.isArray = _isType.isArray;
|
|
97
97
|
exports.isBoolean = _isType.isBoolean;
|
|
98
98
|
exports.isColor = _isType.isColor;
|
|
99
|
+
exports.isDefined = _isType.isDefined;
|
|
99
100
|
exports.isEmpty = _isType.isEmpty;
|
|
100
101
|
exports.isFalse = _isType.isFalse;
|
|
101
102
|
exports.isNil = _isType.isNil;
|
package/dist/esm/_isType.js
CHANGED
|
@@ -51,6 +51,9 @@ var isNull = function isNull(value) {
|
|
|
51
51
|
var isNil = function isNil(val) {
|
|
52
52
|
return val === undefined || val === null;
|
|
53
53
|
};
|
|
54
|
+
var isDefined = function isDefined(val) {
|
|
55
|
+
return !isNil(val) && val !== "";
|
|
56
|
+
};
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Check if a value is empty.
|
|
@@ -70,7 +73,7 @@ var isEmpty = function isEmpty(val) {
|
|
|
70
73
|
if (isNil(val) || val === "") {
|
|
71
74
|
return true;
|
|
72
75
|
}
|
|
73
|
-
if (Array.isArray(val) && val.filter(
|
|
76
|
+
if (Array.isArray(val) && val.filter(isDefined).length === 0) {
|
|
74
77
|
return true;
|
|
75
78
|
}
|
|
76
79
|
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
|
@@ -203,4 +206,4 @@ var isRtl = function isRtl() {
|
|
|
203
206
|
return getComputedStyle(document.documentElement).direction === "rtl";
|
|
204
207
|
};
|
|
205
208
|
|
|
206
|
-
export { isArray, isBoolean, isColor, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined };
|
|
209
|
+
export { isArray, isBoolean, isColor, isDefined, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined };
|
package/dist/esm/_lonlat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
-
import { isArray, isObject, isString } from './_isType.js';
|
|
4
|
+
import { isEmpty, isArray, isObject, isString } from './_isType.js';
|
|
5
5
|
|
|
6
6
|
var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
|
|
7
7
|
var _convertLatLng = convertLatLng(lonLat),
|
|
@@ -27,6 +27,9 @@ var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
|
|
|
27
27
|
* @throws Error if the input is not a valid format.
|
|
28
28
|
*/
|
|
29
29
|
var convertLatLng = function convertLatLng(lonLat) {
|
|
30
|
+
if (isEmpty(lonLat)) {
|
|
31
|
+
throw Error("Invalid geo coordinates");
|
|
32
|
+
}
|
|
30
33
|
if (isArray(lonLat) && lonLat.length === 2 || isArray(lonLat) && lonLat.length === 3) {
|
|
31
34
|
return [Number(lonLat[0]), Number(lonLat[1])];
|
|
32
35
|
}
|
|
@@ -41,7 +44,7 @@ var convertLatLng = function convertLatLng(lonLat) {
|
|
|
41
44
|
_lonLat$split2 = _slicedToArray(_lonLat$split, 2),
|
|
42
45
|
_lat = _lonLat$split2[0],
|
|
43
46
|
_lon = _lonLat$split2[1];
|
|
44
|
-
return [+_lon, +_lat];
|
|
47
|
+
if (!isNaN(+_lat) && !isNaN(+_lon)) return [+_lon, +_lat];
|
|
45
48
|
}
|
|
46
49
|
throw Error("Invalid geo coordinates");
|
|
47
50
|
};
|
|
@@ -60,8 +63,8 @@ var convertLatLng = function convertLatLng(lonLat) {
|
|
|
60
63
|
*/
|
|
61
64
|
var convertToDMS = function convertToDMS(coord) {
|
|
62
65
|
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
63
|
-
var degree = Math.floor(coord);
|
|
64
|
-
var hour = (coord - degree) * 60;
|
|
66
|
+
var degree = Math.floor(Math.abs(coord));
|
|
67
|
+
var hour = (Math.abs(coord) - degree) * 60;
|
|
65
68
|
var minute = (hour - Math.floor(hour)) * 60;
|
|
66
69
|
return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
|
|
67
70
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export { getByPath, getValue } from './_getByPath.js';
|
|
|
12
12
|
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
|
-
export { isArray, isBoolean, isColor, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
|
|
15
|
+
export { isArray, isBoolean, isColor, isDefined, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
|
|
16
16
|
export { convertLatLng, getLatitudeLongitude, getLocationAsText } from './_lonlat.js';
|
|
17
17
|
export { mergeRefs } from './_mergeRefs.js';
|
|
18
18
|
export { iconToken, tokenize } from './_tokenize.js';
|
package/dist/types/_isType.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const isNull: (value: AnyObject) => value is null;
|
|
|
16
16
|
* @returns true if the value is null or undefined, false otherwise.
|
|
17
17
|
*/
|
|
18
18
|
export declare const isNil: (val: AnyObject) => val is null | undefined;
|
|
19
|
+
export declare const isDefined: (val: AnyObject) => boolean;
|
|
19
20
|
/**
|
|
20
21
|
* Check if a value is empty.
|
|
21
22
|
* A value is considered empty if it is:
|
package/dist/types/_lonlat.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type LngLatLike = {
|
|
|
7
7
|
} | {
|
|
8
8
|
longitude: number;
|
|
9
9
|
latitude: number;
|
|
10
|
-
} | [lon: number | string, lat: number | string] | string;
|
|
10
|
+
} | [lon: number | string, lat: number | string] | [lon: number | string, lat: number | string, z: number | string] | string;
|
|
11
11
|
export declare const getLatitudeLongitude: (lonLat: LngLatLike) => {
|
|
12
12
|
latitude: number;
|
|
13
13
|
longitude: number;
|
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.59",
|
|
4
4
|
"description": "RUF: Utility package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"node": ">=18.12.0",
|
|
45
45
|
"npm": ">=8.19.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "74efd06c9c5ac629b6ef5cdc6d53ecb1c356f2eb"
|
|
48
48
|
}
|
package/src/_isType.ts
CHANGED
|
@@ -48,6 +48,8 @@ export const isNil = (val: AnyObject): val is null | undefined => {
|
|
|
48
48
|
return val === undefined || val === null;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
export const isDefined = (val: AnyObject): boolean => !isNil(val) && val !== "";
|
|
52
|
+
|
|
51
53
|
/**
|
|
52
54
|
* Check if a value is empty.
|
|
53
55
|
* A value is considered empty if it is:
|
|
@@ -66,7 +68,7 @@ export const isEmpty = (val: AnyObject): val is undefined => {
|
|
|
66
68
|
if (isNil(val) || val === "") {
|
|
67
69
|
return true;
|
|
68
70
|
}
|
|
69
|
-
if (Array.isArray(val) && val.filter(
|
|
71
|
+
if (Array.isArray(val) && val.filter(isDefined).length === 0) {
|
|
70
72
|
return true;
|
|
71
73
|
}
|
|
72
74
|
if (val instanceof Map || val instanceof Set) return val.size === 0;
|
package/src/_lonlat.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { isArray, isObject, isString } from "./_isType";
|
|
24
|
+
import { isArray, isEmpty, isObject, isString } from "./_isType";
|
|
25
25
|
|
|
26
26
|
export type LngLatLike =
|
|
27
27
|
| {
|
|
@@ -37,6 +37,7 @@ export type LngLatLike =
|
|
|
37
37
|
latitude: number;
|
|
38
38
|
}
|
|
39
39
|
| [lon: number | string, lat: number | string]
|
|
40
|
+
| [lon: number | string, lat: number | string, z: number | string]
|
|
40
41
|
| string;
|
|
41
42
|
|
|
42
43
|
export const getLatitudeLongitude = (
|
|
@@ -61,6 +62,9 @@ export const getLatitudeLongitude = (
|
|
|
61
62
|
export const convertLatLng = (
|
|
62
63
|
lonLat: LngLatLike,
|
|
63
64
|
): [lon: number, lat: number] => {
|
|
65
|
+
if (isEmpty(lonLat)) {
|
|
66
|
+
throw Error("Invalid geo coordinates");
|
|
67
|
+
}
|
|
64
68
|
if (
|
|
65
69
|
(isArray(lonLat) && lonLat.length === 2) ||
|
|
66
70
|
(isArray(lonLat) && lonLat.length === 3)
|
|
@@ -77,7 +81,7 @@ export const convertLatLng = (
|
|
|
77
81
|
|
|
78
82
|
if (isString(lonLat)) {
|
|
79
83
|
const [lat, lon] = lonLat.split(",");
|
|
80
|
-
return [+lon, +lat];
|
|
84
|
+
if (!isNaN(+lat) && !isNaN(+lon)) return [+lon, +lat];
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
throw Error("Invalid geo coordinates");
|
|
@@ -96,8 +100,8 @@ export const convertLatLng = (
|
|
|
96
100
|
* @returns {string} A string representation of the coordinate in DMS format.
|
|
97
101
|
*/
|
|
98
102
|
const convertToDMS = (coord: number, isLat = false) => {
|
|
99
|
-
const degree = Math.floor(coord);
|
|
100
|
-
const hour = (coord - degree) * 60;
|
|
103
|
+
const degree = Math.floor(Math.abs(coord));
|
|
104
|
+
const hour = (Math.abs(coord) - degree) * 60;
|
|
101
105
|
const minute = (hour - Math.floor(hour)) * 60;
|
|
102
106
|
|
|
103
107
|
return `${degree}˚${Math.floor(hour)}'${minute.toFixed(2)}"${
|