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

geojson

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

8

geojson.js
(function(GeoJSON) {
GeoJSON.version = '0.1.3';
GeoJSON.version = '0.1.5';

@@ -66,2 +66,8 @@ // Allow user to specify default parameters

}
if (settings.extraGlobal) {
geojson.properties = {};
for (var key in settings.extraGlobal) {
geojson.properties[key] = settings.extraGlobal[key];
}
}
}

@@ -68,0 +74,0 @@

6

geojson.min.js

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

// geojson.js - v0.1.3
// (c) 2012 Casey Thomas, MIT License
(function(e){function r(e,t){var n=e||{};for(var r in t)t.hasOwnProperty(r)&&!n[r]&&(n[r]=t[r]);return n}function i(e,t){t.crs&&(e.crs={type:"name",properties:{name:t.crs}}),t.bbox&&(e.bbox=t.bbox)}function s(e){e.geom={};for(var n in e)e.hasOwnProperty(n)&&t.indexOf(n)!==-1&&(e.geom[n]=e[n],delete e[n]);o(e.geom)}function o(e){for(var t in e)e.hasOwnProperty(t)&&(typeof e[t]=="string"?n.push(e[t]):typeof e[t]=="object"&&(n.push(e[t][0]),n.push(e[t][1])));if(n.length===0)throw new Error("No geometry attributes specified")}function u(e,t,n){var r={type:"Feature"};return r.geometry=a(e,t),r.properties=n.call(e),r}function a(e,t){var n={},r;for(var i in t.geom)r=typeof t.geom[i]=="object"?t.geom[i][0]:t.geom[i],t.geom.hasOwnProperty(i)&&e[r]&&(n.type=i,typeof t.geom[i]=="string"?n.coordinates=e[t.geom[i]]:n.coordinates=[e[t.geom[i][1]],e[t.geom[i][0]]]);return n}function f(e){var t;return!e.exclude&&!e.include?t=function(e){for(var t in this)this.hasOwnProperty(t)&&n.indexOf(t)===-1&&(e[t]=this[t])}:e.include?t=function(t){e.include.forEach(function(e){t[e]=this[e]},this)}:e.exclude&&(t=function(t){for(var r in this)this.hasOwnProperty(r)&&n.indexOf(r)===-1&&e.exclude.indexOf(r)===-1&&(t[r]=this[r])}),function(){var n={};return t.call(this,n),e.extra&&l(n,e.extra),n}}function l(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}e.version="0.1.3",e.defaults={},e.parse=function(e,t,o){if(e.length===0)throw new Error("No data found");var a={type:"FeatureCollection",features:[]},l=r(t,this.defaults),c;n.length=0,s(l),c=f(l),e.forEach(function(e){a.features.push(u(e,l,c))}),i(a,l);if(!o||typeof o!="function")return a;o(a)};var t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],n=[]})(typeof module=="object"?module.exports:window.GeoJSON={});
// geojson.js - v0.1.5
// (c) 2014 Casey Thomas, MIT License
!function(a){function b(a,b){var c=a||{};for(var d in b)b.hasOwnProperty(d)&&!c[d]&&(c[d]=b[d]);return c}function c(a,b){if(b.crs&&(a.crs={type:"name",properties:{name:b.crs}}),b.bbox&&(a.bbox=b.bbox),b.extraGlobal){a.properties={};for(var c in b.extraGlobal)a.properties[c]=b.extraGlobal[c]}}function d(a){a.geom={};for(var b in a)a.hasOwnProperty(b)&&-1!==j.indexOf(b)&&(a.geom[b]=a[b],delete a[b]);e(a.geom)}function e(a){for(var b in a)a.hasOwnProperty(b)&&("string"==typeof a[b]?k.push(a[b]):"object"==typeof a[b]&&(k.push(a[b][0]),k.push(a[b][1])));if(0===k.length)throw new Error("No geometry attributes specified")}function f(a,b,c){var d={type:"Feature"};return d.geometry=g(a,b),d.properties=c.call(a),d}function g(a,b){var c,d={};for(var e in b.geom)c="object"==typeof b.geom[e]?b.geom[e][0]:b.geom[e],b.geom.hasOwnProperty(e)&&a[c]&&(d.type=e,d.coordinates="string"==typeof b.geom[e]?a[b.geom[e]]:[a[b.geom[e][1]],a[b.geom[e][0]]]);return d}function h(a){var b;return a.exclude||a.include?a.include?b=function(b){a.include.forEach(function(a){b[a]=this[a]},this)}:a.exclude&&(b=function(b){for(var c in this)this.hasOwnProperty(c)&&-1===k.indexOf(c)&&-1===a.exclude.indexOf(c)&&(b[c]=this[c])}):b=function(a){for(var b in this)this.hasOwnProperty(b)&&-1===k.indexOf(b)&&(a[b]=this[b])},function(){var c={};return b.call(this,c),a.extra&&i(c,a.extra),c}}function i(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}a.version="0.1.5",a.defaults={},a.parse=function(a,e,g){if(0===a.length)throw new Error("No data found");var i,j={type:"FeatureCollection",features:[]},l=b(e,this.defaults);return k.length=0,d(l),i=h(l),a.forEach(function(a){j.features.push(f(a,l,i))}),c(j,l),g&&"function"==typeof g?void g(j):j};var j=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],k=[]}("object"==typeof module?module.exports:window.GeoJSON={});
module.exports = function(grunt) {
grunt.initConfig({
pkg: '<json:package.json>',
pkg: grunt.file.readJSON('package.json'),
simplemocha: {

@@ -21,6 +21,8 @@ all: {

banner: '// <%= pkg.name %>.js - v<%= pkg.version %>\n' +
'// (c) 2013 Casey Thomas, MIT License'
'// (c) 2014 Casey Thomas, MIT License \n'
},
dist: {
'geojson.min.js': ['<banner>', 'geojson.js']
files: {
'geojson.min.js': ['<banner>', 'geojson.js']
}
}

@@ -27,0 +29,0 @@ }

{
"name": "geojson",
"description": "Convert an array of geographic objects to GeoJSON",
"author": "Casey Thomas <info@caseypthomas.org>",
"version": "0.1.4",
"author": "Casey Thomas <caseypthomas@gmail.com>",
"version": "0.1.5",
"main": "./geojson",

@@ -7,0 +7,0 @@ "repository": {

@@ -32,3 +32,3 @@ # GeoJSON.js

GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -66,3 +66,3 @@

GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']}, function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -89,2 +89,30 @@

Convert the example data to GeoJSON, and include some dataset attributes.
GeoJSON.parse(data, {Point: ['lat', 'lng'], attrs: {'Creator': 'Mr. Example', 'records': data.length, 'summary': 'A few example points'}}, function(geojson){
console.log(geojson);
});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A"
}
},
...
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
"properties": {
"name": "Location C"
}
}
],
"Creator": "Mr. Example",
"records": 2,
"summary": "A few example points"
}
The `parse` method can handle data with different geometry types. Consider the following sample data:

@@ -115,3 +143,3 @@

GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}, function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -168,3 +196,3 @@

GeoJSON.parse(data1, {}, function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -211,3 +239,3 @@

GeoJSON.parse(data, {Point: ['lat', 'lng']}, function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -273,3 +301,3 @@

function(geojson){
console.log(geojson);
console.log(JSON.stringify(geojson));
});

@@ -295,2 +323,41 @@

#### extraGlobal
You can also add dataset properties using the `extraGlobal` param. The value for `extraGlobal` must be an object. For example, see below:
GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extraGlobal: {
'Creator': 'Mr. Example',
'records': data.length,
'summary': 'A few example points'
}
}, function(geojson){
console.log(geojson);
});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A"
}
},
...
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
"properties": {
"name": "Location C"
}
}
],
"properties": {
"Creator": "Mr. Example",
"records": 2,
"summary": "A few example points"
}
}
## Tests

@@ -297,0 +364,0 @@

@@ -96,3 +96,3 @@ if (typeof window === 'undefined') {

var geoOneAttr = GeoJSON.parse(oneAttr, {Point: 'coords'});
expect(geoOneAttr.features[0].geometry.coordinates[0]).to.be(-74);

@@ -121,8 +121,36 @@ expect(geoOneAttr.features[0].geometry.coordinates[1]).to.be(39.0);

prop1: {"this": "that"}
},
{
multipoint: [
[100.0, 0.0], [101.0, 1.0]
],
prop0: 'value0'
},
{
multipolygon: [
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
],
prop1: {'this': 'that'}
},
{
multilinestring: [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
],
prop0: 'value1'
}
];
var output = GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'});
var output = GeoJSON.parse(data2, {
'Point': ['x', 'y'],
'LineString': 'line',
'Polygon': 'polygon',
'MultiPoint': 'multipoint',
'MultiPolygon': 'multipolygon',
'MultiLineString': 'multilinestring'
});
expect(output.features.length).to.be(3);
expect(output.features.length).to.be(6);

@@ -177,3 +205,3 @@ output.features.forEach(function(feature){

expect(output.crs.properties.name).to.be('urn:ogc:def:crs:EPSG::4326');
output.features.forEach(function(feature){

@@ -190,3 +218,3 @@ expect(feature.properties.name).to.not.be.ok();

expect(output.crs.properties.name).to.be('urn:ogc:def:crs:EPSG::4326');
output.features.forEach(function(feature){

@@ -243,5 +271,18 @@ expect(feature.properties.name).to.be.ok();

it("adds a properties key at the top level if the extraGlobal parameter is set", function() {
var output = GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extra: { 'foo':'bar', 'bar':'foo'},
extraGlobal: { 'name': 'A bunch of points', 'source': 'Government website'}
});
expect(output.properties).to.be.ok();
expect(output.properties.name).to.be('A bunch of points');
expect(output.properties.source).to.be('Government website');
});
it("throws an error if the objects parameter is empty", function(){
var data = [];
expect(function(){ GeoJSON.parse(data); }).to.throwException(/No data found/);

@@ -248,0 +289,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