@react-fabric/utilities 1.0.0-beta.52 → 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.
@@ -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(Boolean).length === 0) {
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;
@@ -3,6 +3,17 @@
3
3
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
4
  var _isType = require('./_isType.js');
5
5
 
6
+ var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
7
+ var _convertLatLng = convertLatLng(lonLat),
8
+ _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
9
+ lon = _convertLatLng2[0],
10
+ lat = _convertLatLng2[1];
11
+ return {
12
+ latitude: lat,
13
+ longitude: lon
14
+ };
15
+ };
16
+
6
17
  /**
7
18
  * Convert various formats of longitude and latitude to a tuple of [lon, lat].
8
19
  * This function supports:
@@ -16,6 +27,9 @@ var _isType = require('./_isType.js');
16
27
  * @throws Error if the input is not a valid format.
17
28
  */
18
29
  var convertLatLng = function convertLatLng(lonLat) {
30
+ if (_isType.isEmpty(lonLat)) {
31
+ throw Error("Invalid geo coordinates");
32
+ }
19
33
  if (_isType.isArray(lonLat) && lonLat.length === 2 || _isType.isArray(lonLat) && lonLat.length === 3) {
20
34
  return [Number(lonLat[0]), Number(lonLat[1])];
21
35
  }
@@ -30,7 +44,7 @@ var convertLatLng = function convertLatLng(lonLat) {
30
44
  _lonLat$split2 = _slicedToArray(_lonLat$split, 2),
31
45
  _lat = _lonLat$split2[0],
32
46
  _lon = _lonLat$split2[1];
33
- return [+_lon, +_lat];
47
+ if (!isNaN(+_lat) && !isNaN(+_lon)) return [+_lon, +_lat];
34
48
  }
35
49
  throw Error("Invalid geo coordinates");
36
50
  };
