@hastehaul/common 2.12.0 → 2.14.0
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/build/utils/utils.d.ts +8 -2
- package/build/utils/utils.js +39 -40
- package/package.json +1 -1
package/build/utils/utils.d.ts
CHANGED
@@ -7,6 +7,12 @@ export declare function colorize(text: string, colorCode: number): string;
|
|
7
7
|
export declare function formatDatetimeToHumanReadable(datetime: Date, format?: string): string;
|
8
8
|
export declare function generateIdentifier(messageContent: string): string;
|
9
9
|
export declare function getValueFromSettings(settings: Setting[], key: string, envVar?: string, defaultValue?: any): any;
|
10
|
-
export declare function loadAsset(
|
11
|
-
export declare function isPointInGeoJSON(latLng:
|
10
|
+
export declare function loadAsset(relativePath: string): Promise<string | null>;
|
11
|
+
export declare function isPointInGeoJSON(latLng: string | any[], fileName: string): Promise<{
|
12
|
+
isInside: boolean;
|
13
|
+
properties: any;
|
14
|
+
} | {
|
15
|
+
isInside: null;
|
16
|
+
properties: null;
|
17
|
+
}>;
|
12
18
|
export {};
|
package/build/utils/utils.js
CHANGED
@@ -1,27 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -43,10 +20,9 @@ exports.getValueFromSettings = getValueFromSettings;
|
|
43
20
|
exports.loadAsset = loadAsset;
|
44
21
|
exports.isPointInGeoJSON = isPointInGeoJSON;
|
45
22
|
const boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon"));
|
46
|
-
const helpers_1 =
|
23
|
+
const helpers_1 = require("@turf/helpers");
|
47
24
|
const moment_1 = __importDefault(require("moment"));
|
48
25
|
const fs_1 = require("fs");
|
49
|
-
const path = __importStar(require("path"));
|
50
26
|
function hasElapsed(expirationDate) {
|
51
27
|
const currentDate = (0, moment_1.default)();
|
52
28
|
const targetDate = (0, moment_1.default)(expirationDate);
|
@@ -71,11 +47,10 @@ function getValueFromSettings(settings, key, envVar, defaultValue) {
|
|
71
47
|
}
|
72
48
|
return process.env[envVar] || defaultValue;
|
73
49
|
}
|
74
|
-
function loadAsset(
|
50
|
+
function loadAsset(relativePath) {
|
75
51
|
return __awaiter(this, void 0, void 0, function* () {
|
76
52
|
try {
|
77
|
-
const
|
78
|
-
const fileContent = yield fs_1.promises.readFile(file, 'utf-8');
|
53
|
+
const fileContent = yield fs_1.promises.readFile(relativePath, 'utf-8');
|
79
54
|
return fileContent;
|
80
55
|
}
|
81
56
|
catch (error) {
|
@@ -84,29 +59,53 @@ function loadAsset(filePath) {
|
|
84
59
|
}
|
85
60
|
});
|
86
61
|
}
|
87
|
-
function
|
62
|
+
// export async function isPointInGeoJSONw(latLng: string | any[], fileName: string) {
|
63
|
+
// try {
|
64
|
+
// if(latLng.length === 0) return false
|
65
|
+
// const geoJsonData = await loadAsset(fileName);
|
66
|
+
// const geojson = JSON.parse(geoJsonData!);
|
67
|
+
// const points = point([latLng[1], latLng[0]]);
|
68
|
+
// const isInside = geojson.features.some((feature: { geometry: any; }) => {
|
69
|
+
// const geometry = feature.geometry;
|
70
|
+
// if (geometry.type === 'Polygon') {
|
71
|
+
// return booleanPointInPolygon(points, polygon(geometry.coordinates));
|
72
|
+
// } else if (geometry.type === 'MultiPolygon') {
|
73
|
+
// return geometry.coordinates.some((poly: Position[][]) => booleanPointInPolygon(points, polygon(poly)));
|
74
|
+
// }
|
75
|
+
// return false;
|
76
|
+
// });
|
77
|
+
// return isInside;
|
78
|
+
// } catch (error) {
|
79
|
+
// console.error(`Error checking point in GeoJSON: ${error}`);
|
80
|
+
// return null;
|
81
|
+
// }
|
82
|
+
// }
|
83
|
+
function isPointInGeoJSON(latLng, fileName) {
|
88
84
|
return __awaiter(this, void 0, void 0, function* () {
|
89
85
|
try {
|
90
|
-
if (latLng.length === 0)
|
91
|
-
return false;
|
92
|
-
const geoJsonData = yield loadAsset(
|
86
|
+
if (!latLng || latLng.length === 0)
|
87
|
+
return { isInside: false, properties: null };
|
88
|
+
const geoJsonData = yield loadAsset(fileName);
|
93
89
|
const geojson = JSON.parse(geoJsonData);
|
94
|
-
const
|
95
|
-
const
|
90
|
+
const points = (0, helpers_1.point)([latLng[1], latLng[0]]);
|
91
|
+
for (const feature of geojson.features) {
|
96
92
|
const geometry = feature.geometry;
|
97
93
|
if (geometry.type === 'Polygon') {
|
98
|
-
|
94
|
+
if ((0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(geometry.coordinates))) {
|
95
|
+
return { isInside: true, properties: feature.properties };
|
96
|
+
}
|
99
97
|
}
|
100
98
|
else if (geometry.type === 'MultiPolygon') {
|
101
|
-
|
99
|
+
if (geometry.coordinates.some((poly) => (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(poly)))) {
|
100
|
+
return { isInside: true, properties: feature.properties };
|
101
|
+
}
|
102
102
|
}
|
103
|
-
|
104
|
-
}
|
105
|
-
return isInside;
|
103
|
+
}
|
104
|
+
return { isInside: false, properties: null };
|
106
105
|
}
|
107
106
|
catch (error) {
|
108
107
|
console.error(`Error checking point in GeoJSON: ${error}`);
|
109
|
-
return null;
|
108
|
+
return { isInside: null, properties: null };
|
110
109
|
}
|
111
110
|
});
|
112
111
|
}
|