@turf/helpers 7.0.0-alpha.0 → 7.0.0-alpha.110

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.
@@ -1,12 +1,52 @@
1
- import { BBox, Feature, FeatureCollection, Geometry, GeometryCollection, GeometryObject, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Position, GeoJsonProperties } from "geojson";
2
- import { Id } from "./lib/geojson";
3
- export * from "./lib/geojson";
4
- export declare type Coord = Feature<Point> | Point | Position;
5
- export declare type Units = "meters" | "metres" | "millimeters" | "millimetres" | "centimeters" | "centimetres" | "kilometers" | "kilometres" | "acres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees" | "hectares";
6
- export declare type Grid = "point" | "square" | "hex" | "triangle";
7
- export declare type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid";
8
- export declare type Lines = LineString | MultiLineString | Polygon | MultiPolygon;
9
- export declare type AllGeoJSON = Feature | FeatureCollection | Geometry | GeometryCollection;
1
+ import { GeoJSON, Feature, Point, Position, LineString, MultiLineString, Polygon, MultiPolygon, FeatureCollection, Geometry, GeometryCollection, GeometryObject, GeoJsonProperties, BBox, MultiPoint } from 'geojson';
2
+
3
+ /**
4
+ * Id
5
+ *
6
+ * https://tools.ietf.org/html/rfc7946#section-3.2
7
+ * If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of
8
+ * the Feature object with the name "id", and the value of this member is either a JSON string or number.
9
+ *
10
+ * Should be contributed to @types/geojson
11
+ */
12
+ type Id = string | number;
13
+
14
+ /**
15
+
16
+ * GeoJSON equality checking utility.
17
+ * Adapted from https://github.com/geosquare/geojson-equality
18
+ *
19
+ * @memberof helpers
20
+ * @type {Class}
21
+ */
22
+ declare class GeojsonEquality {
23
+ private precision;
24
+ private direction;
25
+ private compareProperties;
26
+ constructor(opts?: {
27
+ precision?: number;
28
+ direction?: boolean;
29
+ compareProperties?: boolean;
30
+ });
31
+ compare(g1: GeoJSON, g2: GeoJSON): boolean;
32
+ private compareCoord;
33
+ private compareLine;
34
+ private fixStartIndex;
35
+ private comparePath;
36
+ private comparePolygon;
37
+ private compareGeometryCollection;
38
+ private compareFeature;
39
+ private compareFeatureCollection;
40
+ private compareBBox;
41
+ }
42
+
43
+ type Coord = Feature<Point> | Point | Position;
44
+ type Units = "meters" | "metres" | "millimeters" | "millimetres" | "centimeters" | "centimetres" | "kilometers" | "kilometres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees";
45
+ type AreaUnits = Exclude<Units, "radians" | "degrees"> | "acres" | "hectares";
46
+ type Grid = "point" | "square" | "hex" | "triangle";
47
+ type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid";
48
+ type Lines = LineString | MultiLineString | Polygon | MultiPolygon;
49
+ type AllGeoJSON = Feature | FeatureCollection | Geometry | GeometryCollection;
10
50
  /**
11
51
  * @module helpers
12
52
  */
@@ -16,7 +56,7 @@ export declare type AllGeoJSON = Feature | FeatureCollection | Geometry | Geomet
16
56
  * @memberof helpers
17
57
  * @type {number}
18
58
  */
19
- export declare const earthRadius = 6371008.8;
59
+ declare const earthRadius = 6371008.8;
20
60
  /**
21
61
  * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
22
62
  *
@@ -25,9 +65,7 @@ export declare const earthRadius = 6371008.8;
25
65
  * @memberof helpers
26
66
  * @type {Object}
27
67
  */
28
- export declare const factors: {
29
- [key: string]: number;
30
- };
68
+ declare const factors: Record<Units, number>;
31
69
  /**
32
70
 
33
71
  * Area of measurement factors based on 1 square meter.
@@ -35,9 +73,7 @@ export declare const factors: {
35
73
  * @memberof helpers
36
74
  * @type {Object}
37
75
  */
