You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@turf/difference

Package Overview
Dependencies
Maintainers
4
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/difference - npm Package Compare versions

Comparing version

to
5.0.0

main.js

15

index.d.ts

@@ -1,13 +0,10 @@

/// <reference types="geojson" />
import { Polygon, MultiPolygon, Feature } from '@turf/helpers'
import {Polygon, MultiPolygon, Feature} from '@turf/meta'
type Input = Feature<Polygon|MultiPolygon> | Polygon | MultiPolygon;
type Output = Feature<Polygon|MultiPolygon> | null;
/**
* http://turfjs.org/docs/#difference
*/
declare function difference(polygon1: Input, polygon2: Input): Output;
declare namespace difference { }
export = difference;
export default function difference(
polygon1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon,
polygon2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon
): Feature<Polygon | MultiPolygon> | null;

23

index.js

@@ -1,7 +0,6 @@

// depend on jsts for now https://github.com/bjornharrtell/jsts/blob/master/examples/overlay.html
var jsts = require('jsts');
var area = require('@turf/area');
var feature = require('@turf/helpers').feature;
var getGeom = require('@turf/invariant').getGeom;
var flattenEach = require('@turf/meta').flattenEach;
import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'jsts-es';
import area from '@turf/area';
import { feature } from '@turf/helpers';
import { getGeom } from '@turf/invariant';
import { flattenEach } from '@turf/meta';

@@ -42,3 +41,3 @@ /**

*/
module.exports = function (polygon1, polygon2) {
function difference(polygon1, polygon2) {
var geom1 = getGeom(polygon1);

@@ -55,12 +54,12 @@ var geom2 = getGeom(polygon2);

// JSTS difference operation
var reader = new jsts.io.GeoJSONReader();
var reader = new GeoJSONReader();
var a = reader.read(geom1);
var b = reader.read(geom2);
var differenced = a.difference(b);
var differenced = OverlayOp.difference(a, b);
if (differenced.isEmpty()) return null;
var writer = new jsts.io.GeoJSONWriter();
var writer = new GeoJSONWriter();
var geom = writer.write(differenced);
return feature(geom, properties);
};
}

@@ -87,1 +86,3 @@ /**

}
export default difference;
{
"name": "@turf/difference",
"version": "4.7.4",
"version": "5.0.0",
"description": "turf difference module",
"main": "index.js",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"main.js"
],
"scripts": {
"test": "node test.js",
"bench": "node bench.js"
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
},

@@ -30,15 +34,21 @@ "repository": {

"devDependencies": {
"benchmark": "^2.1.4",
"glob": "~5.0.5",
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.0.0"
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*",
"@std/esm": "*"
},
"dependencies": {
"@turf/area": "^4.7.3",
"@turf/helpers": "^4.7.3",
"@turf/invariant": "^4.7.3",
"@turf/meta": "^4.7.3",
"jsts": "1.3.0"
"@turf/helpers": "5.x",
"@turf/invariant": "5.x",
"@turf/meta": "5.x",
"jsts-es": "*"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}
# @turf/difference
# difference
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## difference
Finds the difference between two [polygons](http://geojson.org/geojson-spec.html#polygon) by clipping the second polygon from the first.

@@ -42,3 +44,3 @@

Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null))** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | null)** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)

@@ -45,0 +47,0 @@ <!-- This file is automatically generated. Please don't edit it directly: