From ff1ab7e6a12305657bd5d6b298fce7345882e941 Mon Sep 17 00:00:00 2001 From: missinglink Date: Mon, 13 May 2019 13:23:43 +0200 Subject: [PATCH] feat(diacritics): remove diacritics for non-latin languages --- lib/analyze.js | 6 +++++- test/lib/analyze.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/analyze.js b/lib/analyze.js index f759e51d..cc13cf99 100644 --- a/lib/analyze.js +++ b/lib/analyze.js @@ -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', '¾'); diff --git a/test/lib/analyze.js b/test/lib/analyze.js index 6513aaae..9ae15f6f 100644 --- a/test/lib/analyze.js +++ b/test/lib/analyze.js @@ -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) {