38
- export declare const areaFactors: {
39
- [key: string]: number;
40
- };
76
+ declare const areaFactors: Record<AreaUnits, number>;
41
77
  /**
42
78
  * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
43
79
  *
@@ -58,7 +94,7 @@ export declare const areaFactors: {
58
94
  *
59
95
  * //=feature
60
96
  */
61
- export declare function feature<G extends GeometryObject = Geometry, P = GeoJsonProperties>(geom: G | null, properties?: P, options?: {
97
+ declare function feature<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(geom: G | null, properties?: P, options?: {
62
98
  bbox?: BBox;
63
99
  id?: Id;
64
100
  }): Feature<G, P>;
@@ -77,7 +113,7 @@ export declare function feature<G extends GeometryObject = Geometry, P = GeoJson
77
113
  * var geometry = turf.geometry(type, coordinates);
78
114
  * // => geometry
79
115
  */
80
- export declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
116
+ declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
81
117
  /**
82
118
  * Creates a {@link Point} {@link Feature} from a Position.
83
119
  *
@@ -93,7 +129,7 @@ export declare function geometry(type: "Point" | "LineString" | "Polygon" | "Mul
93
129
  *
94
130
  * //=point
95
131
  */
96
- export declare function point<P = GeoJsonProperties>(coordinates: Position, properties?: P, options?: {
132
+ declare function point<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position, properties?: P, options?: {
97
133
  bbox?: BBox;
98
134
  id?: Id;
99
135
  }): Feature<Point, P>;
@@ -117,7 +153,7 @@ export declare function point<P = GeoJsonProperties>(coordinates: Position, prop
117
153
  *
118
154
  * //=points
119
155
  */
120
- export declare function points<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
156
+ declare function points<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
121
157
  bbox?: BBox;
122
158
  id?: Id;
123
159
  }): FeatureCollection<Point, P>;
@@ -136,7 +172,7 @@ export declare function points<P = GeoJsonProperties>(coordinates: Position[], p
136
172
  *
137
173
  * //=polygon
138
174
  */
139
- export declare function polygon<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
175
+ declare function polygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
140
176
  bbox?: BBox;
141
177
  id?: Id;
142
178
  }): Feature<Polygon, P>;
@@ -158,7 +194,7 @@ export declare function polygon<P = GeoJsonProperties>(coordinates: Position[][]
158
194
  *
159
195
  * //=polygons
160
196
  */
161
- export declare function polygons<P = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
197
+ declare function polygons<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
162
198
  bbox?: BBox;
163
199
  id?: Id;
164
200
  }): FeatureCollection<Polygon, P>;
@@ -179,7 +215,7 @@ export declare function polygons<P = GeoJsonProperties>(coordinates: Position[][
179
215
  * //=linestring1
180
216
  * //=linestring2
181
217
  */
182
- export declare function lineString<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
218
+ declare function lineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
183
219
  bbox?: BBox;
184
220
  id?: Id;
185
221
  }): Feature<LineString, P>;
@@ -202,7 +238,7 @@ export declare function lineString<P = GeoJsonProperties>(coordinates: Position[
202
238
  *
203
239
  * //=linestrings
204
240
  */
205
- export declare function lineStrings<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
241
+ declare function lineStrings<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
206
242
  bbox?: BBox;
207
243
  id?: Id;
208
244
  }): FeatureCollection<LineString, P>;
