reduce use of parseFloat

as it silently strips non-numeric suffixes (e.g. a value of "123 foo" is transformed into a numeric value of 123 by `parseFloat`, which is typically not what we desire)
This commit is contained in:
Martin Raifer
2022-11-24 19:18:27 +01:00
parent fc75d5f2a1
commit 41aa127d23
10 changed files with 18 additions and 18 deletions

View File

@@ -140,7 +140,7 @@ export function actionSplit(nodeIds, newWayIds) {
if (wayA.tags.step_count) {
// divide up the the step count proportionally between the two ways
var stepCount = parseFloat(wayA.tags.step_count);
var stepCount = Number(wayA.tags.step_count);
if (stepCount &&
// ensure a number
isFinite(stepCount) &&

View File

@@ -22,8 +22,8 @@ export function behaviorBreathe() {
function ratchetyInterpolator(a, b, steps, units) {
a = parseFloat(a);
b = parseFloat(b);
a = Number(a);
b = Number(b);
var sample = d3_scaleQuantize()
.domain([0, 1])
.range(d3_quantize(d3_interpolateNumber(a, b), steps));
@@ -92,11 +92,11 @@ export function behaviorBreathe() {
// determine base opacity and width
if (tag === 'circle') {
opacity = parseFloat(s.style('fill-opacity') || 0.5);
width = parseFloat(s.style('r') || 15.5);
opacity = Number(s.style('fill-opacity') || 0.5);
width = Number(s.style('r') || 15.5);
} else {
opacity = parseFloat(s.style('stroke-opacity') || 0.7);
width = parseFloat(s.style('stroke-width') || 10);
opacity = Number(s.style('stroke-opacity') || 0.7);
width = Number(s.style('stroke-width') || 10);
}
// calculate from/to interpolation params..

View File

@@ -86,8 +86,8 @@ export function behaviorLasso(context) {
sharedParentNodes.indexOf(node2.id);
} else {
// vertices do not share a way; group them by their respective parent ways
return parseFloat(parents1[0].id.slice(1)) -
parseFloat(parents2[0].id.slice(1));
return Number(parents1[0].id.slice(1)) -
Number(parents2[0].id.slice(1));
}
} else if (parents1.length || parents2.length) {

View File

@@ -86,7 +86,7 @@ function abortUnwantedRequests(cache, visibleTiles) {
function getLoc(attrs) {
var lon = attrs.lon && attrs.lon.value;
var lat = attrs.lat && attrs.lat.value;
return [parseFloat(lon), parseFloat(lat)];
return [Number(lon), Number(lat)];
}
@@ -208,7 +208,7 @@ var jsonparsers = {
timestamp: obj.timestamp,
user: obj.user,
uid: obj.uid && obj.uid.toString(),
loc: [parseFloat(obj.lon), parseFloat(obj.lat)],
loc: [Number(obj.lon), Number(obj.lat)],
tags: obj.tags
});
},

View File

@@ -71,7 +71,7 @@ function clean(params) {
function filterKeys(type) {
var count_type = type ? 'count_' + type : 'count_all';
return function(d) {
return parseFloat(d[count_type]) > 2500 || d.in_wiki;
return Number(d[count_type]) > 2500 || d.in_wiki;
};
}
@@ -99,7 +99,7 @@ function filterRoles(geometry) {
return function(d) {
if (d.role === '') return false; // exclude empty role
if (d.role.match(/[A-Z*;,]/) !== null) return false; // exclude uppercase letters and some punctuation
return parseFloat(d[tag_members_fractions[geometry]]) > 0.0;
return Number(d[tag_members_fractions[geometry]]) > 0.0;
};
}

View File

@@ -340,7 +340,7 @@ export function uiCombobox(context, klass) {
if (!val) return;
// Don't autocomplete if user is typing a number - #4935
if (!isNaN(parseFloat(val)) && isFinite(val)) return;
if (isFinite(val)) return;
const suggestionValues = [];
_suggestions.forEach(s => {

View File

@@ -160,7 +160,7 @@ export function uiSectionValidationRules(context) {
function changeSquare() {
var input = d3_select(this);
var degStr = utilGetSetValue(input).trim();
var degNum = parseFloat(degStr, 10);
var degNum = Number(degStr);
if (!isFinite(degNum)) {
degNum = DEFAULTSQUARE;

View File

@@ -47,7 +47,7 @@ export function utilDetect(refresh) {
// detect other browser capabilities
// Legacy Opera has incomplete svg style support. See #715
_detected.opera = (_detected.browser.toLowerCase() === 'opera' && parseFloat(_detected.version) < 15 );
_detected.opera = (_detected.browser.toLowerCase() === 'opera' && Number(_detected.version) < 15 );
if (_detected.browser.toLowerCase() === 'msie') {
_detected.ie = true;

View File

@@ -523,7 +523,7 @@ export function validationCrossingWays(context) {
var crossedWay = graph.hasEntity(crossedWayID);
// use the explicit width of the crossed feature as the structure length, if available
var structLengthMeters = crossedWay && crossedWay.tags.width && parseFloat(crossedWay.tags.width);
var structLengthMeters = crossedWay && isFinite(crossedWay.tags.width) && Number(crossedWay.tags.width);
if (!structLengthMeters) {
// if no explicit width is set, approximate the width based on the tags
structLengthMeters = crossedWay && crossedWay.impliedLineWidthMeters();

View File

@@ -56,7 +56,7 @@ export function validationUnsquareWay(context) {
// user-configurable square threshold
var storedDegreeThreshold = prefs('validate-square-degrees');
var degreeThreshold = isNaN(storedDegreeThreshold) ? DEFAULT_DEG_THRESHOLD : parseFloat(storedDegreeThreshold);
var degreeThreshold = isFinite(storedDegreeThreshold) ? Number(storedDegreeThreshold) : DEFAULT_DEG_THRESHOLD;
var points = nodes.map(function(node) { return context.projection(node.loc); });
if (!geoOrthoCanOrthogonalize(points, isClosed, epsilon, degreeThreshold, true)) return [];