Skip to content

Commit

Permalink
Merge pull request #202 from pelias/diacritics
Browse files Browse the repository at this point in the history
remove diacritics for non-latin languages
  • Loading branch information
missinglink authored May 13, 2019
2 parents 9f9e993 + ff1ab7e commit 247de5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ function housenumber( num ){
// still not a valid string?
if( 'string' !== typeof num ){ return NaN; }

// normalize string diacritics
// https://stackoverflow.com/a/37511463
var number = num.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

// replace fractions, eg: '1/2' with british style character suffices.
var number = num.replace(' 1/4', '¼')
number = number.replace(' 1/4', '¼')
.replace(' 1/2', '½')
.replace(' 3/4', '¾');

Expand Down
6 changes: 6 additions & 0 deletions test/lib/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ module.exports.analyze.housenumber = function(test) {
t.equal(analyze.housenumber('27, 2º, 4ª'), 27);
t.end();
});

// non-latin apartment letters
test('housenumber: 18Č', function (t) {
t.equal(analyze.housenumber('18Č'), 18.09);
t.end();
});
};
module.exports.analyze.housenumberFloatToString = function(test) {
test('housenumberFloatToString: invalid', function(t) {
Expand Down

0 comments on commit 247de5f

Please sign in to comment.