@@ -49,8 +63,8 @@ var convertLatLng = function convertLatLng(lonLat) {
49
63
  */
50
64
  var convertToDMS = function convertToDMS(coord) {
51
65
  var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
52
- var degree = Math.floor(coord);
53
- var hour = (coord - degree) * 60;
66
+ var degree = Math.floor(Math.abs(coord));
67
+ var hour = (Math.abs(coord) - degree) * 60;
54
68
  var minute = (hour - Math.floor(hour)) * 60;
55
69
  return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
56
70
  };
@@ -76,12 +90,13 @@ var convertToDMS = function convertToDMS(coord) {
76
90
  * ```
77
91
  */
78
92
  var getLocationAsText = function getLocationAsText(latlon) {
79
- var _convertLatLng = convertLatLng(latlon),
80
- _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
81
- lon = _convertLatLng2[0],
82
- lat = _convertLatLng2[1];
93
+ var _convertLatLng3 = convertLatLng(latlon),
94
+ _convertLatLng4 = _slicedToArray(_convertLatLng3, 2),
95
+ lon = _convertLatLng4[0],
96
+ lat = _convertLatLng4[1];
83
97
  return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
84
98
  };
85
99
 
86
100
  exports.convertLatLng = convertLatLng;
101
+ exports.getLatitudeLongitude = getLatitudeLongitude;
87
102
  exports.getLocationAsText = getLocationAsText;
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;
@@ -108,6 +109,7 @@ exports.isSvgPath = _isType.isSvgPath;
108
109
  exports.isTrue = _isType.isTrue;
109
110
  exports.isUndefined = _isType.isUndefined;
110
111
  exports.convertLatLng = _lonlat.convertLatLng;
112
+ exports.getLatitudeLongitude = _lonlat.getLatitudeLongitude;
111
113
  exports.getLocationAsText = _lonlat.getLocationAsText;
112
114
  exports.mergeRefs = _mergeRefs.mergeRefs;
113
115
  exports.iconToken = _tokenize.iconToken;
@@ -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(Boolean).length === 0) {
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 };
@@ -1,7 +1,18 @@
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
+
6
+ var getLatitudeLongitude = function getLatitudeLongitude(lonLat) {
7
+ var _convertLatLng = convertLatLng(lonLat),
8
+ _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
9
+ lon = _convertLatLng2[0],
10
+ lat = _convertLatLng2[1];
11
+ return {
12
+ latitude: lat,
13
+ longitude: lon
14
+ };
15
+ };
5
16
 
6
17
  /**
7
18
  * Convert various formats of longitude and latitude to a tuple of [lon, lat].
@@ -16,6 +27,9 @@ import { isArray, isObject, isString } from './_isType.js';
16
27
  * @throws Error if the input is not a valid format.
17
28
  */
18
29
  var convertLatLng = function convertLatLng(lonLat) {
30
+ if (isEmpty(lonLat)) {
31
+ throw Error("Invalid geo coordinates");
32
+ }
19
33
  if (isArray(lonLat) && lonLat.length === 2 || isArray(lonLat) && lonLat.length === 3) {
20
34
  return [Number(lonLat[0]), Number(lonLat[1])];
21
35
  }
@@ -30,7 +44,7 @@ var convertLatLng = function convertLatLng(lonLat) {
30
44
  _lonLat$split2 = _slicedToArray(_lonLat$split, 2),
31
45
  _lat = _lonLat$split2[0],
32
46
  _lon = _lonLat$split2[1];
33
- return [+_lon, +_lat];
47
+ if (!isNaN(+_lat) && !isNaN(+_lon)) return [+_lon, +_lat];
34
48
  }
35
49
  throw Error("Invalid geo coordinates");
36
50
  };
@@ -49,8 +63,8 @@ var convertLatLng = function convertLatLng(lonLat) {
49
63
  */
50
64
  var convertToDMS = function convertToDMS(coord) {
51
65
  var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
52
- var degree = Math.floor(coord);
53
- var hour = (coord - degree) * 60;
66
+ var degree = Math.floor(Math.abs(coord));
67
+ var hour = (Math.abs(coord) - degree) * 60;
54
68
  var minute = (hour - Math.floor(hour)) * 60;
55
69
  return "".concat(degree, "\u02DA").concat(Math.floor(hour), "'").concat(minute.toFixed(2), "\"").concat(coord < 0 ? isLat ? "S" : "W" : isLat ? "N" : "E");
56
70
  };
@@ -76,11 +90,11 @@ var convertToDMS = function convertToDMS(coord) {
76
90
  * ```
77
91
  */
78
92
  var getLocationAsText = function getLocationAsText(latlon) {
79
- var _convertLatLng = convertLatLng(latlon),
80
- _convertLatLng2 = _slicedToArray(_convertLatLng, 2),
81
- lon = _convertLatLng2[0],
82
- lat = _convertLatLng2[1];
93
+ var _convertLatLng3 = convertLatLng(latlon),
94
+ _convertLatLng4 = _slicedToArray(_convertLatLng3, 2),
95
+ lon = _convertLatLng4[0],
96
+ lat = _convertLatLng4[1];
83
97
  return "".concat(convertToDMS(lat, true), ", ").concat(convertToDMS(lon));
84
98
  };
85
99
 
86
- export { convertLatLng, getLocationAsText };
100
+ export { convertLatLng, getLatitudeLongitude, getLocationAsText };
package/dist/esm/index.js CHANGED
@@ -12,8 +12,8 @@ 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';
16
- export { convertLatLng, getLocationAsText } from './_lonlat.js';
15
+ export { isArray, isBoolean, isColor, isDefined, isEmpty, isFalse, isNil, isNull, isNumber, isObject, isRtl, isString, isSvgPath, isTrue, isUndefined } from './_isType.js';
16
+ export { convertLatLng, getLatitudeLongitude, getLocationAsText } from './_lonlat.js';
17
17
  export { mergeRefs } from './_mergeRefs.js';
18
18
  export { iconToken, tokenize } from './_tokenize.js';
19
19
  export { getImageColorset } from './getImageColorset.js';
@@ -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:
@@ -1,4 +1,4 @@
1
- type LngLatLike = {
1
+ export type LngLatLike = {
2
2
  lng: number;
3
3
  lat: number;
4
4
  } | {
@@ -7,7 +7,11 @@ 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
+ export declare const getLatitudeLongitude: (lonLat: LngLatLike) => {
12
+ latitude: number;
13
+ longitude: number;
14
+ };
11
15
  /**
12
16
  * Convert various formats of longitude and latitude to a tuple of [lon, lat].
13
17
  * This function supports:
@@ -42,4 +46,3 @@ export declare const convertLatLng: (lonLat: LngLatLike) => [lon: number, lat: n
42
46
  * ```
43
47
  */
44
48
  export declare const getLocationAsText: (latlon: LngLatLike) => string;
45
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/utilities",
3
- "version": "1.0.0-beta.52",
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",
@@ -32,17 +32,17 @@
32
32
  "watch": "npm-run-all -p watch:rollup watch:dts"
33
33
  },
34
34
  "dependencies": {
35
- "date-fns": "^4.1.0",
36
- "libphonenumber-js": "^1.12.8",
37
- "numeral": "^2.0.6",
38
- "yup": "^1.4.0"
35
+ "date-fns": "~4.1.0",
36
+ "libphonenumber-js": "~1.12.25",
37
+ "numeral": "~2.0.6",
38
+ "yup": "~1.7.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/numeral": "^2.0.2"
41
+ "@types/numeral": "~2.0.5"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18.12.0",
45
45
  "npm": ">=8.19.0"
46
46
  },
47
- "gitHead": "0eabb9d88d91af93d657bcc209b226fd576e8260"
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(Boolean).length === 0) {
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,9 +21,9 @@
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
- type LngLatLike =
26
+ export type LngLatLike =
27
27
  | {
28
28
  lng: number;
29
29
  lat: number;
@@ -37,8 +37,16 @@ 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
 
43
+ export const getLatitudeLongitude = (
44
+ lonLat: LngLatLike,
45
+ ): { latitude: number; longitude: number } => {
46
+ const [lon, lat] = convertLatLng(lonLat);
47
+ return { latitude: lat, longitude: lon };
48
+ };
49
+
42
50
  /**
43
51
  * Convert various formats of longitude and latitude to a tuple of [lon, lat].
44
52
  * This function supports:
@@ -54,6 +62,9 @@ type LngLatLike =
54
62
  export const convertLatLng = (
55
63
  lonLat: LngLatLike,
56
64
  ): [lon: number, lat: number] => {
65
+ if (isEmpty(lonLat)) {
66
+ throw Error("Invalid geo coordinates");
67
+ }
57
68
  if (
58
69
  (isArray(lonLat) && lonLat.length === 2) ||
59
70
  (isArray(lonLat) && lonLat.length === 3)
@@ -70,7 +81,7 @@ export const convertLatLng = (
70
81
 
71
82
  if (isString(lonLat)) {
72
83
  const [lat, lon] = lonLat.split(",");
73
- return [+lon, +lat];
84
+ if (!isNaN(+lat) && !isNaN(+lon)) return [+lon, +lat];
74
85
  }
75
86
 
76
87
  throw Error("Invalid geo coordinates");
@@ -89,8 +100,8 @@ export const convertLatLng = (
89
100
  * @returns {string} A string representation of the coordinate in DMS format.
90
101
  */
91
102
  const convertToDMS = (coord: number, isLat = false) => {
92
- const degree = Math.floor(coord);
93
- const hour = (coord - degree) * 60;
103
+ const degree = Math.floor(Math.abs(coord));
104
+ const hour = (Math.abs(coord) - degree) * 60;
94
105
  const minute = (hour - Math.floor(hour)) * 60;
95
106
 
96
107
  return `${degree}˚${Math.floor(hour)}'${minute.toFixed(2)}"${