@trackunit/geo-json-utils 1.0.2 → 1.0.5

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/index.cjs.js CHANGED
@@ -363,32 +363,30 @@ const getPointCoordinateFromGeoJsonPoint = (point) => {
363
363
  * @returns {GeoJsonPoint} The extreme point in the given direction
364
364
  */
365
365
  const getExtremeGeoJsonPointFromPolygon = ({ polygon, direction, }) => {
366
- var _a, _b, _c;
367
366
  const polygonParsed = geoJsonPolygonSchema.safeParse(polygon);
368
367
  if (!polygonParsed.success) {
369
368
  return null;
370
369
  }
371
- const firstPoint = (_a = polygonParsed.data.coordinates[0]) === null || _a === void 0 ? void 0 : _a[0];
370
+ const firstPoint = polygonParsed.data.coordinates[0]?.[0];
372
371
  if (!firstPoint) {
373
372
  // Should never happen since the schema checks for it
374
373
  return null;
375
374
  }
376
- const extremePosition = (_b = polygonParsed.data.coordinates[0]) === null || _b === void 0 ? void 0 : _b.reduce((extremePoint, currentPoint) => {
377
- var _a, _b, _c, _d;
375
+ const extremePosition = polygonParsed.data.coordinates[0]?.reduce((extremePoint, currentPoint) => {
378
376
  switch (direction) {
379
377
  case "top":
380
- return currentPoint[1] > ((_a = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[1]) !== null && _a !== void 0 ? _a : -Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
378
+ return currentPoint[1] > (extremePoint?.[1] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
381
379
  case "right":
382
- return currentPoint[0] > ((_b = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[0]) !== null && _b !== void 0 ? _b : -Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
380
+ return currentPoint[0] > (extremePoint?.[0] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
383
381
  case "bottom":
384
- return currentPoint[1] < ((_c = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[1]) !== null && _c !== void 0 ? _c : Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
382
+ return currentPoint[1] < (extremePoint?.[1] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
385
383
  case "left":
386
- return currentPoint[0] < ((_d = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[0]) !== null && _d !== void 0 ? _d : Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
384
+ return currentPoint[0] < (extremePoint?.[0] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
387
385
  default: {
388
386
  throw new Error(`${direction} is not known`);
389
387
  }
390
388
  }
391
- }, (_c = polygonParsed.data.coordinates[0]) === null || _c === void 0 ? void 0 : _c[0]);
389
+ }, polygonParsed.data.coordinates[0]?.[0]);
392
390
  return extremePosition
393
391
  ? {
394
392
  type: "Point",
@@ -595,7 +593,7 @@ const tuGeoJsonRectangularBoxPolygonSchema = zod.z
595
593
  .superRefine((data, ctx) => {
596
594
  const coordinates = data.coordinates[0];
597
595
  // Validate polygon has exactly 5 points
598
- if ((coordinates === null || coordinates === void 0 ? void 0 : coordinates.length) !== 5) {
596
+ if (coordinates?.length !== 5) {
599
597
  ctx.addIssue({
600
598
  code: zod.z.ZodIssueCode.custom,
601
599
  message: "Polygon must have exactly 5 coordinates to form a closed box.",
package/index.esm.js CHANGED
@@ -361,32 +361,30 @@ const getPointCoordinateFromGeoJsonPoint = (point) => {
361
361
  * @returns {GeoJsonPoint} The extreme point in the given direction
362
362
  */
363
363
  const getExtremeGeoJsonPointFromPolygon = ({ polygon, direction, }) => {
364
- var _a, _b, _c;
365
364
  const polygonParsed = geoJsonPolygonSchema.safeParse(polygon);
366
365
  if (!polygonParsed.success) {
367
366
  return null;
368
367
  }
369
- const firstPoint = (_a = polygonParsed.data.coordinates[0]) === null || _a === void 0 ? void 0 : _a[0];
368
+ const firstPoint = polygonParsed.data.coordinates[0]?.[0];
370
369
  if (!firstPoint) {
371
370
  // Should never happen since the schema checks for it
372
371
  return null;
373
372
  }
374
- const extremePosition = (_b = polygonParsed.data.coordinates[0]) === null || _b === void 0 ? void 0 : _b.reduce((extremePoint, currentPoint) => {
375
- var _a, _b, _c, _d;
373
+ const extremePosition = polygonParsed.data.coordinates[0]?.reduce((extremePoint, currentPoint) => {
376
374
  switch (direction) {
377
375
  case "top":
378
- return currentPoint[1] > ((_a = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[1]) !== null && _a !== void 0 ? _a : -Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
376
+ return currentPoint[1] > (extremePoint?.[1] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
379
377
  case "right":
380
- return currentPoint[0] > ((_b = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[0]) !== null && _b !== void 0 ? _b : -Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
378
+ return currentPoint[0] > (extremePoint?.[0] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
381
379
  case "bottom":
382
- return currentPoint[1] < ((_c = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[1]) !== null && _c !== void 0 ? _c : Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
380
+ return currentPoint[1] < (extremePoint?.[1] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
383
381
  case "left":
384
- return currentPoint[0] < ((_d = extremePoint === null || extremePoint === void 0 ? void 0 : extremePoint[0]) !== null && _d !== void 0 ? _d : Infinity) ? currentPoint : (extremePoint !== null && extremePoint !== void 0 ? extremePoint : currentPoint);
382
+ return currentPoint[0] < (extremePoint?.[0] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
385
383
  default: {
386
384
  throw new Error(`${direction} is not known`);
387
385
  }
388
386
  }
389
- }, (_c = polygonParsed.data.coordinates[0]) === null || _c === void 0 ? void 0 : _c[0]);
387
+ }, polygonParsed.data.coordinates[0]?.[0]);
390
388
  return extremePosition
391
389
  ? {
392
390
  type: "Point",
@@ -593,7 +591,7 @@ const tuGeoJsonRectangularBoxPolygonSchema = z
593
591
  .superRefine((data, ctx) => {
594
592
  const coordinates = data.coordinates[0];
595
593
  // Validate polygon has exactly 5 points
596
- if ((coordinates === null || coordinates === void 0 ? void 0 : coordinates.length) !== 5) {
594
+ if (coordinates?.length !== 5) {
597
595
  ctx.addIssue({
598
596
  code: z.ZodIssueCode.custom,
599
597
  message: "Polygon must have exactly 5 coordinates to form a closed box.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/geo-json-utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {