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.0 to 0.1.1

2

geojson.js
(function(GeoJSON) {
GeoJSON.version = '0.1.0';
GeoJSON.version = '0.1.1';

@@ -4,0 +4,0 @@ // Allow user to specify default parameters

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

// geojson.js - v0.1.0
// geojson.js - v0.1.1
// (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){var n={type:"Feature"};return n.geometry=a(e,t),n.properties=f(e,t),n}function a(e,t){var r={};for(var i in e)if(e.hasOwnProperty(i)&&n.indexOf(i)!==-1)for(var s in t.geom)if(t.geom.hasOwnProperty(s)&&(i===t.geom[s]||i===t.geom[s][0]))return r.type=s,typeof t.geom[s]=="string"?r.coordinates=e[t.geom[s]]:r.coordinates=[e[t.geom[s][1]],e[t.geom[s][0]]],r}function f(e,t){var r={},i;if(!t.exclude&&!t.include)for(i in e)e.hasOwnProperty(i)&&n.indexOf(i)===-1&&(r[i]=e[i]);else if(t.include)t.include.forEach(function(t){r[t]=e[t]});else if(t.exclude)for(i in e)e.hasOwnProperty(i)&&n.indexOf(i)===-1&&t.exclude.indexOf(i)===-1&&(r[i]=e[i]);return t.extra&&l(r,t.extra),r}function l(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}e.version="0.1.0",e.defaults={},e.parse=function(e,t){if(e.length===0)throw new Error("No data found");var o={type:"FeatureCollection",features:[]},a=r(t,this.defaults);return n.length=0,s(a),e.forEach(function(e){o.features.push(u(e,a))}),i(o,a),o};var t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],n=[]})(typeof module=="object"?module.exports:window.GeoJSON={});
(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){var n={type:"Feature"};return n.geometry=a(e,t),n.properties=f(e,t),n}function a(e,t){var r={};for(var i in e)if(e.hasOwnProperty(i)&&n.indexOf(i)!==-1)for(var s in t.geom)if(t.geom.hasOwnProperty(s)&&(i===t.geom[s]||i===t.geom[s][0]))return r.type=s,typeof t.geom[s]=="string"?r.coordinates=e[t.geom[s]]:r.coordinates=[e[t.geom[s][1]],e[t.geom[s][0]]],r}function f(e,t){var r={},i;if(!t.exclude&&!t.include)for(i in e)e.hasOwnProperty(i)&&n.indexOf(i)===-1&&(r[i]=e[i]);else if(t.include)t.include.forEach(function(t){r[t]=e[t]});else if(t.exclude)for(i in e)e.hasOwnProperty(i)&&n.indexOf(i)===-1&&t.exclude.indexOf(i)===-1&&(r[i]=e[i]);return t.extra&&l(r,t.extra),r}function l(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}e.version="0.1.1",e.defaults={},e.parse=function(e,t){if(e.length===0)throw new Error("No data found");var o={type:"FeatureCollection",features:[]},a=r(t,this.defaults);return n.length=0,s(a),e.forEach(function(e){o.features.push(u(e,a))}),i(o,a),o};var t=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],n=[]})(typeof module=="object"?module.exports:window.GeoJSON={});

@@ -8,2 +8,11 @@ module.exports = function(grunt) {

},
simplemocha: {
src: 'test/*.js'
},
mocha: {
test: {
src: ['test/test.html'],
run: true
}
},
lint: {

@@ -20,3 +29,7 @@ files: ['geojson.js', 'test/test.js']

grunt.registerTask('default', 'lint min');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-mocha');
grunt.registerTask('all', 'simplemocha mocha lint min');
grunt.registerTask('default', 'simplemocha lint min');
};

