From 1d94ced0ae9f5d511768e07f5c8c1a66625452e9 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Sat, 21 May 2022 16:28:04 +1000 Subject: improve within range when passed unit/number format --- lib/withinRange.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/withinRange.js') diff --git a/lib/withinRange.js b/lib/withinRange.js index f8b61ad..81bb6d4 100644 --- a/lib/withinRange.js +++ b/lib/withinRange.js @@ -6,7 +6,7 @@ * @param {boolean} [options.checkHigherOrderAddrKeys=true] - if true checks that addr:suburb, addr:state, addr:postcode also match * @param {boolean} [options.checkStreet=true] - if true checks that addr:street matches * - * @returns {boolean} True if addr:housenumber of feature is within the range of addr:housenumber rangeFeature and all other addr:* attributes match + * @returns {boolean} True if addr:housenumber of feature is within the range of addr:housenumber rangeFeature and all other addr:* attributes match, ignoring any unit from a "unit/number" style addr:housenumber of rangeFeature */ module.exports = (feature, rangeFeature, options) => { const regexp = /^(?
\D*)(?\d*)(?\D*)$/
@@ -37,13 +37,14 @@ module.exports = (feature, rangeFeature, options) => {
       ) : true
     )
   ) {
-    const rangeParts = rangeFeature.properties['addr:housenumber'].split('-')
+    const rangeNumber = rangeFeature.properties["addr:housenumber"].split("/").length > 1 ? rangeFeature.properties["addr:housenumber"].split("/")[1] : rangeFeature.properties["addr:housenumber"];
+    const rangeParts = rangeNumber.split('-')
     if (rangeParts.length === 2) {
       const fromMatch = rangeParts[0].match(regexp)
       const toMatch = rangeParts[1].match(regexp)
 
       if (!fromMatch || !toMatch) {
-        console.log(`range ${rangeFeature.properties['addr:housenumber']} didn't match regexp`, rangeFeature)
+        console.log(`range ${rangeNumber} didn't match regexp`, rangeFeature)
         return false
       }
       const from = rangeParts[0].match(regexp).groups
-- 
cgit v1.2.3