diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2022-05-21 16:28:04 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2022-05-21 16:28:04 +1000 |
commit | 1d94ced0ae9f5d511768e07f5c8c1a66625452e9 (patch) | |
tree | 02c33ebef00521a14ab16f0c17357ef67e5cec14 | |
parent | 47a3ab0c5b9e01e7369661f8929390115fa61610 (diff) |
improve within range when passed unit/number format
-rw-r--r-- | lib/withinRange.js | 7 |
1 files changed, 4 insertions, 3 deletions
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 = /^(?<pre>\D*)(?<num>\d*)(?<suf>\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 |