diff --git a/index.js b/index.js index 693653b..61eb997 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,11 @@ const voies = require('./lib/voies') -const {extractNumeroSuffixe, rewriteSuffixes} = require('./lib/numeros') +const {extractNumeroSuffixe, rewriteSuffixes, getPositionPriorityByType} = require('./lib/numeros') const bal = require('./lib/bal') module.exports = { ...voies, ...bal, rewriteSuffixes, - extractNumeroSuffixe + extractNumeroSuffixe, + getPositionPriorityByType } diff --git a/lib/numeros/index.js b/lib/numeros/index.js index 6e74906..ee04fb5 100644 --- a/lib/numeros/index.js +++ b/lib/numeros/index.js @@ -1,5 +1,24 @@ const {chain} = require('lodash') +const POSITION_TYPES_PRIORITY = { + entrée: 10, + bâtiment: 8, + 'cage d’escalier': 7, + logement: 6, + 'service technique': 5, + 'délivrance postale': 3, + parcelle: 2, + segment: 1 +} + +function getPositionPriorityByType(type) { + if (!type) { + return 0 + } + + return POSITION_TYPES_PRIORITY[type] || 0 +} + function extractNumeroSuffixe(numeroComplet) { const result = String(numeroComplet).match(/^(\d+)(.*)$/i) if (!result) { @@ -39,4 +58,4 @@ function rewriteSuffixes(adresses) { .value() } -module.exports = {extractNumeroSuffixe, rewriteSuffixes} +module.exports = {extractNumeroSuffixe, rewriteSuffixes, getPositionPriorityByType}