Compare commits

..

No commits in common. "060e387b9f1dcbab93fe29c88eedb8815d5c1d92" and "4c7d5e33d0f7761b2b45a98417b3bb77a801a21d" have entirely different histories.

2 changed files with 7 additions and 23 deletions

View File

@ -132,9 +132,8 @@ function hasAddressOrNumberHeader(headers) {
}
function hasGeoHeaders(headers) {
const norm = headers.map(normalizeHeader);
return norm.some(h => /\blat(itude)?\b/.test(h))
&& norm.some(h => /\blo?n[g]?(itude)?\b/.test(h));
return hasHeaderAlias(headers, ['latitude', 'lat'])
&& hasHeaderAlias(headers, ['longitude', 'long', 'lng', 'lon']);
}
function findHeaderRowIndex(rows) {
@ -153,10 +152,8 @@ function resolveColumnIndexes(headers) {
idxCep: findFirstHeaderIndex(headers, header => /\bcep\b/.test(header) || header === 'codigo postal'),
idxNumero: exactIndex(['numero', 'número', 'num', 'nº', 'n°']),
idxEndereco: findFirstHeaderIndex(headers, header => header.includes('endereco') || header.includes('logradouro')),
// Antes: exactIndex(['latitude', 'lat'])
idxLatitude: findFirstHeaderIndex(headers, header => /\blat(itude)?\b/.test(header)),
// Antes: exactIndex(['longitude', 'long', 'lng', 'lon'])
idxLongitude: findFirstHeaderIndex(headers, header => /\blo?n[g]?(itude)?\b/.test(header)),
idxLatitude: exactIndex(['latitude', 'lat']),
idxLongitude: exactIndex(['longitude', 'long', 'lng', 'lon'])
};
}
@ -190,20 +187,7 @@ function buildCepPayload(cols, indexes) {
}
function parseCoordinate(value) {
const str = String(value ?? '')
.replace(/[\u00A0\u202F\u2000-\u200B\u3000]/g, '') // Bug 2: remove non-breaking spaces
.trim()
.replace(',', '.');
// Bug 3: converte DMS "17 38 18.80 S" → -17.638556
const dms = str.match(/^(\d+)[°\s]+(\d+)['\s]+(\d+(?:\.\d+)?)["\s]*([NSEW])?$/i);
if (dms) {
const decimal = parseFloat(dms[1]) + parseFloat(dms[2]) / 60 + parseFloat(dms[3]) / 3600;
const negative = /[SW]/i.test(dms[4] ?? '');
return negative ? -decimal : decimal;
}
const parsed = parseFloat(str);
const parsed = parseFloat(String(value ?? '').trim().replace(',', '.'));
return Number.isFinite(parsed) ? parsed : NaN;
}

View File

@ -105,8 +105,8 @@ function hasAddressOrNumberHeader(headers) {
}
function hasGeoHeaders(headers) {
return headers.some(h => /\blat(itude)?\b/.test(h))
&& headers.some(h => /\blo?n[g]?(itude)?\b/.test(h));
return hasHeader(headers, ['latitude', 'lat'])
&& hasHeader(headers, ['longitude', 'long', 'lng', 'lon']);
}
async function consultarViabilidade(data) {