@react-fabric/utilities 1.0.0-beta.47 → 1.0.0-beta.49

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.
@@ -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;
@@ -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';
@@ -1,4 +1,4 @@
1
- export declare const dedupe: (list: any[], key?: string) => any[];
2
- export declare const flatten: (list: any[]) => any[];
3
- export declare const flattenAndDedupe: (list?: any[], key?: string) => any[];
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[]>;
@@ -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 {};
@@ -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.47",
3
+ "version": "1.0.0-beta.49",
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.0.0",
36
- "libphonenumber-js": "^1.11.8",
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": "832a1bce055337127ba17c505731f419248cc15e"
47
+ "gitHead": "29b3ed65e9f9687d738dd7c6facdb9fedafb4219"
48
48
  }
package/src/_dedupe.ts CHANGED
@@ -23,21 +23,26 @@
23
23
 
24
24
  import { isEmpty } from "./_isType";
25
25
 
26
- export const dedupe = (list: any[], key?: string) => {
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
- return Array.from(new Map(filtered.map((obj) => [obj[key], obj])).values());
32
+ return Array.from(
33
+ new Map(filtered.map((obj) => [(obj as KeyValue)[key], obj])).values(),
34
+ );
33
35
  };
34
36
 
35
- export const flatten = (list: any[]) => {
37
+ export const flatten = <T extends AnyObject>(list: T[]) => {
36
38
  return list.flat(5).filter((i) => !isEmpty(i));
37
39
  };
38
40
 
39
- export const flattenAndDedupe = (list: any[] = [], key?: string) => {
40
- return dedupe(flatten(list), key);
41
+ export const flattenAndDedupe = <T extends AnyObject>(
42
+ list: T[][] = [],
43
+ key?: keyof T,
44
+ ) => {
45
+ return dedupe(flatten(list) as T[], key);
41
46
  };
42
47
 
43
48
  export const groupBy = <T extends KeyValue>(
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/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";