-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (53 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var jsonstream = require('jsonstream');
var collection = '{"type":"FeatureCollection",';
var features = '"features":[';
var endFeatures = ']';
var endCollection = '}';
/**
* Initialize a through stream that will take in
* geojson formatted text and produce a stream containing
* the geocoding object from the main scope of the input.
*
* @returns {Stream}
*/
module.exports.parseGeocoding = function() {
return jsonstream.parse('geocoding');
};
/**
* Initialize a through stream that will take in
* geojson formatted text and produce a stream containing
* the feature ojects in the features array from the main
* scope of the input.
*
* @returns {Stream}
*/
module.exports.parse = function() {
return jsonstream.parse('features.*');
};
/**
* Initialize a through stream that will take in geojson objects
* and produce a text stream of geojson format.
* The object provided in the geocoderInfo parameter will be
* added to the main scope of the resulting geojson.
*
* @param {object} geocoderInfo
* @returns {Stream}
*/
module.exports.stringify = function(geocoderInfo) {
return jsonstream.stringify(openTemplate(geocoderInfo), '\n,\n', closeTemplate());
};
/**
* ||| |||
* VVV Helper functions VVV
*/
function openTemplate(geocoderInfo) {
var res = collection;
if (geocoderInfo) {
res += '"geocoding":' + JSON.stringify(geocoderInfo) + ',';
}
res += features;
return res;
}
function closeTemplate() {
return endFeatures + endCollection;
}