@konfirm/geojson 1.0.0 → 1.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.
Files changed (127) hide show
  1. package/README.md +7 -7
  2. package/dist/{geojson.d.ts → main.d.mts} +18 -79
  3. package/dist/main.d.ts +137 -15
  4. package/dist/main.global.js +853 -0
  5. package/dist/main.global.js.map +1 -0
  6. package/dist/main.js +824 -0
  7. package/dist/main.js.map +1 -0
  8. package/dist/main.mjs +772 -0
  9. package/dist/main.mjs.map +1 -0
  10. package/package.json +101 -63
  11. package/.editorconfig +0 -16
  12. package/.github/workflows/release.yml +0 -21
  13. package/.github/workflows/tests.yml +0 -56
  14. package/CHANGELOG.md +0 -21
  15. package/dist/Domain/Constants.d.ts +0 -5
  16. package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +0 -3
  17. package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +0 -6
  18. package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +0 -4
  19. package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +0 -11
  20. package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +0 -4
  21. package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +0 -3
  22. package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +0 -4
  23. package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +0 -3
  24. package/dist/Domain/GeoJSON/Concept/Position.d.ts +0 -7
  25. package/dist/Domain/GeoJSON/Feature.d.ts +0 -12
  26. package/dist/Domain/GeoJSON/FeatureCollection.d.ts +0 -8
  27. package/dist/Domain/GeoJSON/GeoJSON.d.ts +0 -7
  28. package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +0 -11
  29. package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +0 -7
  30. package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +0 -8
  31. package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +0 -7
  32. package/dist/Domain/GeoJSON/Geometry/Point.d.ts +0 -11
  33. package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +0 -11
  34. package/dist/Domain/GeoJSON/Geometry.d.ts +0 -9
  35. package/dist/Domain/GeoJSON/GeometryCollection.d.ts +0 -8
  36. package/dist/Domain/GeoJSON/GeometryObject.d.ts +0 -12
  37. package/dist/Domain/Guards/Number.d.ts +0 -3
  38. package/dist/Domain/Guards/Tuple.d.ts +0 -3
  39. package/dist/Domain/Iterator/IterablePair.d.ts +0 -32
  40. package/dist/Domain/Iterator/SimpleGeometry.d.ts +0 -90
  41. package/dist/Domain/Utility/Calculate.d.ts +0 -9
  42. package/dist/Domain/Utility/Distance.d.ts +0 -3
  43. package/dist/Domain/Utility/Intersect.d.ts +0 -2
  44. package/dist/Domain/Utility/Segments.d.ts +0 -2
  45. package/dist/Domain/Utility/Winding.d.ts +0 -3
  46. package/dist/geojson.cjs.js +0 -655
  47. package/dist/geojson.cjs.min.js +0 -1
  48. package/dist/geojson.es.js +0 -627
  49. package/dist/geojson.es.min.js +0 -1
  50. package/dist/geojson.js +0 -660
  51. package/dist/geojson.min.js +0 -1
  52. package/rollup.config.mjs +0 -43
  53. package/source/Domain/Constants.ts +0 -5
  54. package/source/Domain/GeoJSON/Concept/Altitude.ts +0 -9
  55. package/source/Domain/GeoJSON/Concept/BoundingBox.ts +0 -31
  56. package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +0 -12
  57. package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +0 -23
  58. package/source/Domain/GeoJSON/Concept/InteriorRing.ts +0 -12
  59. package/source/Domain/GeoJSON/Concept/Latitude.ts +0 -7
  60. package/source/Domain/GeoJSON/Concept/LinearRing.ts +0 -14
  61. package/source/Domain/GeoJSON/Concept/Longitude.ts +0 -7
  62. package/source/Domain/GeoJSON/Concept/Position.ts +0 -18
  63. package/source/Domain/GeoJSON/Feature.ts +0 -24
  64. package/source/Domain/GeoJSON/FeatureCollection.ts +0 -16
  65. package/source/Domain/GeoJSON/GeoJSON.ts +0 -9
  66. package/source/Domain/GeoJSON/Geometry/LineString.ts +0 -12
  67. package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +0 -9
  68. package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +0 -10
  69. package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +0 -9
  70. package/source/Domain/GeoJSON/Geometry/Point.ts +0 -12
  71. package/source/Domain/GeoJSON/Geometry/Polygon.ts +0 -20
  72. package/source/Domain/GeoJSON/Geometry.ts +0 -11
  73. package/source/Domain/GeoJSON/GeometryCollection.ts +0 -23
  74. package/source/Domain/GeoJSON/GeometryObject.ts +0 -20
  75. package/source/Domain/Guards/Number.ts +0 -13
  76. package/source/Domain/Guards/Tuple.ts +0 -6
  77. package/source/Domain/Guards/Utility.ts +0 -1
  78. package/source/Domain/Iterator/IterablePair.ts +0 -47
  79. package/source/Domain/Iterator/SimpleGeometry.ts +0 -137
  80. package/source/Domain/Utility/Calculate.ts +0 -143
  81. package/source/Domain/Utility/Distance.ts +0 -56
  82. package/source/Domain/Utility/Intersect.ts +0 -42
  83. package/source/Domain/Utility/Numeric.ts +0 -8
  84. package/source/Domain/Utility/Segments.ts +0 -5
  85. package/source/Domain/Utility/Winding.ts +0 -19
  86. package/source/main.ts +0 -20
  87. package/test/Domain/GeoJSON/Concept/Altitude.ts +0 -58
  88. package/test/Domain/GeoJSON/Concept/BoundingBox.ts +0 -77
  89. package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +0 -65
  90. package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +0 -56
  91. package/test/Domain/GeoJSON/Concept/InteriorRing.ts +0 -65
  92. package/test/Domain/GeoJSON/Concept/Latitude.ts +0 -56
  93. package/test/Domain/GeoJSON/Concept/LinearRing.ts +0 -63
  94. package/test/Domain/GeoJSON/Concept/Longitude.ts +0 -56
  95. package/test/Domain/GeoJSON/Concept/Position.ts +0 -56
  96. package/test/Domain/GeoJSON/Feature.ts +0 -9
  97. package/test/Domain/GeoJSON/FeatureCollection.ts +0 -9
  98. package/test/Domain/GeoJSON/GeoJSON.ts +0 -21
  99. package/test/Domain/GeoJSON/Geometry/LineString.ts +0 -11
  100. package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +0 -11
  101. package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +0 -11
  102. package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +0 -11
  103. package/test/Domain/GeoJSON/Geometry/Point.ts +0 -11
  104. package/test/Domain/GeoJSON/Geometry/Polygon.ts +0 -11
  105. package/test/Domain/GeoJSON/Geometry.ts +0 -9
  106. package/test/Domain/GeoJSON/GeometryCollection.ts +0 -9
  107. package/test/Domain/GeoJSON/GeometryObject.ts +0 -4
  108. package/test/Domain/Guards/Number.ts +0 -49
  109. package/test/Domain/Guards/Tuple.ts +0 -27
  110. package/test/Domain/Iterator/IterablePair.ts +0 -203
  111. package/test/Domain/Iterator/SimpleGeometry.ts +0 -195
  112. package/test/Domain/Utility/Calculate.ts +0 -178
  113. package/test/Domain/Utility/Distance.ts +0 -19
  114. package/test/Domain/Utility/Intersect.ts +0 -54
  115. package/test/Domain/Utility/Numeric.ts +0 -30
  116. package/test/Domain/Utility/Winding.ts +0 -52
  117. package/test/README.ts +0 -123
  118. package/test/data/Distance.ts +0 -51
  119. package/test/data/HolySee.ts +0 -74
  120. package/test/data/Intersect.ts +0 -300
  121. package/test/data/Italy.ts +0 -2883
  122. package/test/data/SanMarino.ts +0 -83
  123. package/test/data/Shapes.ts +0 -107
  124. package/test/helper/geometry.ts +0 -76
  125. package/test/helper/malform.ts +0 -82
  126. package/test/main.ts +0 -4
  127. package/tsconfig.json +0 -12
