diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-07-01 00:28:56 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-07-01 00:28:56 +1000 |
commit | fde743937c9af05bcaf8b959c54c89404f97bc22 (patch) | |
tree | e551fc19abec02e31b2ebdf8aa88c7f0478a0c65 /lib/withinRange.js | |
parent | 4fab88019b9ff0324d9709dfff48615b5464729c (diff) |
within range provide a drop reason and consider parity of number
Diffstat (limited to 'lib/withinRange.js')
-rw-r--r-- | lib/withinRange.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/withinRange.js b/lib/withinRange.js index 3408a5a..7b6aa18 100644 --- a/lib/withinRange.js +++ b/lib/withinRange.js @@ -1,10 +1,12 @@ /** * @param {Object} feature * @param {Object} rangeFeature + * @param {Object} options + * @param {boolean} options.matchParity - if the parity of the number must match the range to be considered within (eg. if true, then 2 would not be within 1-3 but would be within 2-4 or within 0-4) * * @returns {boolean} True if addr:housenumber of feature is within the range of addr:housenumber rangeFeature and all other addr:* attributes match */ -module.exports = (feature, rangeFeature) => { +module.exports = (feature, rangeFeature, options) => { const regexp = /^(?<pre>\D*)(?<num>\d*)(?<suf>\D*)$/ if ( @@ -33,7 +35,19 @@ module.exports = (feature, rangeFeature) => { Number(i.num) >= Number(from.num) && Number(i.num) <= Number(to.num) ) { // feature within featureRange (ignore prefix/suffix) - return true + if (options && options.matchParity) { + // if parity matches (ie. both number and from/to are even, or both are odd, but not one even and one odd) + if ( + ((Number(i.num) % 2) === (Number(from.num) % 2)) && + ((Number(i.num) % 2) === (Number(to.num) % 2)) + ) { + return true + } else { + return false + } + } else { + return true + } } else { return false } |