geojson-numeric
Advanced tools
Comparing version 0.1.1 to 0.2.0
15
index.js
@@ -1,2 +0,2 @@ | ||
function numeric( geojson ) { | ||
function numeric( geojson, recursive ) { | ||
@@ -15,7 +15,12 @@ function isNumeric(n) { | ||
function toNumeric(obj) { | ||
for (var key in obj) { | ||
if (isNumeric(obj[key])) | ||
obj[key] = parseFloat(obj[key]); | ||
else if (recursive && typeof obj[key] === "object") | ||
toNumeric(obj[key]); | ||
} | ||
} | ||
features.forEach(function mapFeature(f) { | ||
for (var key in f.properties) { | ||
if (isNumeric(f.properties[key])) | ||
f.properties[key] = parseFloat(f.properties[key]); | ||
} | ||
toNumeric(f.properties); | ||
}); | ||
@@ -22,0 +27,0 @@ |
{ | ||
"name": "geojson-numeric", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Makes properties of geojson features numeric.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,1 +63,31 @@ var numerify = require("../"); | ||
test('recursive', function (t) { | ||
var geojson = { | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [0,0] | ||
}, | ||
"properties": { | ||
"tags": { | ||
"asd": "fasd", | ||
"num": "123", | ||
}, | ||
"array": [ | ||
"str", | ||
"1.23" | ||
] | ||
} | ||
}] | ||
}; | ||
var result = numerify(geojson,true); | ||
t.equal(geojson.features[0].properties.tags.asd, "fasd"); | ||
t.equal(geojson.features[0].properties.tags.num, 123); | ||
t.equal(geojson.features[0].properties.array.length, 2); | ||
t.equal(geojson.features[0].properties.array[0], "str"); | ||
t.equal(geojson.features[0].properties.array[1], 1.23); | ||
t.end(); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6432
112