Socket
Socket
Sign inDemoInstall

geojson-stream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-stream - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

CHANGELOG.md

10

index.js

@@ -6,4 +6,10 @@ var JSONStream = require('JSONStream');

module.exports.parse = function() {
var jsonstream = JSONStream.parse('features.*');
module.exports.parse = function(mapFunc) {
var indexFunc;
if (mapFunc) {
indexFunc = function(feature, context) {
return mapFunc(feature, context[1]);
}
}
var jsonstream = JSONStream.parse('features.*', indexFunc);
return jsonstream;

@@ -10,0 +16,0 @@ };

{
"name": "geojson-stream",
"version": "0.0.1",
"version": "0.1.0",
"description": "stream features into and out of geojson",
"main": "index.js",
"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js",
"release": "standard-version"
},

@@ -30,5 +31,6 @@ "repository": {

"devDependencies": {
"concat-stream": "~1.0.1",
"tap": "~0.4.9"
"concat-stream": "~1.6.0",
"standard-version": "^4.4.0",
"tap": "~10.3.2"
}
}

31

README.md
# geojson-stream
[![build status](https://secure.travis-ci.org/mapbox/geojson-stream.png)](http://travis-ci.org/mapbox/geojson-stream)
[![Greenkeeper badge](https://badges.greenkeeper.io/tmcw/geojson-stream.svg)](https://greenkeeper.io/)
[![build status](https://secure.travis-ci.org/tmcw/geojson-stream.svg)](http://travis-ci.org/tmcw/geojson-stream)

@@ -18,7 +19,29 @@ Stream features into and out of [GeoJSON](http://geojson.org/) objects

Returns a transform stream that accepts GeoJSON Feature objects and emits
a stringified FeatureCollection
a stringified FeatureCollection.
### `geojsonStream.parse()`
### `geojsonStream.parse(mapFunc)`
Returns a transform stream that accepts a GeoJSON FeatureCollection as a stream
and emits Feature objects
and emits Feature objects.
`mapFunc(feature, index)` is an optional function which takes a `Feature`, and its zero-based index in the `FeatureCollection` and returns either a `Feature`, or null/undefined
if the feature should be omitted from output.
## example
```
const geojsonStream = require('geojson-stream');
const fs = require('fs');
const out = fs.createWriteStream('buildings-with-id.geojson');
fs
.createReadStream(`buildings.geojson`)
.pipe(geojsonStream.parse((building, index) => {
if (building.geometry.coordinates === null) {
return null;
}
building.id = index;
return building;
}))
.pipe(geojsonStream.stringify())
.pipe(out);
```

@@ -15,2 +15,17 @@ var test = require('tap').test,

test('geojson-stream: read with map', function(t) {
function addExtraProp(feature, index) {
feature.properties.extraProp = true;
feature.id = index;
return feature;
}
var s = geojsonStream.parse(addExtraProp);
fs.createReadStream(__dirname + '/data/featurecollection.geojson')
.pipe(s).pipe(concat(function(d) {
t.deepEqual(d, JSON.parse(fs.readFileSync(__dirname + '/data/extraprop.result')));
t.end();
}));
});
test('geojson-stream: write', function(t) {

@@ -17,0 +32,0 @@ var pt = {

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