package/rollup.config.mjs DELETED
@@ -1,43 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import typescript from '@rollup/plugin-typescript';
3
- import { nodeResolve as resolve } from '@rollup/plugin-node-resolve';
4
- import common from '@rollup/plugin-commonjs';
5
- import { default as terser } from '@rollup/plugin-terser';
6
- import declaration from 'rollup-plugin-dts'
7
-
8
- const { main, iife, module, types } = JSON.parse(readFileSync('./package.json'));
9
-
10
- const defaults = {
11
- name: 'GeoJSON',
12
- sourcemap: false,
13
- };
14
-
15
- function configure(...args) {
16
- return args.reduce((carry, options) => {
17
- const basic = { ...defaults, ...options };
18
- const min = {
19
- ...basic,
20
- file: basic.file.replace(/(\.[a-z]+)$/, '.min$1'),
21
- plugins: [terser({ format: { comments: false } })],
22
- };
23
-
24
- return carry.concat(basic, min);
25
- }, []);
26
- }
27
-
28
- export default [
29
- {
30
- input: 'source/main.ts',
31
- output: configure(
32
- { file: main, format: 'cjs' },
33
- { file: iife, format: 'iife' },
34
- { file: module, format: 'es' },
35
- ),
36
- plugins: [resolve(), common(), typescript(), common()],
37
- },
38
- {
39
- input: 'temp/main.d.ts',
40
- output: { file: types, format: 'es' },
41
- plugins: [declaration()],
42
- }
43
- ];
@@ -1,5 +0,0 @@
1
- export const EARTH_RADIUS = 6_371_008.7714; // mean radius
2
- export const EARTH_RADIUS_MAJOR = 6_378_137; // equatorial radius
3
- export const EARTH_RADIUS_MINOR = 6_356_752.314_245; // semiminor axis
4
- export const EARTH_FLATTENING = 298.257_223_563;
5
- export const GPS_SATELLITE_ORBIT = 20_180_000;
@@ -1,9 +0,0 @@
1
- import { EARTH_RADIUS, GPS_SATELLITE_ORBIT } from "../../Constants";
2
- import { isNumberBetween, isNumberValue } from "../../Guards/Number";
3
-
4
- export type Altitude = number;
5
- export function isAltitude(value: any): value is Altitude {
6
- return isNumberValue(value);
7
- }
8
-
9
- export const isStrictAltitude = isNumberBetween<Altitude>(-EARTH_RADIUS, GPS_SATELLITE_ORBIT);
@@ -1,31 +0,0 @@
1
- import { all, any } from "@konfirm/guard";
2
- import { isTuple } from "../../Guards/Tuple";
3
- import { isLongitude, Longitude, isStrictLongitude } from "./Longitude";
4
- import { isLatitude, Latitude, isStrictLatitude } from "./Latitude";
5
- import { Altitude, isAltitude, isStrictAltitude } from "./Altitude";
6
-
7
- export type BoundingBox
8
- = [Longitude, Latitude, Altitude, Longitude, Latitude, Altitude]
9
- | [Longitude, Latitude, Longitude, Latitude];
10
- const isBoundingBoxWithAltitude = all(
11
- isTuple(isLongitude, isLatitude, isAltitude, isLongitude, isLatitude, isAltitude),
12
- ([, s, , , n]) => s <= n
13
- )
14
- const isBoundingBoxWithoutAltitude = all(
15
- isTuple(isLongitude, isLatitude, isLongitude, isLatitude),
16
- ([, s, , n]) => s <= n
17
- )
18
- export const isBoundingBox = any<BoundingBox>(
19
- isBoundingBoxWithAltitude,
20
- isBoundingBoxWithoutAltitude
21
- );
22
- export const isStrictBoundingBox = any<BoundingBox>(
23
- all(
24
- isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude, isStrictLongitude, isStrictLatitude, isStrictAltitude),
25
- isBoundingBoxWithAltitude
26
- ),
27
- all(
28
- isTuple(isStrictLongitude, isStrictLatitude, isStrictLongitude, isStrictLatitude),
29
- isBoundingBoxWithoutAltitude
30
- ),
31
- );
@@ -1,12 +0,0 @@
1
- import { all } from "@konfirm/guard";
2
- import { isCounterClockwiseWinding } from "../../Utility/Winding";
3
- import { isLinearRing, isStrictLinearRing, LinearRing } from "./LinearRing";
4
-
5
- export type ExteriorRing = LinearRing;
6
- export const isExteriorRing = all<ExteriorRing>(
7
- isLinearRing,
8
- );
9
- export const isStrictExteriorRing = all<ExteriorRing>(
10
- isStrictLinearRing,
11
- isCounterClockwiseWinding
12
- );
@@ -1,23 +0,0 @@
1
- import { all, Guard, isString, isStructure } from "@konfirm/guard";
2
- import { BoundingBox, isBoundingBox, isStrictBoundingBox } from "./BoundingBox";
3
-
4
- type GeoJSONBase = {
5
- type: string;
6
- bbox?: BoundingBox;
7
- [key: string]: unknown;
8
- }
9
- export type GeoJSONObject<T extends GeoJSONBase = GeoJSONBase>
10
- = GeoJSONBase
11
- & T;
12
- export function isGeoJSONObject<T extends GeoJSONBase>(type: string): Guard<T> {
13
- return isStructure<T>({
14
- type: all(isString, (value: any) => value === type),
15
- bbox: isBoundingBox,
16
- }, 'bbox');
17
- }
18
- export function isStrictGeoJSONObject<T extends GeoJSONBase>(type: string): Guard<T> {
19
- return isStructure<T>({
20
- type: all(isString, (value: any) => value === type),
21
- bbox: isStrictBoundingBox,
22
- }, 'bbox');
23
- }
@@ -1,12 +0,0 @@
1
- import { all } from "@konfirm/guard";
2
- import { isClockwiseWinding } from "../../Utility/Winding";
3
- import { isLinearRing, isStrictLinearRing, LinearRing } from "./LinearRing";
4
-
5
- export type InteriorRing = LinearRing;
6
- export const isInteriorRing = all<InteriorRing>(
7
- isLinearRing,
8
- );
9
- export const isStrictInteriorRing = all<InteriorRing>(
10
- isStrictLinearRing,
11
- isClockwiseWinding
12
- );
@@ -1,7 +0,0 @@
1
- import { isNumberBetween, isNumberValue } from "../../Guards/Number";
2
-
3
- export type Latitude = number;
4
- export function isLatitude(value: any): value is Latitude {
5
- return isNumberValue(value);
6
- }
7
- export const isStrictLatitude = isNumberBetween<Latitude>(-90, 90);
@@ -1,14 +0,0 @@
1
- import { all, isArrayOfSize, isArrayOfType } from "@konfirm/guard";
2
- import { isPosition, isStrictPosition, Position } from "./Position";
3
-
4
- export type LinearRing = Array<Position>;
5
- export const isLinearRing = all<LinearRing>(
6
- isArrayOfType(isPosition),
7
- isArrayOfSize(4),
8
- (value: Array<Position>) => value[value.length - 1].every((v, i) => v === value[0][i])
9
- );
10
- export const isStrictLinearRing = all<LinearRing>(
11
- isArrayOfType(isStrictPosition),
12
- isArrayOfSize(4),
13
- (value: Array<Position>) => value[value.length - 1].every((v, i) => v === value[0][i])
14
- );
@@ -1,7 +0,0 @@
1
- import { isNumberBetween, isNumberValue } from "../../Guards/Number";
2
-
3
- export type Longitude = number;
4
- export function isLongitude(value: any): value is Longitude {
5
- return isNumberValue(value);
6
- }
7
- export const isStrictLongitude = isNumberBetween<Longitude>(-180, 180);
@@ -1,18 +0,0 @@
1
- import { any } from "@konfirm/guard";
2
- import { isTuple } from "../../Guards/Tuple";
3
- import { Altitude, isAltitude, isStrictAltitude } from "./Altitude";
4
- import { isLatitude, isStrictLatitude, Latitude } from "./Latitude";
5
- import { isLongitude, isStrictLongitude, Longitude } from "./Longitude";
6
-
7
- export type Position = [Longitude, Latitude, Altitude?];
8
- export const isPosition = any<Position>(
9
- isTuple(isLongitude, isLatitude),
10
- isTuple(isLongitude, isLatitude, isAltitude)
11
- );
12
- export const isStrictPosition = any<Position>(
13
- isTuple(isStrictLongitude, isStrictLatitude),
14
- isTuple(isStrictLongitude, isStrictLatitude, isStrictAltitude),
15
- );
16
- export function isEquivalentPosition(one: any, two: any): boolean {
17
- return isPosition(one) && isPosition(two) && one.length === two.length && one.every((v, i) => v === two[i]);
18
- }
@@ -1,24 +0,0 @@
1
- import { all, any, isNULL, isObject, isStructure } from "@konfirm/guard";
2
- import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
3
- import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
4
- import { GeometryCollection, isGeometryCollection, isStrictGeometryCollection } from "./GeometryCollection";
5
-
6
- export type Feature = GeoJSONObject<{
7
- type: 'Feature';
8
- geometry: Geometry | GeometryCollection;
9
- properties: { [key: string]: unknown } | null;
10
- }>
11
- export const isFeature = all<Feature>(
12
- isGeoJSONObject('Feature'),
13
- isStructure({
14
- geometry: any(isGeometry, isGeometryCollection),
15
- properties: any(isNULL, isObject)
16
- })
17
- );
18
- export const isStrictFeature = all<Feature>(
19
- isGeoJSONObject('Feature'),
20
- isStructure({
21
- geometry: any(isStrictGeometry, isStrictGeometryCollection),
22
- properties: any(isNULL, isObject)
23
- })
24
- );
@@ -1,16 +0,0 @@
1
- import { all, isArrayOfType, isKeyOfType } from "@konfirm/guard";
2
- import { Feature, isFeature, isStrictFeature } from "./Feature";
3
- import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
4
-
5
- export type FeatureCollection = GeoJSONObject<{
6
- type: 'FeatureCollection';
7
- features: Array<Feature>;
8
- }>
9
- export const isFeatureCollection = all<FeatureCollection>(
10
- isGeoJSONObject('FeatureCollection'),
11
- isKeyOfType('features', isArrayOfType(isFeature))
12
- );
13
- export const isStrictFeatureCollection = all<FeatureCollection>(
14
- isGeoJSONObject('FeatureCollection'),
15
- isKeyOfType('features', isArrayOfType(isStrictFeature))
16
- );
@@ -1,9 +0,0 @@
1
- import { any } from "@konfirm/guard";
2
- import { Feature, isFeature, isStrictFeature } from "./Feature";
3
- import { FeatureCollection, isFeatureCollection, isStrictFeatureCollection } from "./FeatureCollection";
4
- import { GeometryCollection, isGeometryCollection, isStrictGeometryCollection } from "./GeometryCollection";
5
- import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
6
-
7
- export type GeoJSON = Geometry | GeometryCollection | Feature | FeatureCollection;
8
- export const isGeoJSON = any<GeoJSON>(isGeometry, isGeometryCollection, isFeature, isFeatureCollection);
9
- export const isStrictGeoJSON = any<GeoJSON>(isStrictGeometry, isStrictGeometryCollection, isStrictFeature, isStrictFeatureCollection);
@@ -1,12 +0,0 @@
1
- import { Guard } from "../../Guards/Utility";
2
- import { GeometryObject, isGeometryObject } from "../GeometryObject";
3
- import { isMultiPointCoordinates, isStrictMultiPointCoordinates, MultiPoint } from "./MultiPoint";
4
-
5
- export type LineString = GeometryObject<{
6
- type: 'LineString';
7
- coordinates: MultiPoint['coordinates'];
8
- }>
9
- export const isLineStringCoordinates = isMultiPointCoordinates;
10
- export const isLineString: Guard<LineString> = isGeometryObject<LineString>('LineString', isLineStringCoordinates);
11
- export const isStrictLineStringCoordinates = isStrictMultiPointCoordinates;
12
- export const isStrictLineString: Guard<LineString> = isGeometryObject<LineString>('LineString', isStrictLineStringCoordinates);
@@ -1,9 +0,0 @@
1
- import { isArrayOfType } from "@konfirm/guard";
2
- import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
3
- import { isLineStringCoordinates, isStrictLineStringCoordinates, LineString } from "./LineString";
4
-
5
- export type MultiLineString = MultiGeometryObject<LineString>;
6
- export const isMultiLineStringCoordinates = isArrayOfType(isLineStringCoordinates);
7
- export const isMultiLineString = isGeometryObject<MultiLineString>('MultiLineString', isMultiLineStringCoordinates);
8
- export const isStrictMultiLineStringCoordinates = isArrayOfType(isStrictLineStringCoordinates);
9
- export const isStrictMultiLineString = isGeometryObject<MultiLineString>('MultiLineString', isStrictMultiLineStringCoordinates);
@@ -1,10 +0,0 @@
1
- import { isArrayOfType } from "@konfirm/guard";
2
- import { Guard } from "../../Guards/Utility";
3
- import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
4
- import { isPointCoordinates, isStrictPointCoordinates, Point } from "./Point";
5
-
6
- export type MultiPoint = MultiGeometryObject<Point>
7
- export const isMultiPointCoordinates: Guard<MultiPoint['coordinates']> = isArrayOfType(isPointCoordinates)
8
- export const isMultiPoint = isGeometryObject<MultiPoint>('MultiPoint', isMultiPointCoordinates);
9
- export const isStrictMultiPointCoordinates: Guard<MultiPoint['coordinates']> = isArrayOfType(isStrictPointCoordinates)
10
- export const isStrictMultiPoint = isGeometryObject<MultiPoint>('MultiPoint', isStrictMultiPointCoordinates);
@@ -1,9 +0,0 @@
1
- import { isArrayOfType } from "@konfirm/guard";
2
- import { isGeometryObject, MultiGeometryObject } from "../GeometryObject";
3
- import { isPolygonCoordinates, isStrictPolygonCoordinates, Polygon } from "./Polygon";
4
-
5
- export type MultiPolygon = MultiGeometryObject<Polygon>
6
- export const isMultiPolygonCoordinates = isArrayOfType(isPolygonCoordinates);
7
- export const isMultiPolygon = isGeometryObject<MultiPolygon>('MultiPolygon', isMultiPolygonCoordinates);
8
- export const isStrictMultiPolygonCoordinates = isArrayOfType(isStrictPolygonCoordinates);
9
- export const isStrictMultiPolygon = isGeometryObject<MultiPolygon>('MultiPolygon', isStrictMultiPolygonCoordinates);
@@ -1,12 +0,0 @@
1
- import { GeometryObject, isGeometryObject } from "../GeometryObject";
2
- import { isPosition, isStrictPosition, Position } from "../Concept/Position";
3
- import { Guard } from "../../Guards/Utility";
4
-
5
- export type Point = GeometryObject<{
6
- type: 'Point';
7
- coordinates: Position;
8
- }>
9
- export const isPointCoordinates: Guard<Point['coordinates']> = isPosition;
10
- export const isPoint: Guard<Point> = isGeometryObject<Point>('Point', isPointCoordinates);
11
- export const isStrictPointCoordinates: Guard<Point['coordinates']> = isStrictPosition;
12
- export const isStrictPoint: Guard<Point> = isGeometryObject<Point>('Point', isStrictPointCoordinates);
@@ -1,20 +0,0 @@
1
- import { all, isArrayOfType } from "@konfirm/guard";
2
- import { GeometryObject, isGeometryObject } from "../GeometryObject";
3
- import { ExteriorRing, isExteriorRing } from "../Concept/ExteriorRing";
4
- import { InteriorRing, isInteriorRing } from "../Concept/InteriorRing";
5
- import { isLinearRing, isStrictLinearRing } from "../Concept/LinearRing";
6
-
7
- export type Polygon = GeometryObject<{
8
- type: 'Polygon';
9
- coordinates: [ExteriorRing, ...Array<InteriorRing>];
10
- }>
11
- export const isPolygonCoordinates = all(
12
- isArrayOfType(isLinearRing)
13
- );
14
- export const isPolygon = isGeometryObject<Polygon>('Polygon', isPolygonCoordinates);
15
- export const isStrictPolygonCoordinates = all(
16
- isArrayOfType(isStrictLinearRing),
17
- (value: any) => isExteriorRing(value[0]),
18
- (value: any) => value.slice(1).every(isInteriorRing)
19
- );
20
- export const isStrictPolygon = isGeometryObject<Polygon>('Polygon', isStrictPolygonCoordinates);
@@ -1,11 +0,0 @@
1
- import { any } from "@konfirm/guard";
2
- import { isLineString, isStrictLineString, LineString } from "./Geometry/LineString";
3
- import { isMultiLineString, isStrictMultiLineString, MultiLineString } from "./Geometry/MultiLineString";
4
- import { isMultiPoint, isStrictMultiPoint, MultiPoint } from "./Geometry/MultiPoint";
5
- import { isMultiPolygon, isStrictMultiPolygon, MultiPolygon } from "./Geometry/MultiPolygon";
6
- import { isPoint, isStrictPoint, Point } from "./Geometry/Point";
7
- import { isPolygon, isStrictPolygon, Polygon } from "./Geometry/Polygon";
8
-
9
- export type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
10
- export const isGeometry = any<Geometry>(isPoint, isMultiPoint, isLineString, isMultiLineString, isPolygon, isMultiPolygon);
11
- export const isStrictGeometry = any<Geometry>(isStrictPoint, isStrictMultiPoint, isStrictLineString, isStrictMultiLineString, isStrictPolygon, isStrictMultiPolygon);
@@ -1,23 +0,0 @@
1
- import { all, any, isArrayOfType, isKeyOfType } from "@konfirm/guard";
2
- import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
3
- import { Geometry, isGeometry, isStrictGeometry } from "./Geometry";
4
-
5
- export type GeometryCollection = GeoJSONObject<{
6
- type: 'GeometryCollection';
7
- geometries: Array<Geometry | GeometryCollection>;
8
- }>;
9
-
10
- const isGeometryCollectionObject = all<GeometryCollection>(
11
- isGeoJSONObject('GeometryCollection'),
12
- isKeyOfType('geometries', isArrayOfType(any(isGeometry, isGeometryCollection)))
13
- );
14
- const isStrictGeometryCollectionObject = all<GeometryCollection>(
15
- isGeoJSONObject('GeometryCollection'),
16
- isKeyOfType('geometries', isArrayOfType(any(isStrictGeometry, isStrictGeometryCollection)))
17
- );
18
- export function isGeometryCollection(value: any): value is GeometryCollection {
19
- return isGeometryCollectionObject(value)
20
- }
21
- export function isStrictGeometryCollection(value: any): value is GeometryCollection {
22
- return isStrictGeometryCollectionObject(value)
23
- }
@@ -1,20 +0,0 @@
1
- import { all, Guard, isKeyOfType, Validator } from "@konfirm/guard";
2
- import { GeoJSONObject, isGeoJSONObject } from "./Concept/GeoJSONObject";
3
-
4
- type GeometryBase = GeoJSONObject & {
5
- coordinates: Array<unknown>;
6
- }
7
-
8
- export type GeometryObject<T extends GeometryBase>
9
- = Omit<GeometryBase, 'coordinates'>
10
- & T;
11
- export type MultiGeometryObject<T extends GeometryBase> = GeometryObject<{
12
- type: `Multi${T['type']}`;
13
- coordinates: Array<T['coordinates']>;
14
- }>;
15
- export function isGeometryObject<T extends GeometryBase>(type: string, isCoordinates: Validator): Guard<T> {
16
- return all<T>(
17
- isGeoJSONObject(type),
18
- isKeyOfType('coordinates', isCoordinates)
19
- );
20
- }
@@ -1,13 +0,0 @@
1
- import { isNumber } from '@konfirm/guard';
2
- import { Guard } from './Utility';
3
-
4
- export function isNumberValue<T extends number>(value: any): value is T {
5
- return isNumber(value) && Number.isFinite(value);
6
- }
7
-
8
- export function isNumberBetween<T extends number>(a: number, b: number = Infinity): Guard<T> {
9
- const min = Math.min(a, b);
10
- const max = Math.max(a, b);
11
-
12
- return (value: any): value is T => isNumberValue(value) && value >= min && value <= max;
13
- }
@@ -1,6 +0,0 @@
1
- import { isArray, Validator } from "@konfirm/guard";
2
- import { Guard } from './Utility';
3
-
4
- export function isTuple<T extends Array<unknown>>(...rules: Array<Validator>): Guard<T> {
5
- return (value: any): value is T => isArray(value) && value.length === rules.length && rules.every((rule, index) => rule(value[index]));
6
- }
@@ -1 +0,0 @@
1
- export type Guard<T> = (value: any) => value is T;
@@ -1,47 +0,0 @@
1
- /**
2
- * Iterator class which traverses all value pairs of two or more Iterable instances
3
- *
4
- * @export
5
- * @class IterablePairIterator
6
- * @template T
7
- */
8
- export class IterablePairIterator<T = unknown> {
9
- private readonly iterators: Array<Iterable<T>> = [];
10
-
11
- /**
12
- * Constructs a new instance of IterablePairIterator
13
- *
14
- * @param iterators
15
- */
16
- constructor(...iterators: [Iterable<T>, Iterable<T>, ...Array<Iterable<T>>]) {
17
- this.iterators = iterators;
18
- }
19
-
20
- /**
21
- * Generator yielding all value pairs from the provided iterators
22
- *
23
- * @return {*} {Iterator<[T, T]>}
24
- * @memberof IterablePairIterator
25
- */
26
- *[Symbol.iterator](): Iterator<[T, T]> {
27
- for (const [a, b] of this.pairs(this.iterators)) {
28
- for (const one of a) {
29
- for (const two of b) {
30
- yield [one, two];
31
- }
32
- }
33
- }
34
- }
35
-
36
- /**
37
- * Create unique Iterator<T> combinations to traverse over
38
- *
39
- * @private
40
- * @param {Array<Iterable<T>>} source
41
- * @return {*} {Array<[Iterable<T>, Iterable<T>]>}
42
- * @memberof IterablePairIterator
43
- */
44
- private pairs(source: Array<Iterable<T>>): Array<[Iterable<T>, Iterable<T>]> {
45
- return source.map((a, i) => source.slice(i + 1).map((b) => [a, b])).flat() as Array<[Iterable<T>, Iterable<T>]>;
46
- }
47
- }
@@ -1,137 +0,0 @@
1
- import { LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from "../../main";
2
- import { Feature } from "../GeoJSON/Feature";
3
- import { FeatureCollection } from "../GeoJSON/FeatureCollection";
4
- import { GeoJSON } from "../GeoJSON/GeoJSON";
5
- import { GeometryCollection } from "../GeoJSON/GeometryCollection";
6
-
7
- type SimpleGeometry = Point | LineString | Polygon;
8
-
9
- /**
10
- * Iterator class to turn any GeoJSON structure into one or more SimpleGeometry (Point | LineString | Polygon) objects
11
- *
12
- * @export
13
- * @class SimpleGeometryIterator
14
- */
15
- export class SimpleGeometryIterator {
16
- private readonly inputs: Array<GeoJSON> = [];
17
-
18
- /**
19
- * Creates an instance of SimpleGeometryIterator
20
- *
21
- * @param {...[GeoJSON, ...Array<GeoJSON>]} inputs
22
- * @memberof SimpleGeometryIterator
23
- */
24
- constructor(...inputs: [GeoJSON, ...Array<GeoJSON>]) {
25
- this.inputs = inputs;
26
- }
27
-
28
- /**
29
- * Generator yielding all SimpleGeometry objects from the provided GeoJSON structure(s)
30
- *
31
- * @return {*} {Iterator<SimpleGeometry>}
32
- * @memberof SimpleGeometryIterator
33
- */
34
- *[Symbol.iterator](): Iterator<SimpleGeometry> {
35
- for (const input of this.inputs) {
36
- for (const simple of this.unwrap(input)) {
37
- yield simple;
38
- }
39
- }
40
- }
41
-
42
- /**
43
- * unwrap any GeoJSON object into one or more SimpleGeometry object
44
- *
45
- * @private
46
- * @param {GeoJSON} geo
47
- * @return {*} {Iterable<SimpleGeometry>}
48
- * @memberof SimpleGeometryIterator
49
- */
50
- private *unwrap(geo: GeoJSON): Iterable<SimpleGeometry> {
51
- geo.type in this
52
- ? yield* this[geo.type](geo)
53
- : yield geo as SimpleGeometry;
54
- }
55
-
56
- /**
57
- * Generate the geometries in a GeometryCollection
58
- *
59
- * @private
60
- * @param {GeometryCollection} { geometries }
61
- * @return {*} {Iterable<SimpleGeometry>}
62
- * @memberof SimpleGeometryIterator
63
- */
64
- private *GeometryCollection({ geometries }: GeometryCollection): Iterable<SimpleGeometry> {
65
- for (const geometry of geometries) {
66
- yield* this.unwrap(geometry);
67
- }
68
- }
69
-
70
- /**
71
- * Generate the geometries of the Feature object(s) in a FeatureCollection
72
- *
73
- * @private
74
- * @param {FeatureCollection} { features }
75
- * @return {*} {Iterable<SimpleGeometry>}
76
- * @memberof SimpleGeometryIterator
77
- */
78
- private *FeatureCollection({ features }: FeatureCollection): Iterable<SimpleGeometry> {
79
- for (const { geometry } of features) {
80
- yield* this.unwrap(geometry);
81
- }
82
- }
83
-
84
- /**
85
- * Generate the geometry of a Feature object
86
- *
87
- * @private
88
- * @param {Feature} { geometry }
89
- * @return {*} {Iterable<SimpleGeometry>}
90
- * @memberof SimpleGeometryIterator
91
- */
92
- private *Feature({ geometry }: Feature): Iterable<SimpleGeometry> {
93
- yield* this.unwrap(geometry);
94
- }
95
-
96
- /**
97
- * Generate Point objects from a MultiPoint object
98
- *
99
- * @private
100
- * @param {MultiPoint} multi
101
- * @return {*} {Iterable<Point>}
102
- * @memberof SimpleGeometryIterator
103
- */
104
- private *MultiPoint(multi: MultiPoint): Iterable<Point> {
105
- for (const coordinates of multi.coordinates) {
106
- yield { type: 'Point', coordinates };
107
- }
108
- }
109
-
110
- /**
111
- * Generate LineString objects from a MultiLineString object
112
- *
113
- * @private
114
- * @param {MultiLineString} multi
115
- * @return {*} {Iterable<LineString>}
116
- * @memberof SimpleGeometryIterator
117
- */
118
- private *MultiLineString(multi: MultiLineString): Iterable<LineString> {
119
- for (const coordinates of multi.coordinates) {
120
- yield { type: 'LineString', coordinates };
121
- }
122
- }
123
-
124
- /**
125
- * Generate Polygon objects from a MultiPolygon object
126
- *
127
- * @private
128
- * @param {MultiPolygon} multi
129
- * @return {*} {Iterable<Polygon>}
130
- * @memberof SimpleGeometryIterator
131
- */
132
- private *MultiPolygon(multi: MultiPolygon): Iterable<Polygon> {
133
- for (const coordinates of multi.coordinates) {
134
- yield { type: 'Polygon', coordinates };
135
- }
136
- }
137
- }