@turf/helpers 7.0.0-alpha.2 → 7.1.0-alpha.7

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/dist/js/index.js DELETED
@@ -1,687 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * @module helpers
5
- */
6
- /**
7
- * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
8
- *
9
- * @memberof helpers
10
- * @type {number}
11
- */
12
- exports.earthRadius = 6371008.8;
13
- /**
14
- * Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
15
- *
16
- * Keys are the name of the unit, values are the number of that unit in a single radian
17
- *
18
- * @memberof helpers
19
- * @type {Object}
20
- */
21
- exports.factors = {
22
- centimeters: exports.earthRadius * 100,
23
- centimetres: exports.earthRadius * 100,
24
- degrees: 360 / (2 * Math.PI),
25
- feet: exports.earthRadius * 3.28084,
26
- inches: exports.earthRadius * 39.37,
27
- kilometers: exports.earthRadius / 1000,
28
- kilometres: exports.earthRadius / 1000,
29
- meters: exports.earthRadius,
30
- metres: exports.earthRadius,
31
- miles: exports.earthRadius / 1609.344,
32
- millimeters: exports.earthRadius * 1000,
33
- millimetres: exports.earthRadius * 1000,
34
- nauticalmiles: exports.earthRadius / 1852,
35
- radians: 1,
36
- yards: exports.earthRadius * 1.0936,
37
- };
38
- /**
39
-
40
- * Area of measurement factors based on 1 square meter.
41
- *
42
- * @memberof helpers
43
- * @type {Object}
44
- */
45
- exports.areaFactors = {
46
- acres: 0.000247105,
47
- centimeters: 10000,
48
- centimetres: 10000,
49
- feet: 10.763910417,
50
- hectares: 0.0001,
51
- inches: 1550.003100006,
52
- kilometers: 0.000001,
53
- kilometres: 0.000001,
54
- meters: 1,
55
- metres: 1,
56
- miles: 3.86e-7,
57
- nauticalmiles: 2.9155334959812285e-7,
58
- millimeters: 1000000,
59
- millimetres: 1000000,
60
- yards: 1.195990046,
61
- };
62
- /**
63
- * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
64
- *
65
- * @name feature
66
- * @param {Geometry} geometry input geometry
67
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
68
- * @param {Object} [options={}] Optional Parameters
69
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
70
- * @param {string|number} [options.id] Identifier associated with the Feature
71
- * @returns {Feature} a GeoJSON Feature
72
- * @example
73
- * var geometry = {
74
- * "type": "Point",
75
- * "coordinates": [110, 50]
76
- * };
77
- *
78
- * var feature = turf.feature(geometry);
79
- *
80
- * //=feature
81
- */
82
- function feature(geom, properties, options = {}) {
83
- const feat = { type: "Feature" };
84
- if (options.id === 0 || options.id) {
85
- feat.id = options.id;
86
- }
87
- if (options.bbox) {
88
- feat.bbox = options.bbox;
89
- }
90
- feat.properties = properties || {};
91
- feat.geometry = geom;
92
- return feat;
93
- }
94
- exports.feature = feature;
95
- /**
96
- * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
97
- * For GeometryCollection type use `helpers.geometryCollection`
98
- *
99
- * @name geometry
100
- * @param {string} type Geometry Type
101
- * @param {Array<any>} coordinates Coordinates
102
- * @param {Object} [options={}] Optional Parameters
103
- * @returns {Geometry} a GeoJSON Geometry
104
- * @example
105
- * var type = "Point";
106
- * var coordinates = [110, 50];
107
- * var geometry = turf.geometry(type, coordinates);
108
- * // => geometry
109
- */
110
- function geometry(type, coordinates, _options = {}) {
111
- switch (type) {
112
- case "Point":
113
- return point(coordinates).geometry;
114
- case "LineString":
115
- return lineString(coordinates).geometry;
116
- case "Polygon":
117
- return polygon(coordinates).geometry;
118
- case "MultiPoint":
119
- return multiPoint(coordinates).geometry;
120
- case "MultiLineString":
121
- return multiLineString(coordinates).geometry;
122
- case "MultiPolygon":
123
- return multiPolygon(coordinates).geometry;
124
- default:
125
- throw new Error(type + " is invalid");
126
- }
127
- }
128
- exports.geometry = geometry;
129
- /**
130
- * Creates a {@link Point} {@link Feature} from a Position.
131
- *
132
- * @name point
133
- * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
134
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
135
- * @param {Object} [options={}] Optional Parameters
136
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
137
- * @param {string|number} [options.id] Identifier associated with the Feature
138
- * @returns {Feature<Point>} a Point feature
139
- * @example
140
- * var point = turf.point([-75.343, 39.984]);
141
- *
142
- * //=point
143
- */
144
- function point(coordinates, properties, options = {}) {
145
- if (!coordinates) {
146
- throw new Error("coordinates is required");
147
- }
148
- if (!Array.isArray(coordinates)) {
149
- throw new Error("coordinates must be an Array");
150
- }
151
- if (coordinates.length < 2) {
152
- throw new Error("coordinates must be at least 2 numbers long");
153
- }
154
- if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
155
- throw new Error("coordinates must contain numbers");
156
- }
157
- const geom = {
158
- type: "Point",
159
- coordinates,
160
- };
161
- return feature(geom, properties, options);
162
- }
163
- exports.point = point;
164
- /**
165
- * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
166
- *
167
- * @name points
168
- * @param {Array<Array<number>>} coordinates an array of Points
169
- * @param {Object} [properties={}] Translate these properties to each Feature
170
- * @param {Object} [options={}] Optional Parameters
171
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
172
- * associated with the FeatureCollection
173
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
174
- * @returns {FeatureCollection<Point>} Point Feature
175
- * @example
176
- * var points = turf.points([
177
- * [-75, 39],
178
- * [-80, 45],
179
- * [-78, 50]
180
- * ]);
181
- *
182
- * //=points
183
- */
184
- function points(coordinates, properties, options = {}) {
185
- return featureCollection(coordinates.map((coords) => {
186
- return point(coords, properties);
187
- }), options);
188
- }
189
- exports.points = points;
190
- /**
191
- * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
192
- *
193
- * @name polygon
194
- * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
195
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
196
- * @param {Object} [options={}] Optional Parameters
197
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
198
- * @param {string|number} [options.id] Identifier associated with the Feature
199
- * @returns {Feature<Polygon>} Polygon Feature
200
- * @example
201
- * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
202
- *
203
- * //=polygon
204
- */
205
- function polygon(coordinates, properties, options = {}) {
206
- for (const ring of coordinates) {
207
- if (ring.length < 4) {
208
- throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
209
- }
210
- if (ring[ring.length - 1].length !== ring[0].length) {
211
- throw new Error("First and last Position are not equivalent.");
212
- }
213
- for (let j = 0; j < ring[ring.length - 1].length; j++) {
214
- // Check if first point of Polygon contains two numbers
215
- if (ring[ring.length - 1][j] !== ring[0][j]) {
216
- throw new Error("First and last Position are not equivalent.");
217
- }
218
- }
219
- }
220
- const geom = {
221
- type: "Polygon",
222
- coordinates,
223
- };
224
- return feature(geom, properties, options);
225
- }
226
- exports.polygon = polygon;
227
- /**
228
- * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
229
- *
230
- * @name polygons
231
- * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
232
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
233
- * @param {Object} [options={}] Optional Parameters
234
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
235
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
236
- * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
237
- * @example
238
- * var polygons = turf.polygons([
239
- * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
240
- * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
241
- * ]);
242
- *
243
- * //=polygons
244
- */
245
- function polygons(coordinates, properties, options = {}) {
246
- return featureCollection(coordinates.map((coords) => {
247
- return polygon(coords, properties);
248
- }), options);
249
- }
250
- exports.polygons = polygons;
251
- /**
252
- * Creates a {@link LineString} {@link Feature} from an Array of Positions.
253
- *
254
- * @name lineString
255
- * @param {Array<Array<number>>} coordinates an array of Positions
256
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
257
- * @param {Object} [options={}] Optional Parameters
258
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
259
- * @param {string|number} [options.id] Identifier associated with the Feature
260
- * @returns {Feature<LineString>} LineString Feature
261
- * @example
262
- * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
263
- * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
264
- *
265
- * //=linestring1
266
- * //=linestring2
267
- */
268
- function lineString(coordinates, properties, options = {}) {
269
- if (coordinates.length < 2) {
270
- throw new Error("coordinates must be an array of two or more positions");
271
- }
272
- const geom = {
273
- type: "LineString",
274
- coordinates,
275
- };
276
- return feature(geom, properties, options);
277
- }
278
- exports.lineString = lineString;
279
- /**
280
- * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
281
- *
282
- * @name lineStrings
283
- * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
284
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
285
- * @param {Object} [options={}] Optional Parameters
286
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north]
287
- * associated with the FeatureCollection
288
- * @param {string|number} [options.id] Identifier associated with the FeatureCollection
289
- * @returns {FeatureCollection<LineString>} LineString FeatureCollection
290
- * @example
291
- * var linestrings = turf.lineStrings([
292
- * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
293
- * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
294
- * ]);
295
- *
296
- * //=linestrings
297
- */
298
- function lineStrings(coordinates, properties, options = {}) {
299
- return featureCollection(coordinates.map((coords) => {
300
- return lineString(coords, properties);
301
- }), options);
302
- }
303
- exports.lineStrings = lineStrings;
304
- /**
305
- * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
306
- *
307
- * @name featureCollection
308
- * @param {Feature[]} features input features
309
- * @param {Object} [options={}] Optional Parameters
310
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
311
- * @param {string|number} [options.id] Identifier associated with the Feature
312
- * @returns {FeatureCollection} FeatureCollection of Features
313
- * @example
314
- * var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
315
- * var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
316
- * var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
317
- *
318
- * var collection = turf.featureCollection([
319
- * locationA,
320
- * locationB,
321
- * locationC
322
- * ]);
323
- *
324
- * //=collection
325
- */
326
- function featureCollection(features, options = {}) {
327
- const fc = { type: "FeatureCollection" };
328
- if (options.id) {
329
- fc.id = options.id;
330
- }
331
- if (options.bbox) {
332
- fc.bbox = options.bbox;
333
- }
334
- fc.features = features;
335
- return fc;
336
- }
337
- exports.featureCollection = featureCollection;
338
- /**
339
- * Creates a {@link Feature<MultiLineString>} based on a
340
- * coordinate array. Properties can be added optionally.
341
- *
342
- * @name multiLineString
343
- * @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
344
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
345
- * @param {Object} [options={}] Optional Parameters
346
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
347
- * @param {string|number} [options.id] Identifier associated with the Feature
348
- * @returns {Feature<MultiLineString>} a MultiLineString feature
349
- * @throws {Error} if no coordinates are passed
350
- * @example
351
- * var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
352
- *
353
- * //=multiLine
354
- */
355
- function multiLineString(coordinates, properties, options = {}) {
356
- const geom = {
357
- type: "MultiLineString",
358
- coordinates,
359
- };
360
- return feature(geom, properties, options);
361
- }
362
- exports.multiLineString = multiLineString;
363
- /**
364
- * Creates a {@link Feature<MultiPoint>} based on a
365
- * coordinate array. Properties can be added optionally.
366
- *
367
- * @name multiPoint
368
- * @param {Array<Array<number>>} coordinates an array of Positions
369
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
370
- * @param {Object} [options={}] Optional Parameters
371
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
372
- * @param {string|number} [options.id] Identifier associated with the Feature
373
- * @returns {Feature<MultiPoint>} a MultiPoint feature
374
- * @throws {Error} if no coordinates are passed
375
- * @example
376
- * var multiPt = turf.multiPoint([[0,0],[10,10]]);
377
- *
378
- * //=multiPt
379
- */
380
- function multiPoint(coordinates, properties, options = {}) {
381
- const geom = {
382
- type: "MultiPoint",
383
- coordinates,
384
- };
385
- return feature(geom, properties, options);
386
- }
387
- exports.multiPoint = multiPoint;
388
- /**
389
- * Creates a {@link Feature<MultiPolygon>} based on a
390
- * coordinate array. Properties can be added optionally.
391
- *
392
- * @name multiPolygon
393
- * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
394
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
395
- * @param {Object} [options={}] Optional Parameters
396
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
397
- * @param {string|number} [options.id] Identifier associated with the Feature
398
- * @returns {Feature<MultiPolygon>} a multipolygon feature
399
- * @throws {Error} if no coordinates are passed
400
- * @example
401
- * var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
402
- *
403
- * //=multiPoly
404
- *
405
- */
406
- function multiPolygon(coordinates, properties, options = {}) {
407
- const geom = {
408
- type: "MultiPolygon",
409
- coordinates,
410
- };
411
- return feature(geom, properties, options);
412
- }
413
- exports.multiPolygon = multiPolygon;
414
- /**
415
- * Creates a {@link Feature<GeometryCollection>} based on a
416
- * coordinate array. Properties can be added optionally.
417
- *
418
- * @name geometryCollection
419
- * @param {Array<Geometry>} geometries an array of GeoJSON Geometries
420
- * @param {Object} [properties={}] an Object of key-value pairs to add as properties
421
- * @param {Object} [options={}] Optional Parameters
422
- * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
423
- * @param {string|number} [options.id] Identifier associated with the Feature
424
- * @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature
425
- * @example
426
- * var pt = turf.geometry("Point", [100, 0]);
427
- * var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
428
- * var collection = turf.geometryCollection([pt, line]);
429
- *
430
- * // => collection
431
- */
432
- function geometryCollection(geometries, properties, options = {}) {
433
- const geom = {
434
- type: "GeometryCollection",
435
- geometries,
436
- };
437
- return feature(geom, properties, options);
438
- }
439
- exports.geometryCollection = geometryCollection;
440
- /**
441
- * Round number to precision
442
- *
443
- * @param {number} num Number
444
- * @param {number} [precision=0] Precision
445
- * @returns {number} rounded number
446
- * @example
447
- * turf.round(120.4321)
448
- * //=120
449
- *
450
- * turf.round(120.4321, 2)
451
- * //=120.43
452
- */
453
- function round(num, precision = 0) {
454
- if (precision && !(precision >= 0)) {
455
- throw new Error("precision must be a positive number");
456
- }
457
- const multiplier = Math.pow(10, precision || 0);
458
- return Math.round(num * multiplier) / multiplier;
459
- }
460
- exports.round = round;
461
- /**
462
- * Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
463
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
464
- *
465
- * @name radiansToLength
466
- * @param {number} radians in radians across the sphere
467
- * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
468
- * meters, kilometres, kilometers.
469
- * @returns {number} distance
470
- */
471
- function radiansToLength(radians, units = "kilometers") {
472
- const factor = exports.factors[units];
473
- if (!factor) {
474
- throw new Error(units + " units is invalid");
475
- }
476
- return radians * factor;
477
- }
478
- exports.radiansToLength = radiansToLength;
479
- /**
480
- * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
481
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
482
- *
483
- * @name lengthToRadians
484
- * @param {number} distance in real units
485
- * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
486
- * meters, kilometres, kilometers.
487
- * @returns {number} radians
488
- */
489
- function lengthToRadians(distance, units = "kilometers") {
490
- const factor = exports.factors[units];
491
- if (!factor) {
492
- throw new Error(units + " units is invalid");
493
- }
494
- return distance / factor;
495
- }
496
- exports.lengthToRadians = lengthToRadians;
497
- /**
498
- * Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
499
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
500
- *
501
- * @name lengthToDegrees
502
- * @param {number} distance in real units
503
- * @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
504
- * meters, kilometres, kilometers.
505
- * @returns {number} degrees
506
- */
507
- function lengthToDegrees(distance, units) {
508
- return radiansToDegrees(lengthToRadians(distance, units));
509
- }
510
- exports.lengthToDegrees = lengthToDegrees;
511
- /**
512
- * Converts any bearing angle from the north line direction (positive clockwise)
513
- * and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
514
- *
515
- * @name bearingToAzimuth
516
- * @param {number} bearing angle, between -180 and +180 degrees
517
- * @returns {number} angle between 0 and 360 degrees
518
- */
519
- function bearingToAzimuth(bearing) {
520
- let angle = bearing % 360;
521
- if (angle < 0) {
522
- angle += 360;
523
- }
524
- return angle;
525
- }
526
- exports.bearingToAzimuth = bearingToAzimuth;
527
- /**
528
- * Converts an angle in radians to degrees
529
- *
530
- * @name radiansToDegrees
531
- * @param {number} radians angle in radians
532
- * @returns {number} degrees between 0 and 360 degrees
533
- */
534
- function radiansToDegrees(radians) {
535
- const degrees = radians % (2 * Math.PI);
536
- return (degrees * 180) / Math.PI;
537
- }
538
- exports.radiansToDegrees = radiansToDegrees;
539
- /**
540
- * Converts an angle in degrees to radians
541
- *
542
- * @name degreesToRadians
543
- * @param {number} degrees angle between 0 and 360 degrees
544
- * @returns {number} angle in radians
545
- */
546
- function degreesToRadians(degrees) {
547
- const radians = degrees % 360;
548
- return (radians * Math.PI) / 180;
549
- }
550
- exports.degreesToRadians = degreesToRadians;
551
- /**
552
- * Converts a length to the requested unit.
553
- * Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
554
- *
555
- * @param {number} length to be converted
556
- * @param {Units} [originalUnit="kilometers"] of the length
557
- * @param {Units} [finalUnit="kilometers"] returned unit
558
- * @returns {number} the converted length
559
- */
560
- function convertLength(length, originalUnit = "kilometers", finalUnit = "kilometers") {
561
- if (!(length >= 0)) {
562
- throw new Error("length must be a positive number");
563
- }
564
- return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
565
- }
566
- exports.convertLength = convertLength;
567
- /**
568
- * Converts a area to the requested unit.
569
- * Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
570
- * @param {number} area to be converted
571
- * @param {Units} [originalUnit="meters"] of the distance
572
- * @param {Units} [finalUnit="kilometers"] returned unit
573
- * @returns {number} the converted area
574
- */
575
- function convertArea(area, originalUnit = "meters", finalUnit = "kilometers") {
576
- if (!(area >= 0)) {
577
- throw new Error("area must be a positive number");
578
- }
579
- const startFactor = exports.areaFactors[originalUnit];
580
- if (!startFactor) {
581
- throw new Error("invalid original units");
582
- }
583
- const finalFactor = exports.areaFactors[finalUnit];
584
- if (!finalFactor) {
585
- throw new Error("invalid final units");
586
- }
587
- return (area / startFactor) * finalFactor;
588
- }
589
- exports.convertArea = convertArea;
590
- /**
591
- * isNumber
592
- *
593
- * @param {*} num Number to validate
594
- * @returns {boolean} true/false
595
- * @example
596
- * turf.isNumber(123)
597
- * //=true
598
- * turf.isNumber('foo')
599
- * //=false
600
- */
601
- function isNumber(num) {
602
- return !isNaN(num) && num !== null && !Array.isArray(num);
603
- }
604
- exports.isNumber = isNumber;
605
- /**
606
- * isObject
607
- *
608
- * @param {*} input variable to validate
609
- * @returns {boolean} true/false, including false for Arrays and Functions
610
- * @example
611
- * turf.isObject({elevation: 10})
612
- * //=true
613
- * turf.isObject('foo')
614
- * //=false
615
- */
616
- function isObject(input) {
617
- return input !== null && typeof input === "object" && !Array.isArray(input);
618
- }
619
- exports.isObject = isObject;
620
- /**
621
- * Validate BBox
622
- *
623
- * @private
624
- * @param {Array<number>} bbox BBox to validate
625
- * @returns {void}
626
- * @throws {Error} if BBox is not valid
627
- * @example
628
- * validateBBox([-180, -40, 110, 50])
629
- * //=OK
630
- * validateBBox([-180, -40])
631
- * //=Error
632
- * validateBBox('Foo')
633
- * //=Error
634
- * validateBBox(5)
635
- * //=Error
636
- * validateBBox(null)
637
- * //=Error
638
- * validateBBox(undefined)
639
- * //=Error
640
- */
641
- function validateBBox(bbox) {
642
- if (!bbox) {
643
- throw new Error("bbox is required");
644
- }
645
- if (!Array.isArray(bbox)) {
646
- throw new Error("bbox must be an Array");
647
- }
648
- if (bbox.length !== 4 && bbox.length !== 6) {
649
- throw new Error("bbox must be an Array of 4 or 6 numbers");
650
- }
651
- bbox.forEach((num) => {
652
- if (!isNumber(num)) {
653
- throw new Error("bbox must only contain numbers");
654
- }
655
- });
656
- }
657
- exports.validateBBox = validateBBox;
658
- /**
659
- * Validate Id
660
- *
661
- * @private
662
- * @param {string|number} id Id to validate
663
- * @returns {void}
664
- * @throws {Error} if Id is not valid
665
- * @example
666
- * validateId([-180, -40, 110, 50])
667
- * //=Error
668
- * validateId([-180, -40])
669
- * //=Error
670
- * validateId('Foo')
671
- * //=OK
672
- * validateId(5)
673
- * //=OK
674
- * validateId(null)
675
- * //=Error
676
- * validateId(undefined)
677
- * //=Error
678
- */
679
- function validateId(id) {
680
- if (!id) {
681
- throw new Error("id is required");
682
- }
683
- if (["string", "number"].indexOf(typeof id) === -1) {
684
- throw new Error("id must be a number or a string");
685
- }
686
- }
687
- exports.validateId = validateId;
@@ -1,10 +0,0 @@
1
- /**
2
- * Id
3
- *
4
- * https://tools.ietf.org/html/rfc7946#section-3.2
5
- * If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of
6
- * the Feature object with the name "id", and the value of this member is either a JSON string or number.
7
- *
8
- * Should be contributed to @types/geojson
9
- */
10
- export declare type Id = string | number;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });