@flumens/utils 0.0.1
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/README.md +1 -0
- package/dist/date.d.ts +16 -0
- package/dist/date.js +1 -0
- package/dist/device.d.ts +9 -0
- package/dist/device.js +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.js +1 -0
- package/dist/globals.d.ts +4 -0
- package/dist/globals.js +1 -0
- package/dist/image.d.ts +50 -0
- package/dist/image.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -0
- package/dist/location.d.ts +72 -0
- package/dist/location.js +1 -0
- package/dist/sentry.d.ts +9 -0
- package/dist/sentry.js +1 -0
- package/dist/string.d.ts +5 -0
- package/dist/string.js +1 -0
- package/dist/type.d.ts +51 -0
- package/dist/type.js +1 -0
- package/dist/uuid.d.ts +7 -0
- package/dist/uuid.js +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @flumens/models
|
package/dist/date.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const dateFormat: Intl.DateTimeFormat;
|
|
2
|
+
export declare const timeFormat: Intl.DateTimeFormat;
|
|
3
|
+
export declare const getRelativeDate: (date: string | number | Date) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Validates the date.
|
|
6
|
+
* @param date
|
|
7
|
+
* @returns {boolean}
|
|
8
|
+
*/
|
|
9
|
+
export declare const isValidDate: (date: string | number | Date) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the ISO date in the local time with timezone offset at the end.
|
|
12
|
+
* https://stackoverflow.com/a/17415677
|
|
13
|
+
* @param date
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const toISOTimezoneString: (date: Date) => string;
|
package/dist/date.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-i18next"),t=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"numeric",year:"numeric"}),a=new Intl.DateTimeFormat("en-GB",{hour:"numeric",minute:"numeric"});exports.dateFormat=t,exports.getRelativeDate=function(a){var n=new Date(a),r=t.format(n),o=new Date;if(t.format(o)===r)return(c=(e.getI18n()||{}).t)?c("Today"):"Today";var c,i=new Date;return i.setDate(i.getDate()-1),t.format(i)===r?(c=(e.getI18n()||{}).t)?c("Yesterday"):"Yesterday":r},exports.isValidDate=function(e){var t=new Date(e);return t instanceof Date&&!Number.isNaN(t)},exports.timeFormat=a,exports.toISOTimezoneString=function(e){var t=-e.getTimezoneOffset(),a=t>=0?"+":"-",n=function(e){return(e<10?"0":"")+e};return"".concat(e.getFullYear(),"-").concat(n(e.getMonth()+1),"-").concat(n(e.getDate()),"T").concat(n(e.getHours()),":").concat(n(e.getMinutes()),":").concat(n(e.getSeconds())).concat(a).concat(n(Math.floor(Math.abs(t)/60)),":").concat(n(Math.abs(t)%60))};
|
package/dist/device.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeviceInfo } from '@capacitor/device';
|
|
2
|
+
import { ConnectionType } from '@capacitor/network';
|
|
3
|
+
type DeviceType = {
|
|
4
|
+
isOnline: boolean;
|
|
5
|
+
connectionType: ConnectionType;
|
|
6
|
+
info?: DeviceInfo;
|
|
7
|
+
};
|
|
8
|
+
declare const device: DeviceType;
|
|
9
|
+
export default device;
|
package/dist/device.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("mobx"),t=require("@capacitor/device"),r=require("@capacitor/network"),i=n.observable({isOnline:!1,connectionType:"unknown",info:void 0});r.Network.addListener("networkStatusChange",(function(e){var n=e.connected;i.isOnline=n})),e.__awaiter(void 0,void 0,void 0,(function(){var n,t,o;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,r.Network.getStatus()];case 1:return n=e.sent(),t=n.connected,o=n.connectionType,i.isOnline=t,i.connectionType=o,[2]}}))})),e.__awaiter(void 0,void 0,void 0,(function(){var n;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,t.Device.getInfo()];case 1:return n=e.sent(),i.info=n,[2]}}))})),exports.default=i;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Error that should not be sent to the backend analytics. Can still be displayed
|
|
4
|
+
* to the user in the UI.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HandledError extends Error {
|
|
7
|
+
isHandled: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const isAxiosNetworkError: (error: AxiosError) => boolean;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),e=require("axios"),o=function(e){function o(){var r=null!==e&&e.apply(this,arguments)||this;return r.isHandled=!0,r}return r.__extends(o,e),o}(Error);exports.HandledError=o,exports.isAxiosNetworkError=function(r){return e.AxiosError.ETIMEDOUT===r.code||e.AxiosError.ECONNABORTED===r.code||e.AxiosError.ERR_CANCELED===r.code||e.AxiosError.ERR_NETWORK===r.code};
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GalleryPhoto, ImageOptions as ImageOptionsOriginal } from '@capacitor/camera';
|
|
2
|
+
export type URL = string;
|
|
3
|
+
export type ObjectURL = string;
|
|
4
|
+
export type DataURI = string;
|
|
5
|
+
/**
|
|
6
|
+
* Create an object URL from dataURI.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getObjectURL(dataURI: DataURI): ObjectURL;
|
|
9
|
+
export declare function saveFile(imageDataURL: URL, fileName: string): Promise<string>;
|
|
10
|
+
export declare function deleteFile(fileName: string): Promise<void>;
|
|
11
|
+
export declare const createImage: (url: URL | DataURI | ObjectURL) => Promise<HTMLImageElement>;
|
|
12
|
+
export declare function resizeImage({ url, fileType, MAX_WIDTH, MAX_HEIGHT, }: {
|
|
13
|
+
url: URL;
|
|
14
|
+
fileType?: string;
|
|
15
|
+
MAX_WIDTH?: number;
|
|
16
|
+
MAX_HEIGHT?: number;
|
|
17
|
+
}): Promise<[HTMLImageElement, DataURI]>;
|
|
18
|
+
type Area = {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Crops an image.
|
|
26
|
+
* @param imageURL
|
|
27
|
+
* @param crop
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function cropImage(imageURL: URL, crop: Area, rotation?: number): Promise<DataURI>;
|
|
31
|
+
type Options = Partial<ImageOptionsOriginal> & {
|
|
32
|
+
/**
|
|
33
|
+
* Should we use a camera instead of gallery.
|
|
34
|
+
*/
|
|
35
|
+
camera?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Should we allow to select multiple images from the gallery.
|
|
38
|
+
*/
|
|
39
|
+
multiple?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Call a custom photo capture implementation e.g. CameraPreview.
|
|
42
|
+
*/
|
|
43
|
+
getPhoto?: () => Promise<GalleryPhoto | null>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Gets a URL of the selected image from the camera or gallery.
|
|
47
|
+
* If none selected then URL is empty.
|
|
48
|
+
*/
|
|
49
|
+
export declare function captureImage(options?: Options): Promise<URL[]>;
|
|
50
|
+
export {};
|
package/dist/image.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@capacitor/camera"),r=require("@capacitor/core"),a=require("@capacitor/filesystem");function i(e){for(var t=e.split(",")[0].split(":")[1].split(";")[0],r=window.atob(e.split(",")[1]),a=[],i=0;i<r.length;i++)a.push(r.charCodeAt(i));var n=new Blob([new Uint8Array(a)],{type:t});return window.URL.createObjectURL(n)}var n=function(e){return new Promise((function(t,r){var a=new window.Image;a.onload=function(){return t(a)},a.onerror=function(e){return r(e)},a.src=e}))};function s(e){var t=e.url,r=e.fileType,a=void 0===r?"image/jpeg":r,i=e.MAX_WIDTH,n=void 0===i?2e3:i,s=e.MAX_HEIGHT,o=void 0===s?2e3:s,c=new Promise((function(e){var r=new window.Image;r.onload=function(){var t,i=r.width,s=r.height,c=null;i/=c=i>s?i/(n>i?i:n):s/(o>s?s:o),s/=c;var u=document.createElement("canvas");u.width=i,u.height=s,null===(t=u.getContext("2d"))||void 0===t||t.drawImage(r,0,0,i,s),e([r,u.toDataURL(a)])},r.src=t}));return c}function o(e){return e*Math.PI/180}function c(t){return e.__awaiter(this,void 0,void 0,(function(){var i,n,o;return e.__generator(this,(function(e){switch(e.label){case 0:return i="".concat(Date.now(),".jpeg"),[4,s({url:r.Capacitor.convertFileSrc(t)})];case 1:return n=e.sent(),o=n[1],[4,a.Filesystem.writeFile({path:i,data:o,directory:a.Directory.Data})];case 2:return e.sent(),[4,a.Filesystem.stat({path:i,directory:a.Directory.Data})];case 3:return[2,e.sent().uri]}}))}))}function u(r){return e.__awaiter(this,void 0,void 0,(function(){var a,i,n,s,o,c,u,h,l;return e.__generator(this,(function(d){switch(d.label){case 0:return a=r.camera,i=r.multiple,n=r.getPhoto,s=e.__rest(r,["camera","multiple","getPhoto"]),n?[4,n()]:[3,2];case 1:return[2,(h=d.sent())?[h]:[]];case 2:if(!i)return[3,6];d.label=3;case 3:return d.trys.push([3,5,,6]),o=e.__assign({quality:40,correctOrientation:!0,limit:30},s),[4,t.Camera.pickImages(o)];case 4:return[2,d.sent().photos];case 5:if(c=d.sent(),c.message.includes("User cancelled photos app")||c.message.includes("No images picked"))return[2,[]];throw c;case 6:return d.trys.push([6,8,,9]),u=e.__assign({quality:40,allowEditing:!1,saveToGallery:!0,webUseInput:!0,correctOrientation:!0,resultType:t.CameraResultType.Uri,source:a?t.CameraSource.Camera:t.CameraSource.Photos},s),[4,t.Camera.getPhoto(u)];case 7:return[2,[h=d.sent()]];case 8:if(l=d.sent(),l.message.includes("User cancelled photos app")||l.message.includes("No image picked"))return[2,[]];throw l;case 9:return[2]}}))}))}exports.captureImage=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,(function(){var r,a,i,n,s,o;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,u(t)];case 1:r=e.sent(),a=[],i=0,n=r,e.label=2;case 2:return i<n.length?(s=n[i]).path?[4,c(s.path)]:(s.webPath&&a.push(s.webPath),[3,4]):[3,5];case 3:o=e.sent(),a.push(o),e.label=4;case 4:return i++,[3,2];case 5:return[2,a]}}))}))},exports.createImage=n,exports.cropImage=function(t,r,a){return void 0===a&&(a=0),e.__awaiter(this,void 0,void 0,(function(){var i,s,c,u,h,l,d,p,w;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,n(t)];case 1:return i=e.sent(),s=document.createElement("canvas"),(c=s.getContext("2d"))?(u=o(a),h=function(e,t,r){var a=o(r);return{width:Math.abs(Math.cos(a)*e)+Math.abs(Math.sin(a)*t),height:Math.abs(Math.sin(a)*e)+Math.abs(Math.cos(a)*t)}}(i.width,i.height,a),l=h.width,d=h.height,s.width=l,s.height=d,c.translate(l/2,d/2),c.rotate(u),c.translate(-i.width/2,-i.height/2),c.drawImage(i,0,0),p=document.createElement("canvas"),(w=p.getContext("2d"))?(p.width=r.width,p.height=r.height,w.drawImage(s,r.x,r.y,r.width,r.height,0,0,r.width,r.height),[2,p.toDataURL()]):[2,""]):[2,""]}}))}))},exports.deleteFile=function(t){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return r.Capacitor.isNativePlatform()?[4,a.Filesystem.deleteFile({path:t,directory:a.Directory.Data})]:[2];case 1:return e.sent(),[2]}}))}))},exports.getObjectURL=i,exports.resizeImage=s,exports.saveFile=function(t,n){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return r.Capacitor.isNativePlatform()?[4,a.Filesystem.writeFile({path:n,data:t,directory:a.Directory.Data})]:[2,i(t)];case 1:return e.sent(),[4,a.Filesystem.stat({path:n,directory:a.Directory.Data})];case 2:return[2,e.sent().uri]}}))}))};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./string.js"),r=require("./device.js"),t=require("./date.js"),o=require("./image.js"),i=require("./location.js"),s=require("./sentry.js"),a=require("./errors.js");exports.string=e.default,exports.device=r.default,exports.dateFormat=t.dateFormat,exports.getRelativeDate=t.getRelativeDate,exports.isValidDate=t.isValidDate,exports.timeFormat=t.timeFormat,exports.toISOTimezoneString=t.toISOTimezoneString,exports.captureImage=o.captureImage,exports.createImage=o.createImage,exports.cropImage=o.cropImage,exports.deleteFile=o.deleteFile,exports.getObjectURL=o.getObjectURL,exports.resizeImage=o.resizeImage,exports.saveFile=o.saveFile,exports.checkGridType=i.checkGridType,exports.doesExceedGridRef=i.doesExceedGridRef,exports.getGridSquareCenter=i.getGridSquareCenter,exports.gridrefAccuracy=i.gridrefAccuracy,exports.gridrefStringToLatLng=i.gridrefStringToLatLng,exports.isInGB=i.isInGB,exports.isValidGridRef=i.isValidGridRef,exports.isValidLocation=i.isValidLocation,exports.locationToGrid=i.locationToGrid,exports.normalizeCoords=i.normalizeCoords,exports.normalizeGridRefAcc=i.normalizeGridRefAcc,exports.parseGrid=i.parseGrid,exports.prettyPrintGridRef=i.prettyPrintGridRef,exports.prettyPrintLocation=i.prettyPrintLocation,exports.updateModelLocation=i.updateModelLocation,exports.options=s.options,exports.HandledError=a.HandledError,exports.isAxiosNetworkError=a.isAxiosNetworkError;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Polygon, LineString } from 'geojson';
|
|
2
|
+
export type Location = {
|
|
3
|
+
latitude: number;
|
|
4
|
+
longitude: number;
|
|
5
|
+
gridref?: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
accuracy?: number;
|
|
8
|
+
altitude?: number;
|
|
9
|
+
altitudeAccuracy?: number;
|
|
10
|
+
shape?: LineString | Polygon;
|
|
11
|
+
geocoded?: {
|
|
12
|
+
center: [number, number];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const gridrefAccuracy: any;
|
|
16
|
+
export declare function prettyPrintGridRef(gridRef: string): string;
|
|
17
|
+
export declare function locationToGrid(location: Location): any;
|
|
18
|
+
export declare function parseGrid(gridrefString: string): any;
|
|
19
|
+
export declare function gridrefStringToLatLng(gridrefString: string): any;
|
|
20
|
+
export declare function isValidGridRef(gridrefString: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {type} location
|
|
24
|
+
* @returns {Boolean}
|
|
25
|
+
*/
|
|
26
|
+
export declare function isInGB(location: Location): boolean;
|
|
27
|
+
export declare function updateModelLocation(model: any, location: Location, skipGridRef?: boolean): Promise<void>;
|
|
28
|
+
export declare function prettyPrintLocation(location: any): string;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if location gridref size matches the provided one.
|
|
31
|
+
* @param location
|
|
32
|
+
* @param gridRefSize
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
export declare function checkGridType(location: any, gridRefSize: any): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the location fits in the calculated grid reference square.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
export declare function doesExceedGridRef(gridCoords: any, location: any, normAcc: any): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a normalized grid square that takes into account the accuracy
|
|
43
|
+
* of the location.
|
|
44
|
+
+
|
|
45
|
+
| OK Not OK
|
|
46
|
+
|
|
|
47
|
+
| +------------+ +------------+
|
|
48
|
+
| | | | |
|
|
49
|
+
| | +------+ | | |
|
|
50
|
+
| | | | | | |
|
|
51
|
+
| | | XX | | | +------+
|
|
52
|
+
| | | | | | | | |
|
|
53
|
+
| | +------+ | | | XX| |
|
|
54
|
+
| +------------+ +------------+ |
|
|
55
|
+
| +------+
|
|
56
|
+
* @param gridCoords
|
|
57
|
+
* @param location
|
|
58
|
+
* @param normAcc
|
|
59
|
+
* @returns {*}
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizeGridRefAcc(gridCoords: any, location: any, normAcc: any): any;
|
|
62
|
+
export declare function getGridSquareCenter(gridref: string): any;
|
|
63
|
+
type LatLng = {
|
|
64
|
+
lat: number;
|
|
65
|
+
lng: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Normalises Mapbox longitude being > 180 or < -180.
|
|
69
|
+
*/
|
|
70
|
+
export declare const normalizeCoords: ({ lat, lng }: LatLng) => LatLng;
|
|
71
|
+
export declare const isValidLocation: (location?: Location | null) => boolean;
|
|
72
|
+
export {};
|
package/dist/location.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(require("@flumens/bigu")),a={tetrad:{label:"Tetrad (2km square)",length:5},monad:{label:"Monad (1km square)",length:6}};function n(t){var e=t.match(/^([A-Z]*)\d/i)[1],r=t.replace(e,""),a=r.length;if(a%2)return"".concat(e," ").concat(r);var n=r.slice(0,a/2),i=r.slice(a/2);return"".concat(e," ").concat(n," ").concat(i)}function i(t){var e=r.default.latlng_to_grid_coords(t.latitude,t.longitude);if(!e||!Number.isFinite(t.accuracy))return null;var a=r.default.GridRefParser.get_normalized_precision(2*t.accuracy);return e.to_gridref(a)}function o(t,e,r){var a=e.accuracy,n=t.x,i=t.y;return n%r-a<0||(n%r+a>r||(i%r-a<0||i%r+a>r))}exports.checkGridType=function(t,e){if(!e)return!1;var r=t.gridref||"",n=a[e].length;return/^.\d/.test(r)&&(n-=1),r.length===n},exports.doesExceedGridRef=o,exports.getGridSquareCenter=function(t){var e=r.default.GridRefParser.factory(t);if(!e)return null;var a=e.osRef;return new e.NationalRef(a.x+e.length/2,a.y+e.length/2).to_latLng()},exports.gridrefAccuracy=a,exports.gridrefStringToLatLng=function(t){try{var e=r.default.GridRefParser.factory(t);return e?e.osRef.to_latLng():null}catch(t){console.error(t.message)}return null},exports.isInGB=function(t){if(t.latitude){var e=r.default.latlng_to_grid_coords(t.latitude,t.longitude);return!!e&&"GB"===e.country}return!1},exports.isValidGridRef=function(t){try{var e=r.default.GridRefParser.factory(t);return!(!e||!r.default.MappingUtils.is_gb_hectad(e.hectad))}catch(t){console.error(t.message)}return!1},exports.isValidLocation=function(t){return Number.isFinite(null==t?void 0:t.latitude)&&Number.isFinite(null==t?void 0:t.longitude)},exports.locationToGrid=i,exports.normalizeCoords=function(t){var e=t.lat,r=t.lng;return r>180?{lat:e,lng:r-180-180}:r<-180?{lat:e,lng:180+(r+180)}:{lat:e,lng:r}},exports.normalizeGridRefAcc=function t(e,r,a){return a>=1e4?null:o(e,r,a)?t(e,r,10*a):e.to_gridref(a)},exports.parseGrid=function(t){var e,a=r.default.GridRefParser.factory(t);return a&&(a.osRef.x+=a.length/2,a.osRef.y+=a.length/2,e=a.osRef),e},exports.prettyPrintGridRef=n,exports.prettyPrintLocation=function(t){if(!t||!t.latitude)return"";if(t.gridref)return n(t.gridref);t.accuracy;var e=i(t);return e?n(e):"".concat(parseFloat(t.latitude).toFixed(4),", ").concat(parseFloat(t.longitude).toFixed(4))},exports.updateModelLocation=function(e,r,a){return void 0===a&&(a=!1),t.__awaiter(this,void 0,void 0,(function(){var n,o,c;return t.__generator(this,(function(u){switch(u.label){case 0:return e.metadata.deleted?(console.warn("LocationUtils: skipping deleted model location set"),[2]):((n=t.__assign({},r)).latitude=parseFloat(parseFloat("".concat(n.latitude)).toFixed(5)),n.longitude=parseFloat(parseFloat("".concat(n.longitude)).toFixed(5)),(n.accuracy||Number.isFinite(n.accuracy))&&(n.accuracy=parseFloat(parseFloat("".concat(n.accuracy)).toFixed(2))),(n.altitude||Number.isFinite(n.altitude))&&(n.altitude=parseFloat(parseFloat("".concat(n.altitude)).toFixed(2))),(n.altitudeAccuracy||Number.isFinite(n.altitudeAccuracy))&&(n.altitudeAccuracy=parseFloat(parseFloat("".concat(n.altitudeAccuracy)).toFixed(2))),n.source="gps",a||(n.gridref=i(n)),o=e.attrs.location,c=t.__assign(t.__assign({},o),n),e.setGPSLocation?[4,e.setGPSLocation(c)]:[3,2]);case 1:case 3:return u.sent(),[2];case 2:return e.attrs.location=c,[4,e.save()]}}))}))};
|
package/dist/sentry.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function beforeBreadcrumb(crumb: any, hint: any): any;
|
|
2
|
+
export declare const options: {
|
|
3
|
+
maxBreadcrumbs: number;
|
|
4
|
+
ignoreErrors: string[];
|
|
5
|
+
beforeSend: (event: any) => any;
|
|
6
|
+
beforeBreadcrumb: typeof beforeBreadcrumb;
|
|
7
|
+
integrations: any[];
|
|
8
|
+
};
|
|
9
|
+
export {};
|
package/dist/sentry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sentry/integrations");function t(e){return e.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"UUID")}var a=["Unable to preventDefault inside passive event listener invocation.","Incorrect password or email","AbortError: Fetch is aborted","Attempted to load an infinite number of tiles","No images picked","User cancelled photos app","No image picked","User denied access to camera","User denied access to photos","Failed to fetch"],r={maxBreadcrumbs:400,ignoreErrors:a,beforeSend:function(e){var t,r;if("[object Object]"===e.message){var o=((null===(r=null===(t=e.extra)||void 0===t?void 0:t.arguments)||void 0===r?void 0:r[0])||{}).message;if(!o||a.includes(o))return null;e.message=o}return e},beforeBreadcrumb:function(e,a){if("navigation"===e.category)return e.data={to:t(e.data.to),from:t(e.data.from)},e;if(e.category.startsWith("ui")){var r=a.event.target,o=r.innerText,n=r.dataset;o&&o.length<15&&(e.message="[".concat(o,"] ").concat(e.message)),n.label&&(e.message="[".concat(n.label,"] ").concat(e.message))}if(["xhr","fetch"].includes(e.category)){if(e.data.url.startsWith("data:"))return null;"GET"===e.data.method&&e.data.url.match(/jpeg$/i)&&(e.data.url=e.data.url.replace(/files\/\d+\.jpeg/i,"files/FILENAME.jpeg"))}return e},integrations:[new e.CaptureConsole({levels:["error"]}),new e.Dedupe]};exports.options=r;
|
package/dist/string.d.ts
ADDED
package/dist/string.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={limit:function(e,t){if(void 0===t&&(t=20),!e)return"";var r=e.toString(),n=r&&r.length>t?"...":"";return r?r.substring(0,t)+n:""},escape:function(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e.toString())),t.innerHTML.trim()}};exports.default=e;
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructs a type that will pick only those properties that are typeof Value.
|
|
3
|
+
*
|
|
4
|
+
* https://stackoverflow.com/questions/46583883/typescript-pick-properties-with-a-defined-type
|
|
5
|
+
*/
|
|
6
|
+
export type PickByType<T, Value> = {
|
|
7
|
+
[P in keyof T as T[P] extends Value | undefined ? P : never]: T[P];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Like Partial but creates recursive partial deep type;
|
|
11
|
+
*/
|
|
12
|
+
export type PartialDeep<K> = {
|
|
13
|
+
[attr in keyof K]?: K[attr] extends object ? PartialDeep<K[attr]> : K[attr];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Makes selected keys optional.
|
|
17
|
+
*
|
|
18
|
+
* Optional<{a; b; c}, 'b'>
|
|
19
|
+
*
|
|
20
|
+
* {a; c}
|
|
21
|
+
* Omit<T, K>
|
|
22
|
+
* &
|
|
23
|
+
* {a?; b?; c?}
|
|
24
|
+
* Partial<T>;
|
|
25
|
+
* =
|
|
26
|
+
* {a; b?; c}
|
|
27
|
+
*/
|
|
28
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Makes all optional except selected keys.
|
|
31
|
+
*
|
|
32
|
+
* OptionalExcept<{a; b; c}, 'a' | 'c'>
|
|
33
|
+
*
|
|
34
|
+
* {a; c;}
|
|
35
|
+
* Pick<T, K>
|
|
36
|
+
* &
|
|
37
|
+
* {a?; b?; c?}
|
|
38
|
+
* Partial<T>;
|
|
39
|
+
* =
|
|
40
|
+
* {a; b?; c}
|
|
41
|
+
*/
|
|
42
|
+
export type OptionalExcept<T, K extends keyof T> = Pick<T, K> & Partial<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Transforms snake-case keys to camel-case.
|
|
45
|
+
* https://medium.com/@fullstack-shepherd/typescript-transforming-types-with-snake-case-keys-to-camelcase-keys-or-how-to-keep-busy-in-9d5f074d9bfa
|
|
46
|
+
*/
|
|
47
|
+
type Camelize<T extends string> = T extends `${infer A}_${infer B}` ? `${A}${Camelize<Capitalize<B>>}` : T;
|
|
48
|
+
export type CamelizeKeys<T extends object> = {
|
|
49
|
+
[key in keyof T as key extends string ? Camelize<key> : key]: T[key];
|
|
50
|
+
};
|
|
51
|
+
export {};
|
package/dist/type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/uuid.d.ts
ADDED
package/dist/uuid.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r,e,a=(t=function(t){return crypto.getRandomValues(t)},r=-1,e=0,function(){var a=Math.max(Date.now(),r);e=a===r?e+1:0,r=a;var n=new Uint32Array(2);t(n),n[0]=2<<30|n[0]>>>2;var o=a.toString(16).padStart(12,"0")+"7"+e.toString(16).padStart(3,"0")+n[0].toString(16).padStart(8,"0")+n[1].toString(16).padStart(8,"0");return o.slice(0,8)+"-"+o.slice(8,12)+"-"+o.slice(12,16)+"-"+o.slice(16,20)+"-"+o.slice(20)});exports.default=a,exports.hashCode=function(t){var r,e=0;if(0===t.length)return e;for(r=0;r<t.length;r++)e=(e<<5)-e+t.charCodeAt(r),e|=0;return e};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flumens/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/src/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rollup -c",
|
|
8
|
+
"build:watch": "rollup -c -w",
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"test:eslint": "eslint src --quiet --ext .jsx --ext .ts --ext .tsx --ext .js && echo '\\033[37;42;1m PASS \\033[00m'",
|
|
11
|
+
"postpublish": "TAG_NAME=models-v\"$npm_package_version\" && git tag $TAG_NAME && git push origin \"$TAG_NAME\"",
|
|
12
|
+
"test": "jest --passWithNoTests",
|
|
13
|
+
"test:watch": "jest --watchAll"
|
|
14
|
+
},
|
|
15
|
+
"author": "Flumens",
|
|
16
|
+
"license": "GNU GPL v3",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@rollup/plugin-json": "6.0.0",
|
|
19
|
+
"@rollup/plugin-node-resolve": "13.3.0",
|
|
20
|
+
"@rollup/plugin-typescript": "8.3.2",
|
|
21
|
+
"@trivago/prettier-plugin-sort-imports": "4.3.0",
|
|
22
|
+
"@types/react": "18.2.38",
|
|
23
|
+
"@types/react-dom": "18.2.17",
|
|
24
|
+
"prettier": "3.2.5",
|
|
25
|
+
"react": "^18.2.0",
|
|
26
|
+
"react-dom": "^18.2.0",
|
|
27
|
+
"rollup-plugin-clear": "2.0.7",
|
|
28
|
+
"rollup-plugin-terser": "7.0.2",
|
|
29
|
+
"tslib": "2.6.2",
|
|
30
|
+
"typescript": "4.9.4"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {},
|
|
33
|
+
"optionalDependencies": {
|
|
34
|
+
"react-i18next": "^14 || ^15",
|
|
35
|
+
"mobx": "^6",
|
|
36
|
+
"@capacitor/device": "^5 || ^6",
|
|
37
|
+
"@capacitor/network": "^5 || ^6",
|
|
38
|
+
"axios": "^1",
|
|
39
|
+
"@capacitor/camera": "^5 || ^6",
|
|
40
|
+
"@capacitor/core": "^5 || ^6",
|
|
41
|
+
"@capacitor/filesystem": "^5 || ^6",
|
|
42
|
+
"geojson": "0.5.0",
|
|
43
|
+
"@flumens/bigu": "^0.4.0",
|
|
44
|
+
"@sentry/integrations": "^7 || ^8"
|
|
45
|
+
},
|
|
46
|
+
"jest": {
|
|
47
|
+
"testEnvironment": "jsdom",
|
|
48
|
+
"preset": "ts-jest",
|
|
49
|
+
"moduleNameMapper": {
|
|
50
|
+
"^.+.(css|style|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
|
|
51
|
+
},
|
|
52
|
+
"testPathIgnorePatterns": [
|
|
53
|
+
"node_modules",
|
|
54
|
+
"dist"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {}
|
|
58
|
+
}
|