@@ -5,3 +5,3 @@ {

"author": "Casey Thomas <c@cpt.ph>",
"version": "0.1.0",
"version": "0.1.1",
"main": "./geojson",

@@ -17,3 +17,5 @@ "repository": {

"expect.js": "*",
"grunt": ">=0.3.16"
"grunt": ">=0.3.16",
"grunt-simple-mocha": ">=0.2.0",
"grunt-mocha": "0.1.7"
},

@@ -20,0 +22,0 @@ "engines": {

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

# geojson.js
# GeoJSON.js

@@ -7,3 +7,3 @@ Convert an array of objects with geometry to a [GeoJSON](http://geojson.org/) feature collection.

For node, use npm: `npm install geojson`
For node, use npm: `$ npm install geojson`

@@ -25,23 +25,5 @@ In the browser, include `geojson.min.js`. For example: `<script type="text/javascript" src="js/geojson.min.js"></script>`

var data = [
{
name: 'Location A',
category: 'Store',
street: 'Market',
lat: 39.984,
lng: -75.343
},
{
name: 'Location B',
category: 'House',
street: 'Broad',
lat: 39.284,
lng: -75.833
},
{
name: 'Location C',
category: 'Office',
street: 'South',
lat: 39.123,
lng: -74.534
}
{ name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
{ name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 },
{ name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 }
];

@@ -171,15 +153,5 @@

var data1 = [{
name: 'Location A',
street: 'Market',
x: 34,
y: -75
}];
var data1 = [{ name: 'Location A', street: 'Market', x: 34, y: -75 }];
var data2 = [{
name: 'Location B',
date: '11/23/2012',
x: 54,
y: -98
}];
var data2 = [{ name: 'Location B', date: '11/23/2012', x: 54, y: -98 }];

@@ -226,2 +198,4 @@ GeoJSON.defaults = {Point: ['x', 'y'], include: ['name']};

#### include/exclude
Depending on which makes more sense for the data that is being parsed, either specify an array of attributes to include or exclude in `properties` for each feature. If neither `include` nor `exclude` is set, all the attributes (besides the attributes containing the geometry data) will be added to feature `properties`.

@@ -232,2 +206,4 @@

#### Geometry
The geometry parameters specify which attribute(s) contain(s) the geographic/geometric data. A geometry parameter must be specified for each type of geometry object that is present in the data that is being parsed. For example, if the data contains both points and polygons, specify both the `Point` and `Polygon` parameters. **Note that geometry parameters must be in proper case.** See the [GeoJSON spec](http://geojson.org/geojson-spec.html) for details on each geometry type. The structure of the geometry parameter is:

@@ -239,7 +215,3 @@

data = [{
name: 'location',
x: 34,
y: 85
}];
data = [{ name: 'location', x: 34, y: 85 }];

@@ -250,6 +222,3 @@ GeoJSON.parse(data, {Point: ['lat', 'lng']});

data = [{
name: 'location',
coords: [85, 34]
}];
data = [{ name: 'location', coords: [85, 34] }];

@@ -267,2 +236,4 @@ GeoJSON.parse(data, {Point: 'coords'});

#### bbox, crs
geojson.js also supports the optional GeoJSON properties `bbox` and `crs`.

@@ -273,37 +244,45 @@

#### extra
You can add arbitrary properties to features using the `extra` param. The value for `extra` must be an object.For example, using the original sample data:
GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extra: {
style: {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
GeoJSON.parse(data, {
Point: ['lat', 'lng'],
extra: {
style: {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
}
}
}
});
});
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A",
"category": "Store",
"style": {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A",
"category": "Store",
"style": {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
}
}
}
},
...
}
},
...
}
## Tests
For node, `npm test`.
For node, `$ npm test`.
For the browser, visit `test/test.html`.
For the browser, visit `test/test.html`.
## Building
`$ grunt ` will run test.js, and lint and minify `geojson.js`.
`$ grunt all` will do all the above, plus run the browser tests, `test.html`. Note that this requires [PhantomJS](http://phantomjs.org/).

@@ -1,39 +0,46 @@

var GeoJSON = require('../geojson');
var expect = require('expect.js');
if (typeof window === 'undefined') {
var expect = require('expect.js');
var GeoJSON = require('../geojson');
}
describe('GeoJSON', function() {
describe('#parse()', function(){
// Sample Data
var data = [
{
name: 'Location A',
category: 'Store',
lat: 39.984,
lng: -75.343,
street: 'Market'
},
{
name: 'Location B',
category: 'House',
lat: 39.284,
lng: -75.833,
street: 'Broad'
},
{
name: 'Location C',
category: 'Office',
lat: 39.123,
lng: -74.534,
street: 'South'
describe('#defaults', function(){
it('exists as a public object of GeoJSON', function(){
expect(typeof GeoJSON.defaults).to.eql('object');
});
it('is initially empty', function() {
var count = 0;
for(var key in GeoJSON.defaults) {
if(GeoJSON.defaults.hasOwnProperty(key)) {
count++;
}
}
];
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']});
expect(count).to.be(0);
});
});
it('should return output with the same number of features as the input', function(){
describe('#parse', function(){
var data;
before(function() {
// Sample Data
data = [
{ name: 'Location A', category: 'Store', lat: 39.984, lng: -75.343, street: 'Market' },
{ name: 'Location B', category: 'House', lat: 39.284, lng: -75.833, street: 'Broad' },
{ name: 'Location C', category: 'Office', lat: 39.123, lng: -74.534, street: 'South' }
];
});
it('returns output with the same number of features as the input', function(){
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']});
expect(output.features.length).to.be(3);
});
it('should not include geometry fields in feature properties', function(){
it('doesn\'t include geometry fields in feature properties', function(){
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']});
output.features.forEach(function(feature){

@@ -45,3 +52,5 @@ expect(feature.properties.lat).to.not.be.ok();

it('should include all properties besides geometry attributes when include or exclude isn\'t set', function() {
it('includes all properties besides geometry attributes when include or exclude isn\'t set', function() {
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']});
output.features.forEach(function(feature){

@@ -54,3 +63,3 @@ expect(feature.properties.name).to.be.ok();

it('should only include attributes that are listed in the include parameter', function(){
it('only includes attributes that are listed in the include parameter', function(){
var output = GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']});

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

it('should only include attributes that not are listed in the exclude parameter', function(){
it('does not include attributes listed in the exclude parameter', function(){
var output = GeoJSON.parse(data, {Point: ['lat', 'lng'], exclude: ['name']});

@@ -77,9 +86,4 @@

it('should be able to handle Point geom with x,y stored in one or two attributes', function(){
var twoAttrs = [{
name: 'test location',
y: -74,
x: 39.0,
foo: 'bar'
}];
it('handles Point geom with x,y stored in one or two attributes', function(){
var twoAttrs = [{ name: 'test location', y: -74, x: 39.0, foo: 'bar' }];

@@ -91,7 +95,3 @@ var geoTwoAttrs = GeoJSON.parse(twoAttrs, {Point: ['x', 'y']});

var oneAttr = [{
name: 'test location',
coords: [-74, 39],
foo: 'bar'
}];
var oneAttr = [{ name: 'test location', coords: [-74, 39], foo: 'bar'}];

@@ -104,24 +104,24 @@ var geoOneAttr = GeoJSON.parse(oneAttr, {Point: 'coords'});

// Based off example spec at http://geojson.org/geojson-spec.html
var data2 = [
{
x: 0.5,
y: 102.0,
prop0: 'value0'
},
{
line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]],
prop0: 'value0',
prop1: 0.0
},
{
polygon: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
],
prop0: 'value0',
prop1: {"this": "that"}
}
];
it('parses data with different geometry types', function(){
// Based off example spec at http://geojson.org/geojson-spec.html
var data2 = [
{
x: 0.5,
y: 102.0,
prop0: 'value0'
},
{
line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]],
prop0: 'value0',
prop1: 0.0
},
{
polygon: [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
],
prop0: 'value0',
prop1: {"this": "that"}
}
];
it('should be able to handle data with different geometry types', function(){
var output = GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'});

@@ -156,3 +156,3 @@

it('should use the default settings when they have been specified', function(){
it('uses the default settings when they have been specified', function(){
GeoJSON.defaults = {

@@ -176,3 +176,3 @@ Point: ['lat', 'lng'],

it('should only apply default settings that haven\'t been set in params', function(){
it('only applies default settings that haven\'t been set in params', function(){
var output = GeoJSON.parse(data, {include: ['category', 'street']});

@@ -189,3 +189,3 @@

it('shouldn\'t be affected from prior calls to parse that set params', function(){
it('keeps the default settings until they have been explicity reset', function(){
var output = GeoJSON.parse(data);

@@ -207,3 +207,3 @@

it("it should add 'bbox' and/or 'crs' to the output if either is specified in the parameters", function(){
it("adds 'bbox' and/or 'crs' to the output if either is specified in the parameters", function(){
var output = GeoJSON.parse(data, {

@@ -221,3 +221,3 @@ Point: ['lat', 'lng'],

it("should add extra attributes if extra param is set", function() {
it("adds extra attributes if extra param is set", function() {
var output = GeoJSON.parse(data, {Point: ['lat', 'lng'], extra: { 'foo':'bar', 'bar':'foo'}});

@@ -248,3 +248,3 @@

it("should throw an error if the objects parameter is empty", function(){
it("throws an error if the objects parameter is empty", function(){
var data = [];

@@ -255,4 +255,4 @@

it("should throw an error if no geometry attributes have been specified", function() {
expect(function(){ GeoJSON.parse(data); }).to.throwException(/No geometry attributes specified/);
it("throws an error if no geometry attributes have been specified", function() {
expect(function(){ GeoJSON.parse(data); }).to.throwException(/No geometry attributes specified/);
});

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