@konfirm/geojson 1.0.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.
Files changed (122) hide show
  1. package/.editorconfig +16 -0
  2. package/.github/workflows/release.yml +21 -0
  3. package/.github/workflows/tests.yml +56 -0
  4. package/CHANGELOG.md +21 -0
  5. package/LICENSE +21 -0
  6. package/README.md +260 -0
  7. package/dist/Domain/Constants.d.ts +5 -0
  8. package/dist/Domain/GeoJSON/Concept/Altitude.d.ts +3 -0
  9. package/dist/Domain/GeoJSON/Concept/BoundingBox.d.ts +6 -0
  10. package/dist/Domain/GeoJSON/Concept/ExteriorRing.d.ts +4 -0
  11. package/dist/Domain/GeoJSON/Concept/GeoJSONObject.d.ts +11 -0
  12. package/dist/Domain/GeoJSON/Concept/InteriorRing.d.ts +4 -0
  13. package/dist/Domain/GeoJSON/Concept/Latitude.d.ts +3 -0
  14. package/dist/Domain/GeoJSON/Concept/LinearRing.d.ts +4 -0
  15. package/dist/Domain/GeoJSON/Concept/Longitude.d.ts +3 -0
  16. package/dist/Domain/GeoJSON/Concept/Position.d.ts +7 -0
  17. package/dist/Domain/GeoJSON/Feature.d.ts +12 -0
  18. package/dist/Domain/GeoJSON/FeatureCollection.d.ts +8 -0
  19. package/dist/Domain/GeoJSON/GeoJSON.d.ts +7 -0
  20. package/dist/Domain/GeoJSON/Geometry/LineString.d.ts +11 -0
  21. package/dist/Domain/GeoJSON/Geometry/MultiLineString.d.ts +7 -0
  22. package/dist/Domain/GeoJSON/Geometry/MultiPoint.d.ts +8 -0
  23. package/dist/Domain/GeoJSON/Geometry/MultiPolygon.d.ts +7 -0
  24. package/dist/Domain/GeoJSON/Geometry/Point.d.ts +11 -0
  25. package/dist/Domain/GeoJSON/Geometry/Polygon.d.ts +11 -0
  26. package/dist/Domain/GeoJSON/Geometry.d.ts +9 -0
  27. package/dist/Domain/GeoJSON/GeometryCollection.d.ts +8 -0
  28. package/dist/Domain/GeoJSON/GeometryObject.d.ts +12 -0
  29. package/dist/Domain/Guards/Number.d.ts +3 -0
  30. package/dist/Domain/Guards/Tuple.d.ts +3 -0
  31. package/dist/Domain/Iterator/IterablePair.d.ts +32 -0
  32. package/dist/Domain/Iterator/SimpleGeometry.d.ts +90 -0
  33. package/dist/Domain/Utility/Calculate.d.ts +9 -0
  34. package/dist/Domain/Utility/Distance.d.ts +3 -0
  35. package/dist/Domain/Utility/Intersect.d.ts +2 -0
  36. package/dist/Domain/Utility/Segments.d.ts +2 -0
  37. package/dist/Domain/Utility/Winding.d.ts +3 -0
  38. package/dist/geojson.cjs.js +655 -0
  39. package/dist/geojson.cjs.min.js +1 -0
  40. package/dist/geojson.d.ts +198 -0
  41. package/dist/geojson.es.js +627 -0
  42. package/dist/geojson.es.min.js +1 -0
  43. package/dist/geojson.js +660 -0
  44. package/dist/geojson.min.js +1 -0
  45. package/dist/main.d.ts +15 -0
  46. package/package.json +63 -0
  47. package/rollup.config.mjs +43 -0
  48. package/source/Domain/Constants.ts +5 -0
  49. package/source/Domain/GeoJSON/Concept/Altitude.ts +9 -0
  50. package/source/Domain/GeoJSON/Concept/BoundingBox.ts +31 -0
  51. package/source/Domain/GeoJSON/Concept/ExteriorRing.ts +12 -0
  52. package/source/Domain/GeoJSON/Concept/GeoJSONObject.ts +23 -0
  53. package/source/Domain/GeoJSON/Concept/InteriorRing.ts +12 -0
  54. package/source/Domain/GeoJSON/Concept/Latitude.ts +7 -0
  55. package/source/Domain/GeoJSON/Concept/LinearRing.ts +14 -0
  56. package/source/Domain/GeoJSON/Concept/Longitude.ts +7 -0
  57. package/source/Domain/GeoJSON/Concept/Position.ts +18 -0
  58. package/source/Domain/GeoJSON/Feature.ts +24 -0
  59. package/source/Domain/GeoJSON/FeatureCollection.ts +16 -0
  60. package/source/Domain/GeoJSON/GeoJSON.ts +9 -0
  61. package/source/Domain/GeoJSON/Geometry/LineString.ts +12 -0
  62. package/source/Domain/GeoJSON/Geometry/MultiLineString.ts +9 -0
  63. package/source/Domain/GeoJSON/Geometry/MultiPoint.ts +10 -0
  64. package/source/Domain/GeoJSON/Geometry/MultiPolygon.ts +9 -0
  65. package/source/Domain/GeoJSON/Geometry/Point.ts +12 -0
  66. package/source/Domain/GeoJSON/Geometry/Polygon.ts +20 -0
  67. package/source/Domain/GeoJSON/Geometry.ts +11 -0
  68. package/source/Domain/GeoJSON/GeometryCollection.ts +23 -0
  69. package/source/Domain/GeoJSON/GeometryObject.ts +20 -0
  70. package/source/Domain/Guards/Number.ts +13 -0
  71. package/source/Domain/Guards/Tuple.ts +6 -0
  72. package/source/Domain/Guards/Utility.ts +1 -0
  73. package/source/Domain/Iterator/IterablePair.ts +47 -0
  74. package/source/Domain/Iterator/SimpleGeometry.ts +137 -0
  75. package/source/Domain/Utility/Calculate.ts +143 -0
  76. package/source/Domain/Utility/Distance.ts +56 -0
  77. package/source/Domain/Utility/Intersect.ts +42 -0
  78. package/source/Domain/Utility/Numeric.ts +8 -0
  79. package/source/Domain/Utility/Segments.ts +5 -0
  80. package/source/Domain/Utility/Winding.ts +19 -0
  81. package/source/main.ts +20 -0
  82. package/test/Domain/GeoJSON/Concept/Altitude.ts +58 -0
  83. package/test/Domain/GeoJSON/Concept/BoundingBox.ts +77 -0
  84. package/test/Domain/GeoJSON/Concept/ExteriorRing.ts +65 -0
  85. package/test/Domain/GeoJSON/Concept/GeoJSONObject.ts +56 -0
  86. package/test/Domain/GeoJSON/Concept/InteriorRing.ts +65 -0
  87. package/test/Domain/GeoJSON/Concept/Latitude.ts +56 -0
  88. package/test/Domain/GeoJSON/Concept/LinearRing.ts +63 -0
  89. package/test/Domain/GeoJSON/Concept/Longitude.ts +56 -0
  90. package/test/Domain/GeoJSON/Concept/Position.ts +56 -0
  91. package/test/Domain/GeoJSON/Feature.ts +9 -0
  92. package/test/Domain/GeoJSON/FeatureCollection.ts +9 -0
  93. package/test/Domain/GeoJSON/GeoJSON.ts +21 -0
  94. package/test/Domain/GeoJSON/Geometry/LineString.ts +11 -0
  95. package/test/Domain/GeoJSON/Geometry/MultiLineString.ts +11 -0
  96. package/test/Domain/GeoJSON/Geometry/MultiPoint.ts +11 -0
  97. package/test/Domain/GeoJSON/Geometry/MultiPolygon.ts +11 -0
  98. package/test/Domain/GeoJSON/Geometry/Point.ts +11 -0
  99. package/test/Domain/GeoJSON/Geometry/Polygon.ts +11 -0
  100. package/test/Domain/GeoJSON/Geometry.ts +9 -0
  101. package/test/Domain/GeoJSON/GeometryCollection.ts +9 -0
  102. package/test/Domain/GeoJSON/GeometryObject.ts +4 -0
  103. package/test/Domain/Guards/Number.ts +49 -0
  104. package/test/Domain/Guards/Tuple.ts +27 -0
  105. package/test/Domain/Iterator/IterablePair.ts +203 -0
  106. package/test/Domain/Iterator/SimpleGeometry.ts +195 -0
  107. package/test/Domain/Utility/Calculate.ts +178 -0
  108. package/test/Domain/Utility/Distance.ts +19 -0
  109. package/test/Domain/Utility/Intersect.ts +54 -0
  110. package/test/Domain/Utility/Numeric.ts +30 -0
  111. package/test/Domain/Utility/Winding.ts +52 -0
  112. package/test/README.ts +123 -0
  113. package/test/data/Distance.ts +51 -0
  114. package/test/data/HolySee.ts +74 -0
  115. package/test/data/Intersect.ts +300 -0
  116. package/test/data/Italy.ts +2883 -0
  117. package/test/data/SanMarino.ts +83 -0
  118. package/test/data/Shapes.ts +107 -0
  119. package/test/helper/geometry.ts +76 -0
  120. package/test/helper/malform.ts +82 -0
  121. package/test/main.ts +4 -0
  122. package/tsconfig.json +12 -0