@@ -228,7 +264,7 @@ export declare function lineStrings<P = GeoJsonProperties>(coordinates: Position
228
264
  *
229
265
  * //=collection
230
266
  */
231
- export declare function featureCollection<G extends GeometryObject = Geometry, P = GeoJsonProperties>(features: Array<Feature<G, P>>, options?: {
267
+ declare function featureCollection<G extends GeometryObject = Geometry, P extends GeoJsonProperties = GeoJsonProperties>(features: Array<Feature<G, P>>, options?: {
232
268
  bbox?: BBox;
233
269
  id?: Id;
234
270
  }): FeatureCollection<G, P>;
@@ -249,7 +285,7 @@ export declare function featureCollection<G extends GeometryObject = Geometry, P
249
285
  *
250
286
  * //=multiLine
251
287
  */
252
- export declare function multiLineString<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
288
+ declare function multiLineString<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: {
253
289
  bbox?: BBox;
254
290
  id?: Id;
255
291
  }): Feature<MultiLineString, P>;
@@ -270,7 +306,7 @@ export declare function multiLineString<P = GeoJsonProperties>(coordinates: Posi
270
306
  *
271
307
  * //=multiPt
272
308
  */
273
- export declare function multiPoint<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
309
+ declare function multiPoint<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: {
274
310
  bbox?: BBox;
275
311
  id?: Id;
276
312
  }): Feature<MultiPoint, P>;
@@ -292,7 +328,7 @@ export declare function multiPoint<P = GeoJsonProperties>(coordinates: Position[
292
328
  * //=multiPoly
293
329
  *
294
330
  */
295
- export declare function multiPolygon<P = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
331
+ declare function multiPolygon<P extends GeoJsonProperties = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: {
296
332
  bbox?: BBox;
297
333
  id?: Id;
298
334
  }): Feature<MultiPolygon, P>;
@@ -314,7 +350,7 @@ export declare function multiPolygon<P = GeoJsonProperties>(coordinates: Positio
314
350
  *
315
351
  * // => collection
316
352
  */
317
- export declare function geometryCollection<P = GeoJsonProperties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: {
353
+ declare function geometryCollection<P extends GeoJsonProperties = GeoJsonProperties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: {
318
354
  bbox?: BBox;
319
355
  id?: Id;
320
356
  }): Feature<GeometryCollection, P>;
@@ -331,7 +367,7 @@ export declare function geometryCollection<P = GeoJsonProperties>(geometries: Ar
331
367
  * turf.round(120.4321, 2)
332
368
  * //=120.43
333
369
  */
334
- export declare function round(num: number, precision?: number): number;
370
+ declare function round(num: number, precision?: number): number;
335
371
  /**
336
372
  * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
337
373
  * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
@@ -342,7 +378,7 @@ export declare function round(num: number, precision?: number): number;
342
378
  * meters, kilometres, kilometers.
343
379
  * @returns {number} distance
344
380
  */
345
- export declare function radiansToLength(radians: number, units?: Units): number;
381
+ declare function radiansToLength(radians: number, units?: Units): number;
346
382
  /**
347
383
  * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
348
384
  * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
@@ -353,7 +389,7 @@ export declare function radiansToLength(radians: number, units?: Units): number;
353
389
  * meters, kilometres, kilometers.
354
390
  * @returns {number} radians
355
391
  */
356
- export declare function lengthToRadians(distance: number, units?: Units): number;
392
+ declare function lengthToRadians(distance: number, units?: Units): number;
357
393
  /**
358
394
  * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
359
395
  * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
@@ -364,7 +400,7 @@ export declare function lengthToRadians(distance: number, units?: Units): number
364
400
  * meters, kilometres, kilometers.
365
401
  * @returns {number} degrees
366
402
  */
367
- export declare function lengthToDegrees(distance: number, units?: Units): number;
403
+ declare function lengthToDegrees(distance: number, units?: Units): number;
368
404
  /**
369
405
  * Converts any bearing angle from the north line direction (positive clockwise)
370
406
  * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
@@ -373,7 +409,7 @@ export declare function lengthToDegrees(distance: number, units?: Units): number
373
409
  * @param {number} bearing angle, between -180 and +180 degrees
374
410
  * @returns {number} angle between 0 and 360 degrees
375
411
  */
376
- export declare function bearingToAzimuth(bearing: number): number;
412
+ declare function bearingToAzimuth(bearing: number): number;
377
413
  /**
378
414
  * Converts an angle in radians to degrees
379
415
  *
@@ -381,7 +417,7 @@ export declare function bearingToAzimuth(bearing: number): number;
381
417
  * @param {number} radians angle in radians
382
418
  * @returns {number} degrees between 0 and 360 degrees
383
419
  */
384
- export declare function radiansToDegrees(radians: number): number;
420
+ declare function radiansToDegrees(radians: number): number;
385
421
  /**
386
422
  * Converts an angle in degrees to radians
387
423
  *
@@ -389,7 +425,7 @@ export declare function radiansToDegrees(radians: number): number;
389
425
  * @param {number} degrees angle between 0 and 360 degrees
390
426
  * @returns {number} angle in radians
391
427
  */
392
- export declare function degreesToRadians(degrees: number): number;
428
+ declare function degreesToRadians(degrees: number): number;
393
429
  /**
394
430
  * Converts a length to the requested unit.
395
431
  * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
@@ -399,7 +435,7 @@ export declare function degreesToRadians(degrees: number): number;
399
435
  * @param {Units} [finalUnit="kilometers"] returned unit
400
436
  * @returns {number} the converted length
401
437
  */
402
- export declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
438
+ declare function convertLength(length: number, originalUnit?: Units, finalUnit?: Units): number;
403
439
  /**
404
440
  * Converts a area to the requested unit.
405
441
  * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
@@ -408,7 +444,7 @@ export declare function convertLength(length: number, originalUnit?: Units, fina
408
444
  * @param {Units} [finalUnit="kilometers"] returned unit
409
445
  * @returns {number} the converted area
410
446
  */
411
- export declare function convertArea(area: number, originalUnit?: Units, finalUnit?: Units): number;
447
+ declare function convertArea(area: number, originalUnit?: AreaUnits, finalUnit?: AreaUnits): number;
412
448
  /**
413
449
  * isNumber
414
450
  *
@@ -420,7 +456,7 @@ export declare function convertArea(area: number, originalUnit?: Units, finalUni
420
456
  * turf.isNumber('foo')
421
457
  * //=false
422
458
  */
423
- export declare function isNumber(num: any): boolean;
459
+ declare function isNumber(num: any): boolean;
424
460
  /**
425
461
  * isObject
426
462
  *
@@ -432,7 +468,7 @@ export declare function isNumber(num: any): boolean;
432
468
  * turf.isObject('foo')
433
469
  * //=false
434
470
  */
435
- export declare function isObject(input: any): boolean;
471
+ declare function isObject(input: any): boolean;
436
472
  /**
437
473
  * Validate BBox
438
474
  *
@@ -454,7 +490,7 @@ export declare function isObject(input: any): boolean;
454
490
  * validateBBox(undefined)
455
491
  * //=Error
456
492
  */
457
- export declare function validateBBox(bbox: any): void;
493
+ declare function validateBBox(bbox: any): void;
458
494
  /**
459
495
  * Validate Id
460
496
  *
@@ -476,4 +512,6 @@ export declare function validateBBox(bbox: any): void;
476
512
  * validateId(undefined)
477
513
  * //=Error
478
514
  */
479
- export declare function validateId(id: any): void;
515
+ declare function validateId(id: any): void;
516
+
517
+ export { type AllGeoJSON, type AreaUnits, type Coord, type Corners, GeojsonEquality, type Grid, type Id, type Lines, type Units, areaFactors, bearingToAzimuth, convertArea, convertLength, degreesToRadians, earthRadius, factors, feature, featureCollection, geometry, geometryCollection, isNumber, isObject, lengthToDegrees, lengthToRadians, lineString, lineStrings, multiLineString, multiPoint, multiPolygon, point, points, polygon, polygons, radiansToDegrees, radiansToLength, round, validateBBox, validateId };