Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

carp

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

carp - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

29

index.js

@@ -7,4 +7,8 @@ 'use strict';

module.exports = function(latlng, tolerance) {
var result;
if (Array.isArray(latlng)) {
return latlng.concat(latlng);
result = latlng.concat(addTolerance(latlng, tolerance));
return result;
}

@@ -18,3 +22,4 @@

var arr = toArray(latlng, latKey, lngKey);
return arr.concat(arr);
result = arr.concat(addTolerance(arr, tolerance));
return result;
}

@@ -34,1 +39,21 @@ };

}
function addTolerance(arr, tolerance) {
var result = [];
if (!isNaN(tolerance)) {
result[0] = arr[0] + tolerance;
result[1] = arr[1] + tolerance;
}
else {
result = clone(arr);
}
return result;
}
function clone(arr) {
return arr.map(function(i) {
return i;
});
}

5

package.json
{
"name": "carp",
"version": "0.0.1",
"version": "0.1.0",
"description": "lat/lng to bbox with a tolerance",
"main": "index.js",
"scripts": {
"test": "node test"
"test": "node test",
"debug": "node --debug-brk=5959 test/index.js"
},

@@ -9,0 +10,0 @@ "repository": {

@@ -17,8 +17,13 @@ carp [![Build Status: Master][travis-badge]][travis-badge-url]

carp([50.90061, 105.51079]); // [50.90061, 105.51079, 50.90061, 105.51079]
carp([50.90, 105.51]); // [50.90, 105.51, 50.90, 105.51]
carp({ lat: 50.90, lng: 105.51 }, 1); // [50.90, 105.51, 51.90, 106.51]
```
The method signature is `carp(coordinates, tolerance)`. Coordinates can be:
* Array - `[lat, lng]`
* Object - `{ lat: lat, lng: lng}`, or `{ latitude: lat, longitude: lng }`, or a mixed version..
## Roadmap
* tolerance by difference
* handle `carp(lat, lng, tol)`

@@ -25,0 +30,0 @@

@@ -5,8 +5,34 @@ 'use strict';

var carp = require('../');
var ll = [40.35, -71.20];
var bbox = ll.concat(ll);
test('array, no tolerance', function (t) {
var result = carp([40.35, -71.20]);
var result = carp(ll);
t.same(result, [40.35, -71.20, 40.35, -71.20], 'bbox is same sw/ne if no tolerance');
t.same(result, ll.concat(ll), 'bbox is same sw/ne if no tolerance');
t.end();
});
test('lat/lng, no tolerance', function (t) {
var result1 = carp({ lat: ll[0], lng: ll[1] });
var result2 = carp({ latitude: ll[0], longitude: ll[1] });
var result3 = carp({ latitude: ll[0], lng: ll[1] });
t.same(result1, bbox, 'lat/lng - bbox is same sw/ne if no tolerance');
t.same(result2, bbox, 'latitude/longitude - bbox is same sw/ne if no tolerance');
t.same(result3, bbox, 'latitude/lng - bbox is same sw/ne if no tolerance');
t.end();
});
test('tolerance, simple integer', function (t) {
var result = carp(ll, 1);
t.same(result, ll.concat(ll.map(plusTol(1))), 'ne is increase by the tolerance');
t.end();
});
function plusTol(tol) {
return function (item) {
return item + tol;
};
}
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