@hastehaul/common 2.12.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/build/utils/utils.d.ts +2 -2
- package/build/utils/utils.js +8 -33
- package/package.json +1 -1
package/build/utils/utils.d.ts
CHANGED
@@ -7,6 +7,6 @@ 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<any>;
|
12
12
|
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,21 +59,21 @@ function loadAsset(filePath) {
|
|
84
59
|
}
|
85
60
|
});
|
86
61
|
}
|
87
|
-
function isPointInGeoJSON(latLng,
|
62
|
+
function isPointInGeoJSON(latLng, fileName) {
|
88
63
|
return __awaiter(this, void 0, void 0, function* () {
|
89
64
|
try {
|
90
65
|
if (latLng.length === 0)
|
91
66
|
return false;
|
92
|
-
const geoJsonData = yield loadAsset(
|
67
|
+
const geoJsonData = yield loadAsset(fileName);
|
93
68
|
const geojson = JSON.parse(geoJsonData);
|
94
|
-
const
|
69
|
+
const points = (0, helpers_1.point)([latLng[1], latLng[0]]);
|
95
70
|
const isInside = geojson.features.some((feature) => {
|
96
71
|
const geometry = feature.geometry;
|
97
72
|
if (geometry.type === 'Polygon') {
|
98
|
-
return (0, boolean_point_in_polygon_1.default)(
|
73
|
+
return (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(geometry.coordinates));
|
99
74
|
}
|
100
75
|
else if (geometry.type === 'MultiPolygon') {
|
101
|
-
return geometry.coordinates.some((
|
76
|
+
return geometry.coordinates.some((poly) => (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(poly)));
|
102
77
|
}
|
103
78
|
return false;
|
104
79
|
});
|