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

osm2json

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osm2json - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

10

CHANGELOG.md

@@ -5,8 +5,13 @@ # Change Log

## [1.2.0] - 2016-08-22
### Added
- Support [`<diffResult>`](http://wiki.openstreetmap.org/wiki/API_v0.6#Diff_upload:_POST_.2Fapi.2F0.6.2Fchangeset.2F.23id.2Fupload)
- Add non-streaming `parse(str)` method.
## [1.1.0] - 2016-08-21
## Added
### Added
- Options `bounds`, `strict`, `types`
## [1.0.0] - 2016-08-19
## Changed
### Changed
- Output Overpass [OSM JSON format](http://overpass-api.de/output_formats.html#json) fixes [#1](https://github.com/digidem/osm2json/issues/1)

@@ -20,3 +25,4 @@ - Parse [OsmChange XML](http://wiki.openstreetmap.org/wiki/OsmChange)

[1.2.0]: https://github.com/digidem/osm2json/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/digidem/osm2json/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/digidem/osm2json/compare/v0.0.1...v1.0.0

23

lib/osm2json.js

@@ -12,3 +12,3 @@ /**

// These attributes are "id-like" and will be coerced to Number if opts.coerceIds === true
var ID_ATTRIBUTES = ['id', 'uid', 'version', 'changeset', 'ref']
var ID_ATTRIBUTES = ['id', 'uid', 'version', 'changeset', 'ref', 'old_id', 'new_id', 'new_version']
// These attributes are always coerced to Number

@@ -19,3 +19,3 @@ var NUMBER_ATTRIBUTES = ['lat', 'lon', 'comments_count', 'min_lat', 'min_lon', 'max_lat', 'max_lon',

// Any nodes in the XML that are not listed below will throw an error
var VALID_ROOTS = ['osm', 'osmChange']
var VALID_ROOTS = ['osm', 'osmChange', 'diffResult']
var VALID_ACTIONS = ['create', 'modify', 'delete']

@@ -26,3 +26,3 @@ var VALID_NODES = ['node', 'way', 'relation', 'changeset', 'bounds']

// Any node that is a child of a VALID_NODE that is not in `children` will throw an error
var ELEMENT_ATTRIBUTES = ['id', 'user', 'uid', 'visible', 'version', 'changeset', 'timestamp']
var ELEMENT_ATTRIBUTES = ['id', 'user', 'uid', 'visible', 'version', 'changeset', 'timestamp', 'old_id', 'new_id', 'new_version']
var WHITELISTS = {

@@ -95,2 +95,3 @@ node: {

if (this.opts.bounds) this.opts.types.push('bounds')
this.nodes = []
this.parser.onerror = this.onError.bind(this)

@@ -107,5 +108,19 @@ this.parser.onopentag = this.onOpenTag.bind(this)

this.parser.write(chunk.toString())
while (this.nodes.length) this.push(this.nodes.shift())
done(this.error)
}
Osm2Json.prototype.parse = function (str) {
this.parser.write(str)
this.parser.end()
if (this.error) {
var err = this.error
this.error = null
throw err
}
var nodes = this.nodes
this.nodes = []
return nodes
}
Osm2Json.prototype.onError = function (err) {

@@ -138,3 +153,3 @@ err.message = 'Invalid XML at line #' + this.parser.line +

} else if (is(this.opts.types, name)) {
this.push(this.currentNode)
this.nodes.push(this.currentNode)
this.currentNode = null

@@ -141,0 +156,0 @@ }

{
"name": "osm2json",
"version": "1.1.0",
"version": "1.2.0",
"description": "Converts an OSM XML file to OSM JSON objects as a transform stream",

@@ -30,2 +30,3 @@ "main": "lib/osm2json.js",

"concat-stream": "^1.5.1",
"from2-string": "^1.1.0",
"standard": "^8.0.0-beta.5",

@@ -32,0 +33,0 @@ "tape": "^4.6.0"

@@ -107,2 +107,6 @@ # osm2json

### stream.parse(str)
Parse `str` and return the result. Will throw any error.
## Contribute

@@ -109,0 +113,0 @@

@@ -5,2 +5,3 @@ var test = require('tape')

var concat = require('concat-stream')
var fromString = require('from2-string')

@@ -18,2 +19,11 @@ var Osm2Json = require('../lib/osm2json')

test('non-streaming', function (t) {
var expected = require('./output_defaults.json')
var input = fs.readFileSync(path.join(__dirname, 'test.osm'), 'utf8')
var parser = new Osm2Json()
t.deepEqual(parser.parse(input), expected)
t.deepEqual(parser.parse(input), expected, 're-usable')
t.end()
})
test('expected output coerceIds = false', function (t) {

@@ -64,1 +74,27 @@ var expected = require('./output_string_ids.json')

})
test('diffResult', function (t) {
var input = '<diffResult generator="OpenStreetMap Server" version="0.6">' +
'<node old_id="1" new_id="2" new_version="2"/>' +
'<way old_id="3" new_id="4" new_version="2"/>' +
'<relation old_id="5"/>' +
'</diffResult>'
var expected = [{
type: 'node',
old_id: 1,
new_id: 2,
new_version: 2
}, {
type: 'way',
old_id: 3,
new_id: 4,
new_version: 2
}, {
type: 'relation',
old_id: 5
}]
fromString(input).pipe(new Osm2Json()).pipe(concat(function (data) {
t.deepEqual(data, expected)
t.end()
}))
})
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