diff options
-rw-r--r-- | lib/withinRange.js | 5 | ||||
-rw-r--r-- | test/withinRange.js | 28 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/withinRange.js b/lib/withinRange.js index e75f788..3408a5a 100644 --- a/lib/withinRange.js +++ b/lib/withinRange.js @@ -28,7 +28,10 @@ module.exports = (feature, rangeFeature) => { const to = rangeParts[1].match(regexp).groups const i = feature.properties['addr:housenumber'].match(regexp).groups - if (i.num >= from.num && i.num <= to.num) { + if ( + Number.isInteger(Number(i.num)) && Number.isInteger(Number(from.num)) && Number.isInteger(Number(to.num)) && + Number(i.num) >= Number(from.num) && Number(i.num) <= Number(to.num) + ) { // feature within featureRange (ignore prefix/suffix) return true } else { diff --git a/test/withinRange.js b/test/withinRange.js index 1158c20..5dd349c 100644 --- a/test/withinRange.js +++ b/test/withinRange.js @@ -70,6 +70,29 @@ const AC_2 = { } } +const subNumber = { + "type": "Feature", + "properties": { + "addr:housenumber": "12C", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} +const rangeOutsideSub = { + "type": "Feature", + "properties": { + "addr:housenumber": "118-120", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} + test('withinRange', t => { t.same( @@ -102,6 +125,11 @@ test('withinRange', t => { false, 'A Main Street not within AC Secondary Street' ) + t.same( + withinRange(subNumber, rangeOutsideSub), + false, + '12C not within 118-120' + ) t.end() }) |