Skip to content

Commit d86c06f

Browse files
authored
skip encoding null values altogether (#43)
1 parent 0adf420 commit d86c06f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,20 @@ function writeProperties (context, pbf) {
9494
var valuecache = context.valuecache
9595

9696
for (var key in feature.properties) {
97+
var value = feature.properties[key]
98+
9799
var keyIndex = keycache[key]
100+
if (value === null) continue // don't encode null value properties
101+
98102
if (typeof keyIndex === 'undefined') {
99103
keys.push(key)
100104
keyIndex = keys.length - 1
101105
keycache[key] = keyIndex
102106
}
103107
pbf.writeVarint(keyIndex)
104108

105-
var value = feature.properties[key]
106109
var type = typeof value
107-
if (value !== null && type !== 'string' && type !== 'boolean' && type !== 'number') {
110+
if (type !== 'string' && type !== 'boolean' && type !== 'number') {
108111
value = JSON.stringify(value)
109112
}
110113
var valueKey = type + ':' + value

test/properties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('property encoding', function (t) {
5555
var second = layer.feature(1).properties
5656
t.same(first.c, '{"hello":"world"}')
5757
t.same(first.d, '[1,2,3]')
58-
t.equals(first.e, null)
58+
t.equals(first.e, undefined)
5959
t.same(second.c, '{"goodbye":"planet"}')
6060
t.same(second.d, '{"hello":"world"}')
6161
t.end()

0 commit comments

Comments
 (0)