@@ -0,0 +1,198 @@
1
+ import * as _konfirm_guard from '@konfirm/guard';
2
+
3
+ type Guard<T> = (value: any) => value is T;
4
+
5
+ type Longitude = number;
6
+
7
+ type Latitude = number;
8
+
9
+ type Altitude = number;
10
+
11
+ type BoundingBox = [Longitude, Latitude, Altitude, Longitude, Latitude, Altitude] | [Longitude, Latitude, Longitude, Latitude];
12
+
13
+ type GeoJSONBase = {
14
+ type: string;
15
+ bbox?: BoundingBox;
16
+ [key: string]: unknown;
17
+ };
18
+ type GeoJSONObject<T extends GeoJSONBase = GeoJSONBase> = GeoJSONBase & T;
19
+
20
+ type Position = [Longitude, Latitude, Altitude?];
21
+ declare const isPosition: _konfirm_guard.Guard<Position>;
22
+ declare const isStrictPosition: _konfirm_guard.Guard<Position>;
23
+
24
+ type GeometryBase = GeoJSONObject & {
25
+ coordinates: Array<unknown>;
26
+ };
27
+ type GeometryObject<T extends GeometryBase> = Omit<GeometryBase, 'coordinates'> & T;
28
+ type MultiGeometryObject<T extends GeometryBase> = GeometryObject<{
29
+ type: `Multi${T['type']}`;
30
+ coordinates: Array<T['coordinates']>;
31
+ }>;
32
+
33
+ type Point = GeometryObject<{
34
+ type: 'Point';
35
+ coordinates: Position;
36
+ }>;
37
+ declare const isPoint: Guard<Point>;
38
+ declare const isStrictPoint: Guard<Point>;
39
+
40
+ type MultiPoint = MultiGeometryObject<Point>;
41
+ declare const isMultiPoint: _konfirm_guard.Guard<MultiPoint>;
42
+ declare const isStrictMultiPoint: _konfirm_guard.Guard<MultiPoint>;
43
+
44
+ type LineString = GeometryObject<{
45
+ type: 'LineString';
46
+ coordinates: MultiPoint['coordinates'];
47
+ }>;
48
+ declare const isLineString: Guard<LineString>;
49
+ declare const isStrictLineString: Guard<LineString>;
50
+
51
+ type MultiLineString = MultiGeometryObject<LineString>;
52
+ declare const isMultiLineString: _konfirm_guard.Guard<MultiLineString>;
53
+ declare const isStrictMultiLineString: _konfirm_guard.Guard<MultiLineString>;
54
+
55
+ type LinearRing = Array<Position>;
56
+
57
+ type ExteriorRing = LinearRing;
58
+
59
+ type InteriorRing = LinearRing;
60
+
61
+ type Polygon = GeometryObject<{
62
+ type: 'Polygon';
63
+ coordinates: [ExteriorRing, ...Array<InteriorRing>];
64
+ }>;
65
+ declare const isPolygon: _konfirm_guard.Guard<Polygon>;
66
+ declare const isStrictPolygon: _konfirm_guard.Guard<Polygon>;
67
+
68
+ type MultiPolygon = MultiGeometryObject<Polygon>;
69
+ declare const isMultiPolygon: _konfirm_guard.Guard<MultiPolygon>;
70
+ declare const isStrictMultiPolygon: _konfirm_guard.Guard<MultiPolygon>;
71
+
72
+ type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
73
+ declare const isGeometry: _konfirm_guard.Guard<Geometry>;
74
+ declare const isStrictGeometry: _konfirm_guard.Guard<Geometry>;
75
+
76
+ type GeometryCollection = GeoJSONObject<{
77
+ type: 'GeometryCollection';
78
+ geometries: Array<Geometry | GeometryCollection>;
79
+ }>;
80
+ declare function isGeometryCollection(value: any): value is GeometryCollection;
81
+ declare function isStrictGeometryCollection(value: any): value is GeometryCollection;
82
+
83
+ type Feature = GeoJSONObject<{
84
+ type: 'Feature';
85
+ geometry: Geometry | GeometryCollection;
86
+ properties: {
87
+ [key: string]: unknown;
88
+ } | null;
89
+ }>;
90
+ declare const isFeature: _konfirm_guard.Guard<Feature>;
91
+ declare const isStrictFeature: _konfirm_guard.Guard<Feature>;
92
+
93
+ type FeatureCollection = GeoJSONObject<{
94
+ type: 'FeatureCollection';
95
+ features: Array<Feature>;
96
+ }>;
97
+ declare const isFeatureCollection: _konfirm_guard.Guard<FeatureCollection>;
98
+ declare const isStrictFeatureCollection: _konfirm_guard.Guard<FeatureCollection>;
99
+
100
+ type GeoJSON = Geometry | GeometryCollection | Feature | FeatureCollection;
101
+ declare const isGeoJSON: _konfirm_guard.Guard<GeoJSON>;
102
+ declare const isStrictGeoJSON: _konfirm_guard.Guard<GeoJSON>;
103
+
104
+ declare function intersect(a: GeoJSON, b: GeoJSON): boolean;
105
+
106
+ type PointToPointCalculation = 'cartesian' | 'haversine' | 'vincenty' | ((a: Point['coordinates'], b: Point['coordinates']) => number);
107
+
108
+ declare function distance(a: GeoJSON, b: GeoJSON, calculation?: PointToPointCalculation): number;
109
+
110
+ type SimpleGeometry = Point | LineString | Polygon;
111
+ /**
112
+ * Iterator class to turn any GeoJSON structure into one or more SimpleGeometry (Point | LineString | Polygon) objects
113
+ *
114
+ * @export
115
+ * @class SimpleGeometryIterator
116
+ */
117
+ declare class SimpleGeometryIterator {
118
+ private readonly inputs;
119
+ /**
120
+ * Creates an instance of SimpleGeometryIterator
121
+ *
122
+ * @param {...[GeoJSON, ...Array<GeoJSON>]} inputs
123
+ * @memberof SimpleGeometryIterator
124
+ */
125
+ constructor(...inputs: [GeoJSON, ...Array<GeoJSON>]);
126
+ /**
127
+ * Generator yielding all SimpleGeometry objects from the provided GeoJSON structure(s)
128
+ *
129
+ * @return {*} {Iterator<SimpleGeometry>}
130
+ * @memberof SimpleGeometryIterator
131
+ */
132
+ [Symbol.iterator](): Iterator<SimpleGeometry>;
133
+ /**
134
+ * unwrap any GeoJSON object into one or more SimpleGeometry object
135
+ *
136
+ * @private
137
+ * @param {GeoJSON} geo
138
+ * @return {*} {Iterable<SimpleGeometry>}
139
+ * @memberof SimpleGeometryIterator
140
+ */
141
+ private unwrap;
142
+ /**
143
+ * Generate the geometries in a GeometryCollection
144
+ *
145
+ * @private
146
+ * @param {GeometryCollection} { geometries }
147
+ * @return {*} {Iterable<SimpleGeometry>}
148
+ * @memberof SimpleGeometryIterator
149
+ */
150
+ private GeometryCollection;
151
+ /**
152
+ * Generate the geometries of the Feature object(s) in a FeatureCollection
153
+ *
154
+ * @private
155
+ * @param {FeatureCollection} { features }
156
+ * @return {*} {Iterable<SimpleGeometry>}
157
+ * @memberof SimpleGeometryIterator
158
+ */
159
+ private FeatureCollection;
160
+ /**
161
+ * Generate the geometry of a Feature object
162
+ *
163
+ * @private
164
+ * @param {Feature} { geometry }
165
+ * @return {*} {Iterable<SimpleGeometry>}
166
+ * @memberof SimpleGeometryIterator
167
+ */
168
+ private Feature;
169
+ /**
170
+ * Generate Point objects from a MultiPoint object
171
+ *
172
+ * @private
173
+ * @param {MultiPoint} multi
174
+ * @return {*} {Iterable<Point>}
175
+ * @memberof SimpleGeometryIterator
176
+ */
177
+ private MultiPoint;
178
+ /**
179
+ * Generate LineString objects from a MultiLineString object
180
+ *
181
+ * @private
182
+ * @param {MultiLineString} multi
183
+ * @return {*} {Iterable<LineString>}
184
+ * @memberof SimpleGeometryIterator
185
+ */
186
+ private MultiLineString;
187
+ /**
188
+ * Generate Polygon objects from a MultiPolygon object
189
+ *
190
+ * @private
191
+ * @param {MultiPolygon} multi
192
+ * @return {*} {Iterable<Polygon>}
193
+ * @memberof SimpleGeometryIterator
194
+ */
195
+ private MultiPolygon;
196
+ }
197
+
198
+ export { Feature, FeatureCollection, GeoJSON, Geometry, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Position, SimpleGeometryIterator, distance, intersect, isFeature, isFeatureCollection, isGeoJSON, isGeometry, isGeometryCollection, isLineString, isMultiLineString, isMultiPoint, isMultiPolygon, isPoint, isPolygon, isPosition, isStrictFeature, isStrictFeatureCollection, isStrictGeoJSON, isStrictGeometry, isStrictGeometryCollection, isStrictLineString, isStrictMultiLineString, isStrictMultiPoint, isStrictMultiPolygon, isStrictPoint, isStrictPolygon, isStrictPosition };