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.0.7 to 0.0.8

test/test.html

181

geojson.js

@@ -1,100 +0,102 @@

exports.version = '0.0.7';
(function(GeoJSON) {
GeoJSON.version = '0.0.8';
exports.defaults = {};
GeoJSON.defaults = {};
exports.parse = function(objects, params) {
var geojson = {"type": "FeatureCollection", "features": []},
settings = applyDefaults(params, this.defaults);
GeoJSON.parse = function(objects, params) {
var geojson = {"type": "FeatureCollection", "features": []},
settings = applyDefaults(params, this.defaults);
setGeom(settings);
setGeom(settings);
objects.forEach(function(item){
geojson.features.push(getFeature(item, settings));
});
objects.forEach(function(item){
geojson.features.push(getFeature(item, settings));
});
addOptionals(geojson, settings);
return geojson;
};
addOptionals(geojson, settings);
return geojson;
};
// Helper functions
var geoms = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'],
geomAttrs = [];
// Helper functions
var geoms = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'],
geomAttrs = [];
function applyDefaults(params, defaults) {
var settings = params || {};
function applyDefaults(params, defaults) {
var settings = params || {};
for(var setting in defaults) {
if(defaults.hasOwnProperty(setting) && !settings[setting]) {
settings[setting] = defaults[setting];
for(var setting in defaults) {
if(defaults.hasOwnProperty(setting) && !settings[setting]) {
settings[setting] = defaults[setting];
}
}
return settings;
}
return settings;
}
function addOptionals(geojson, settings){
if(settings.crs) {
geojson.crs = {
type: "name",
properties: {
name: settings.crs
}
};
function addOptionals(geojson, settings){
if(settings.crs) {
geojson.crs = {
type: "name",
properties: {
name: settings.crs
}
};
}
if (settings.bbox) {
geojson.bbox = settings.bbox;
}
}
if (settings.bbox) {
geojson.bbox = settings.bbox;
}
}
function setGeom(params) {
params.geom = {};
function setGeom(params) {
params.geom = {};
for(var param in params) {
if(params.hasOwnProperty(param) && geoms.indexOf(param) !== -1){
params.geom[param] = params[param];
delete params[param];
for(var param in params) {
if(params.hasOwnProperty(param) && geoms.indexOf(param) !== -1){
params.geom[param] = params[param];
delete params[param];
}
}
setGeomAttrList(params.geom);
}
setGeomAttrList(params.geom);
}
function setGeomAttrList(params) {
for(var param in params) {
if(params.hasOwnProperty(param)) {
if(typeof params[param] === 'string') {
geomAttrs.push(params[param]);
} else if (typeof params[param] === 'object') { // Array of coordinates for Point
geomAttrs.push(params[param][0]);
geomAttrs.push(params[param][1]);
function setGeomAttrList(params) {
for(var param in params) {
if(params.hasOwnProperty(param)) {
if(typeof params[param] === 'string') {
geomAttrs.push(params[param]);
} else if (typeof params[param] === 'object') { // Array of coordinates for Point
geomAttrs.push(params[param][0]);
geomAttrs.push(params[param][1]);
}
}
}
}
}
function getFeature(item, params) {
var feature = { "type": "Feature" };
function getFeature(item, params) {
var feature = { "type": "Feature" };
feature.geometry = buildGeom(item, params);
feature.properties = buildProps(item, params);
feature.geometry = buildGeom(item, params);
feature.properties = buildProps(item, params);
return feature;
}
return feature;
}
function buildGeom(item, params) {
var geom = {};
function buildGeom(item, params) {
var geom = {};
for(var attr in item) {
if(item.hasOwnProperty(attr) && geomAttrs.indexOf(attr) !== -1) {
for(var gtype in params.geom) {
if(params.geom.hasOwnProperty(gtype) && (attr === params.geom[gtype] || attr === params.geom[gtype][0])) {
geom.type = gtype;
for(var attr in item) {
if(item.hasOwnProperty(attr) && geomAttrs.indexOf(attr) !== -1) {
for(var gtype in params.geom) {
if(params.geom.hasOwnProperty(gtype) && (attr === params.geom[gtype] || attr === params.geom[gtype][0])) {
geom.type = gtype;
if (typeof params.geom[gtype] === 'string') {
geom.coordinates = item[params.geom[gtype]];
} else { // Point with geom stored in two attributes
geom.coordinates = [item[params.geom[gtype][1]], item[params.geom[gtype][0]]];
if (typeof params.geom[gtype] === 'string') {
geom.coordinates = item[params.geom[gtype]];
} else { // Point with geom stored in two attributes
geom.coordinates = [item[params.geom[gtype][1]], item[params.geom[gtype][0]]];
}
return geom;
}
return geom;
}

@@ -104,26 +106,27 @@ }

}
}
function buildProps(item, params) {
var properties = {};
function buildProps(item, params) {
var properties = {};
if (!params.exclude && !params.include) {
for(var attr in item) {
if(item.hasOwnProperty(attr) && (geomAttrs.indexOf(attr) === -1)) {
if (!params.exclude && !params.include) {
for(var attr in item) {
if(item.hasOwnProperty(attr) && (geomAttrs.indexOf(attr) === -1)) {
properties[attr] = item[attr];
}
}
} else if (params.include) {
params.include.forEach(function(attr){
properties[attr] = item[attr];
});
} else if (params.exclude) {
for(var attr in item) {
if(item.hasOwnProperty(attr) && (geomAttrs.indexOf(attr) === -1) && (params.exclude.indexOf(attr) === -1)) {
properties[attr] = item[attr];
}
}
} else if (params.include) {
params.include.forEach(function(attr){
properties[attr] = item[attr];
});
} else if (params.exclude) {
for(var attr in item) {
if(item.hasOwnProperty(attr) && (geomAttrs.indexOf(attr) === -1) && (params.exclude.indexOf(attr) === -1)) {
properties[attr] = item[attr];
}
}
return properties;
}
return properties;
}
}(typeof module == 'object' ? module.exports : window.GeoJSON = {}));

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

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

@@ -15,3 +15,4 @@ "repository": {

"devDependencies": {
"mocha": "*"
"mocha": "*",
"expect.js": "*"
},

@@ -18,0 +19,0 @@ "engines": {

@@ -7,12 +7,12 @@ # geojson.js

For node, use npm:
For node, use npm: `npm install geojson`
npm install geojson
In the browser, include `geojson.js`. For example: `<script type="text/javascript" src="js/geojson.js"></script>`
Client-side version is coming soon.
## Getting Started
var GeoJSON = require('geojson');
In node, `var GeoJSON = require('geojson');`
In the browser, the library is available at `GeoJSON`.
## Example Usage

@@ -241,2 +241,4 @@

or
data = [{

@@ -261,2 +263,8 @@ name: 'location',

- `crs` - A string identifying a coordinate reference system. Only named CRSs are supported at the moment. [More information](http://geojson.org/geojson-spec.html#named-crs)
- `bbox` - A bounding box for the feature collection. An array with the following format: `[y1, x1, y2, x2]`. [More information](http://geojson.org/geojson-spec.html#bounding-boxes)
- `bbox` - A bounding box for the feature collection. An array with the following format: `[y1, x1, y2, x2]`. [More information](http://geojson.org/geojson-spec.html#bounding-boxes)
## Tests
For node, `npm test`.
For the browser, visit `test/test.html`.
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