import lineStringToPolygon from '@turf/linestring-to-polygon';
import { lineString, featureCollection } from '@turf/helpers';
import { getCoords } from '@turf/invariant';
import d3voronoi from 'd3-voronoi';

/**
 * @param {Array<Array<number>>} coords representing a polygon
 * @returns {Feature<Polygon>} polygon
 */
function coordsToPolygon(coords) {
    return lineStringToPolygon(lineString(coords.slice(0)));
}

/**
 * Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection
 * of Voronoi polygons. 
 * 
 * The Voronoi algorithim used comes from the d3-voronoi package.
 *
 * @name voronoi
 * @param {FeatureCollection<Point>} points to find the Voronoi polygons around.
 * @param {number[]} bbox clipping rectangle, in [minX, minY, maxX, MaxY] order.
 * @returns {FeatureCollection<Polygon>} a set of polygons, one per input polygon.
 * @example
 * var bbox = [-70, 40, -60, 60];
 * var points = turf.randomPoints(100, { bbox: bbox }); 
 * var voronoiPolygons = turf.voronoi(points, bbox);
 */
function voronoi(points, bbox) {
    if (!points) throw new Error('points is required');
    if (!bbox) throw new Error('bbox is required');
    if (!Array.isArray(bbox)) throw new Error('bbox is invalid');

    var d3v = d3voronoi.voronoi().extent([[bbox[0], bbox[1]], [bbox[2], bbox[3]]]);

    // convert points into simple array of coordinates, expected by D3    
    var coords = points.features.map(getCoords);

    var polygonsd3 = d3v(coords).polygons();

    return featureCollection(polygonsd3.map(coordsToPolygon));
}

export default voronoi;

@@ -137,16 +137,30 @@
 etCoords
+, collectionOf
  %7D from 
@@ -543,21 +543,19 @@
 olygons.
- 
 %0A *
- 
 %0A * The 
@@ -979,17 +979,16 @@
 bbox %7D);
- 
 %0A * var 
@@ -1248,50 +1248,85 @@
 ');%0A
-%0A
     
-var d3v = d3voronoi.voronoi().
+collectionOf(points, 'Point', 'points');%0A%0A    // Inputs%0A    var 
 extent
-(
+ = 
 %5B%5Bbb
@@ -1365,222 +1365,190 @@
 3%5D%5D%5D
-);%0A%0A    // convert points into simple array of coordinates, expected by D3    %0A    var coords = points.features.map(getCoords);%0A%0A    var polygonsd3 = d3v(coords).polygons();%0A%0A    return featureCollection(polygonsd3
+;%0A    var coords = points.features.map(getCoords);%0A%0A    return featureCollection(%0A        d3voronoi.voronoi()%0A            .extent(extent)(coords)%0A            .polygons()%0A            
 .map
@@ -1564,16 +1564,21 @@
 Polygon)
+%0A    
 );%0A%7D%0A%0Aex

Change to functional methods