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