Socket
Socket
Sign inDemoInstall

geojson-equality

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-equality - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

20

dist/geojson-equality.js

@@ -133,10 +133,22 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.GeojsonEquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

g1.id !== g2.id ||
!this.objectComparator(g1.properties, g2.properties)
!this.objectComparator(g1.properties, g2.properties) ||
!this.compareBBox(g1,g2)
) {
return false;
}
return this.compare(g1.geometry, g2.geometry);
};
Equality.prototype.compareBBox = function(g1,g2) {
if (
(!g1.bbox && !g2.bbox) ||
(
g1.bbox && g2.bbox &&
this.compareCoord(g1.bbox, g2.bbox)
)
) {
return true;
}
return false;
};
Equality.prototype.removePseudo = function(path) {

@@ -284,4 +296,2 @@ //TODO to be implement

});
//# sourceMappingURL=geojson-equality.js.map
//# sourceMappingURL=geojson-equality.js.map

@@ -1,1 +0,1 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.GeojsonEquality=e()}}(function(){return function e(t,r,o){function n(c,u){if(!r[c]){if(!t[c]){var p="function"==typeof require&&require;if(!u&&p)return p(c,!0);if(i)return i(c,!0);var s=new Error("Cannot find module '"+c+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[c]={exports:{}};t[c][0].call(a.exports,function(e){var r=t[c][1][e];return n(r?r:e)},a,a.exports,e,t,r,o)}return r[c].exports}for(var i="function"==typeof require&&require,c=0;c<o.length;c++)n(o[c]);return n}({1:[function(e,t){function r(e){return e.coordinates.map(function(t){return{type:e.type.replace("Multi",""),coordinates:t}})}function o(e,t){return e.hasOwnProperty("coordinates")?e.coordinates.length===t.coordinates.length:e.length===t.length}function n(e,t){return i(e,t,{strict:!0})}var i=e("deep-equal"),c=function(e){this.precision=e&&e.precision?e.precision:17,this.direction=e&&e.direction?e.direction:!1,this.pseudoNode=e&&e.pseudoNode?e.pseudoNode:!1,this.objectComparator=e&&e.objectComparator?e.objectComparator:n};c.prototype.compare=function(e,t){if(e.type!==t.type||!o(e,t))return!1;switch(e.type){case"Point":return this.compareCoord(e.coordinates,t.coordinates);case"LineString":return this.compareLine(e.coordinates,t.coordinates,0,!1);case"Polygon":return this.comparePolygon(e,t);case"Feature":return this.compareFeature(e,t);default:if(0===e.type.indexOf("Multi")){var n=this,i=r(e),c=r(t);return i.every(function(e){return this.some(function(t){return n.compare(e,t)})},c)}}return!1},c.prototype.compareCoord=function(e,t){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(e[r].toFixed(this.precision)!==t[r].toFixed(this.precision))return!1;return!0},c.prototype.compareLine=function(e,t,r,n){if(!o(e,t))return!1;var i=this.pseudoNode?e:this.removePseudo(e),c=this.pseudoNode?t:this.removePseudo(t);if(!n||this.compareCoord(i[0],c[0])||(c=this.fixStartIndex(c,i))){var u=this.compareCoord(i[r],c[r]);return this.direction||u?this.comparePath(i,c):this.compareCoord(i[r],c[c.length-(1+r)])?this.comparePath(i.slice().reverse(),c):!1}},c.prototype.fixStartIndex=function(e,t){for(var r,o=-1,n=0;n<e.length;n++)if(this.compareCoord(e[n],t[0])){o=n;break}return o>=0&&(r=[].concat(e.slice(o,e.length),e.slice(1,o+1))),r},c.prototype.comparePath=function(e,t){var r=this;return e.every(function(e,t){return r.compareCoord(e,this[t])},t)},c.prototype.comparePolygon=function(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){var r=e.coordinates.slice(1,e.coordinates.length),o=t.coordinates.slice(1,t.coordinates.length),n=this;return r.every(function(e){return this.some(function(t){return n.compareLine(e,t,1,!0)})},o)}return!1},c.prototype.compareFeature=function(e,t){return e.id===t.id&&this.objectComparator(e.properties,t.properties)?this.compare(e.geometry,t.geometry):!1},c.prototype.removePseudo=function(e){return e},t.exports=c},{"deep-equal":2}],2:[function(e,t){function r(e){return null===e||void 0===e}function o(e){return e&&"object"==typeof e&&"number"==typeof e.length?"function"!=typeof e.copy||"function"!=typeof e.slice?!1:e.length>0&&"number"!=typeof e[0]?!1:!0:!1}function n(e,t,n){var s,a;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(u(e))return u(t)?(e=i.call(e),t=i.call(t),p(e,t,n)):!1;if(o(e)){if(!o(t))return!1;if(e.length!==t.length)return!1;for(s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}try{var f=c(e),l=c(t)}catch(d){return!1}if(f.length!=l.length)return!1;for(f.sort(),l.sort(),s=f.length-1;s>=0;s--)if(f[s]!=l[s])return!1;for(s=f.length-1;s>=0;s--)if(a=f[s],!p(e[a],t[a],n))return!1;return typeof e==typeof t}var i=Array.prototype.slice,c=e("./lib/keys.js"),u=e("./lib/is_arguments.js"),p=t.exports=function(e,t,r){return r||(r={}),e===t?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():"object"!=typeof e&&"object"!=typeof t?r.strict?e===t:e==t:n(e,t,r)}},{"./lib/is_arguments.js":3,"./lib/keys.js":4}],3:[function(e,t,r){function o(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function n(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var i="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();r=t.exports=i?o:n,r.supported=o,r.unsupported=n},{}],4:[function(e,t,r){function o(e){var t=[];for(var r in e)t.push(r);return t}r=t.exports="function"==typeof Object.keys?Object.keys:o,r.shim=o},{}]},{},[1])(1)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.GeojsonEquality=e()}}(function(){return function e(t,r,o){function n(c,u){if(!r[c]){if(!t[c]){var p="function"==typeof require&&require;if(!u&&p)return p(c,!0);if(i)return i(c,!0);var s=new Error("Cannot find module '"+c+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[c]={exports:{}};t[c][0].call(a.exports,function(e){var r=t[c][1][e];return n(r?r:e)},a,a.exports,e,t,r,o)}return r[c].exports}for(var i="function"==typeof require&&require,c=0;c<o.length;c++)n(o[c]);return n}({1:[function(e,t){function r(e){return e.coordinates.map(function(t){return{type:e.type.replace("Multi",""),coordinates:t}})}function o(e,t){return e.hasOwnProperty("coordinates")?e.coordinates.length===t.coordinates.length:e.length===t.length}function n(e,t){return i(e,t,{strict:!0})}var i=e("deep-equal"),c=function(e){this.precision=e&&e.precision?e.precision:17,this.direction=e&&e.direction?e.direction:!1,this.pseudoNode=e&&e.pseudoNode?e.pseudoNode:!1,this.objectComparator=e&&e.objectComparator?e.objectComparator:n};c.prototype.compare=function(e,t){if(e.type!==t.type||!o(e,t))return!1;switch(e.type){case"Point":return this.compareCoord(e.coordinates,t.coordinates);case"LineString":return this.compareLine(e.coordinates,t.coordinates,0,!1);case"Polygon":return this.comparePolygon(e,t);case"Feature":return this.compareFeature(e,t);default:if(0===e.type.indexOf("Multi")){var n=this,i=r(e),c=r(t);return i.every(function(e){return this.some(function(t){return n.compare(e,t)})},c)}}return!1},c.prototype.compareCoord=function(e,t){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(e[r].toFixed(this.precision)!==t[r].toFixed(this.precision))return!1;return!0},c.prototype.compareLine=function(e,t,r,n){if(!o(e,t))return!1;var i=this.pseudoNode?e:this.removePseudo(e),c=this.pseudoNode?t:this.removePseudo(t);if(!n||this.compareCoord(i[0],c[0])||(c=this.fixStartIndex(c,i))){var u=this.compareCoord(i[r],c[r]);return this.direction||u?this.comparePath(i,c):this.compareCoord(i[r],c[c.length-(1+r)])?this.comparePath(i.slice().reverse(),c):!1}},c.prototype.fixStartIndex=function(e,t){for(var r,o=-1,n=0;n<e.length;n++)if(this.compareCoord(e[n],t[0])){o=n;break}return o>=0&&(r=[].concat(e.slice(o,e.length),e.slice(1,o+1))),r},c.prototype.comparePath=function(e,t){var r=this;return e.every(function(e,t){return r.compareCoord(e,this[t])},t)},c.prototype.comparePolygon=function(e,t){if(this.compareLine(e.coordinates[0],t.coordinates[0],1,!0)){var r=e.coordinates.slice(1,e.coordinates.length),o=t.coordinates.slice(1,t.coordinates.length),n=this;return r.every(function(e){return this.some(function(t){return n.compareLine(e,t,1,!0)})},o)}return!1},c.prototype.compareFeature=function(e,t){return e.id===t.id&&this.objectComparator(e.properties,t.properties)&&this.compareBBox(e,t)?this.compare(e.geometry,t.geometry):!1},c.prototype.compareBBox=function(e,t){return!e.bbox&&!t.bbox||e.bbox&&t.bbox&&this.compareCoord(e.bbox,t.bbox)?!0:!1},c.prototype.removePseudo=function(e){return e},t.exports=c},{"deep-equal":2}],2:[function(e,t){function r(e){return null===e||void 0===e}function o(e){return e&&"object"==typeof e&&"number"==typeof e.length?"function"!=typeof e.copy||"function"!=typeof e.slice?!1:e.length>0&&"number"!=typeof e[0]?!1:!0:!1}function n(e,t,n){var s,a;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(u(e))return u(t)?(e=i.call(e),t=i.call(t),p(e,t,n)):!1;if(o(e)){if(!o(t))return!1;if(e.length!==t.length)return!1;for(s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}try{var f=c(e),l=c(t)}catch(d){return!1}if(f.length!=l.length)return!1;for(f.sort(),l.sort(),s=f.length-1;s>=0;s--)if(f[s]!=l[s])return!1;for(s=f.length-1;s>=0;s--)if(a=f[s],!p(e[a],t[a],n))return!1;return typeof e==typeof t}var i=Array.prototype.slice,c=e("./lib/keys.js"),u=e("./lib/is_arguments.js"),p=t.exports=function(e,t,r){return r||(r={}),e===t?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():"object"!=typeof e&&"object"!=typeof t?r.strict?e===t:e==t:n(e,t,r)}},{"./lib/is_arguments.js":3,"./lib/keys.js":4}],3:[function(e,t,r){function o(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function n(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var i="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();r=t.exports=i?o:n,r.supported=o,r.unsupported=n},{}],4:[function(e,t,r){function o(e){var t=[];for(var r in e)t.push(r);return t}r=t.exports="function"==typeof Object.keys?Object.keys:o,r.shim=o},{}]},{},[1])(1)});

@@ -132,10 +132,22 @@ //index.js

g1.id !== g2.id ||
!this.objectComparator(g1.properties, g2.properties)
!this.objectComparator(g1.properties, g2.properties) ||
!this.compareBBox(g1,g2)
) {
return false;
}
return this.compare(g1.geometry, g2.geometry);
};
Equality.prototype.compareBBox = function(g1,g2) {
if (
(!g1.bbox && !g2.bbox) ||
(
g1.bbox && g2.bbox &&
this.compareCoord(g1.bbox, g2.bbox)
)
) {
return true;
}
return false;
};
Equality.prototype.removePseudo = function(path) {

@@ -142,0 +154,0 @@ //TODO to be implement

{
"name": "geojson-equality",
"version": "0.1.5",
"version": "0.1.6",
"description": "Check two valid geojson geometries for equality.",

@@ -37,2 +37,3 @@ "main": "index.js",

"chai": "~1.9.1",
"exorcist": "^0.4.0",
"mocha": "~1.21.4",

@@ -39,0 +40,0 @@ "uglify-js": "~2.4.15",

@@ -116,3 +116,2 @@ var expect = require('chai').expect,

it('after limiting precision, are equal', function() {
debugger;
var eq = new Equality({precision: 3});

@@ -129,28 +128,28 @@ expect(eq.compare(gprecision1,gprecision2)).to.be.true;

describe ('geojson-equality for Feature', function() {
it ('will be not be equal with changed id', function() {
var gprecision1 = {"type": "Feature", "id": "id1"};
var gprecision2 = {"type": "Feature", "id": "id2"};
it ('will not be equal with changed id', function() {
var f1 = {"type": "Feature", "id": "id1"};
var f2 = {"type": "Feature", "id": "id2"};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will be not be equal with different count of properties', function() {
var gprecision1 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar"}};
var gprecision2 = {"type": "Feature", "id": "id1", "properties": {"foo1": "bar", "foo2": "bar"}};
it ('will not be equal with different count of properties', function() {
var f1 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar"}};
var f2 = {"type": "Feature", "id": "id1", "properties": {"foo1": "bar", "foo2": "bar"}};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will be not be equal with different keys in properties', function() {
var gprecision1 = {"type": "Feature", "id": "id1", "properties": {"foo1": "bar"}};
var gprecision2 = {"type": "Feature", "id": "id1", "properties": {"foo2": "bar"}};
it ('will not be equal with different keys in properties', function() {
var f1 = {"type": "Feature", "id": "id1", "properties": {"foo1": "bar"}};
var f2 = {"type": "Feature", "id": "id1", "properties": {"foo2": "bar"}};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will be not be equal with different properties', function() {
var gprecision1 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar1"}};
var gprecision2 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar2"}};
it ('will not be equal with different properties', function() {
var f1 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar1"}};
var f2 = {"type": "Feature", "id": "id1", "properties": {"foo": "bar2"}};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will be not be equal with different geometry', function() {
var gprecision1 = {
it ('will not be equal with different geometry', function() {
var f1 = {
"type": "Feature",

@@ -163,3 +162,3 @@ "id": "id1",

};
var gprecision2 = {
var f2 = {
"type": "Feature",

@@ -173,26 +172,26 @@ "id": "id1",

var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will be equal with nested properties', function() {
var gprecision1 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
var f1 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
"geometry": {"type": "Point", "coordinates": [0, 1]}
};
var gprecision2 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
var f2 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
"geometry": {"type": "Point", "coordinates": [0, 1]}
};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.true;
expect(eq.compare(f1, f2)).to.be.true;
});
it ('will be not equal with different nested properties', function() {
var gprecision1 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
it ('will not be equal with different nested properties', function() {
var f1 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz"}},
"geometry": {"type": "Point", "coordinates": [0, 1]}
};
var gprecision2 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz2"}},
var f2 = {"type": "Feature", "id": "id1", "properties": {"foo": {"bar": "baz2"}},
"geometry": {"type": "Point", "coordinates": [0, 1]}
};
var eq = new Equality();
expect(eq.compare(gprecision1, gprecision2)).to.be.false;
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will use a custom comparator if provided', function() {
var gprecision1 = {
var f1 = {
"type": "Feature",

@@ -205,3 +204,3 @@ "id": "id1",

};
var gprecision2 = {
var f2 = {
"type": "Feature",

@@ -217,4 +216,60 @@ "id": "id1",

}});
expect(eq.compare(gprecision1, gprecision2)).to.be.true;
expect(eq.compare(f1, f2)).to.be.true;
});
it ('will not be equal if one has bbox and other not', function() {
var f1 = {"type": "Feature", "id": "id1", "bbox": [1, 2, 3, 4]},
f2 = {"type": "Feature", "id": "id1"},
eq = new Equality();
expect(eq.compare(f1, f2)).to.be.false;
});
it ('will not be equal if bboxes are not equal', function() {
var f1 = {"type": "Feature", "id": "id1", "bbox": [1, 2, 3, 4]},
f2 = {"type": "Feature", "id": "id1", "bbox": [1, 2, 3, 5]},
eq = new Equality();
expect(eq.compare(f1, f2)).to.be.false;
});
it ('equal features with bboxes', function() {
var f1 = {
"type": "Feature",
"id": "id1",
"properties": {"foo": "bar1"},
"geometry": { "type": "Polygon", "coordinates": [
[[30, 10], [41, 40], [20, 40], [10, 20], [30, 10]]
]},
"bbox": [10, 10, 41, 40]
};
var f2 = {
"type": "Feature",
"id": "id1",
"properties": {"foo": "bar1"},
"geometry": { "type": "Polygon", "coordinates": [
[[30, 10], [41, 40], [20, 40], [10, 20], [30, 10]]
]},
"bbox": [10, 10, 41, 40]
};
var eq = new Equality();
expect(eq.compare(f1, f2)).to.be.true;
});
it ('not equal features with equal bboxes', function() {
var f1 = {
"type": "Feature",
"id": "id1",
"properties": {"foo": "bar1"},
"geometry": { "type": "Polygon", "coordinates": [
[[30, 10], [41, 40], [20, 40], [10, 20], [30, 10]]
]},
"bbox": [10, 10, 41, 40]
};
var f2 = {
"type": "Feature",
"id": "id1",
"properties": {"foo": "bar1"},
"geometry": { "type": "Polygon", "coordinates": [
[[30, 10], [41, 40], [20, 40], [10, 20], [30, 1]]
]},
"bbox": [10, 10, 41, 40]
};
var eq = new Equality();
expect(eq.compare(f1, f2)).to.be.false;
});
});

@@ -292,3 +347,2 @@

var eq = new Equality();
debugger;
expect(eq.compare(g1,g3)).to.be.false;

@@ -295,0 +349,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc