Ensure frequency values are always numbers (#1943)
This commit is contained in:
parent
9899727d7d
commit
c15683d206
@ -17,7 +17,7 @@
|
|||||||
"description": "Type of data. \"freq\" corresponds to frequency information."
|
"description": "Type of data. \"freq\" corresponds to frequency information."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": ["string", "number"],
|
"type": ["number"],
|
||||||
"description": "Data for the character."
|
"description": "Data for the character."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
{
|
{
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
{
|
{
|
||||||
"type": ["string", "number"],
|
"type": ["number"],
|
||||||
"description": "Frequency information for the term."
|
"description": "Frequency information for the term."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@
|
|||||||
"description": "Reading for the term."
|
"description": "Reading for the term."
|
||||||
},
|
},
|
||||||
"frequency": {
|
"frequency": {
|
||||||
"type": ["string", "number"],
|
"type": ["number"],
|
||||||
"description": "Frequency information for the term."
|
"description": "Frequency information for the term."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -866,7 +866,7 @@ class Translator {
|
|||||||
dictionaryIndex,
|
dictionaryIndex,
|
||||||
dictionaryPriority,
|
dictionaryPriority,
|
||||||
hasReading,
|
hasReading,
|
||||||
frequency
|
this._convertFrequency(frequency)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -920,7 +920,7 @@ class Translator {
|
|||||||
dictionaryIndex,
|
dictionaryIndex,
|
||||||
dictionaryPriority,
|
dictionaryPriority,
|
||||||
character,
|
character,
|
||||||
data
|
this._convertFrequency(data)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -971,6 +971,18 @@ class Translator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_convertFrequency(value) {
|
||||||
|
switch (typeof value) {
|
||||||
|
case 'number':
|
||||||
|
return value;
|
||||||
|
case 'string':
|
||||||
|
value = Number.parseFloat(value);
|
||||||
|
return Number.isFinite(value) ? value : 0;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
_getNameBase(name) {
|
_getNameBase(name) {
|
||||||
|
Loading…
Reference in New Issue
Block a user