Compare with uppercase strings
parent
b414e9adeb
commit
fdd452b5db
|
@ -21,6 +21,40 @@ class PrefixParser {
|
|||
_getKeyByValue(object, value) {
|
||||
return Object.keys(object).find(key => object[key] === value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Makes an array of strings uppercase.
|
||||
* @param {String[]} a
|
||||
* @returns {String[]}
|
||||
*/
|
||||
_toUpperCaseArray(a) {
|
||||
// If the array is empty, return
|
||||
if (a.length === 0) return [];
|
||||
|
||||
/**
|
||||
* Makes a string uppercase.
|
||||
* @param {String} s
|
||||
* @returns {String}
|
||||
*/
|
||||
function toUpper(s) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
return a.map(toUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Check if `dict` contains `value` as a value.
|
||||
* @param {Object.<number, string>} dict
|
||||
* @param {String} value
|
||||
*/
|
||||
_valueInDict(dict, value) {
|
||||
const array = Object.values(dict);
|
||||
const upperArr = this._toUpperCaseArray(array);
|
||||
const element = value.toUpperCase();
|
||||
return upperArr.includes(element);
|
||||
}
|
||||
//#endregion Private methods
|
||||
|
||||
/**
|
||||
|
@ -33,10 +67,10 @@ class PrefixParser {
|
|||
for(const p of prefixes) {
|
||||
// Check what dict contains the value
|
||||
let dict = null;
|
||||
if(Object.values(shared.statuses).includes(p)) dict = shared.statuses;
|
||||
else if (Object.values(shared.engines).includes(p)) dict = shared.engines;
|
||||
else if (Object.values(shared.tags).includes(p)) dict = shared.tags;
|
||||
else if (Object.values(shared.others).includes(p)) dict = shared.others;
|
||||
if (this._valueInDict(shared.statuses, p)) dict = shared.statuses;
|
||||
else if (this._valueInDict(shared.engines, p)) dict = shared.engines;
|
||||
else if (this._valueInDict(shared.tags, p)) dict = shared.tags;
|
||||
else if (this._valueInDict(shared.others, p)) dict = shared.others;
|
||||
else continue;
|
||||
|
||||
// Extract the key from the dict
|
||||
|
@ -56,10 +90,10 @@ class PrefixParser {
|
|||
for(const id of ids) {
|
||||
// Check what dict contains the key
|
||||
let dict = null;
|
||||
if (Object.keys(shared.statuses).includes(id)) dict = shared.statuses;
|
||||
else if (Object.keys(shared.engines).includes(id)) dict = shared.engines;
|
||||
else if (Object.keys(shared.tags).includes(id)) dict = shared.tags;
|
||||
else if (Object.keys(shared.others).includes(id)) dict = shared.others;
|
||||
if (Object.keys(shared.statuses).includes(id.toString())) dict = shared.statuses;
|
||||
else if (Object.keys(shared.engines).includes(id.toString())) dict = shared.engines;
|
||||
else if (Object.keys(shared.tags).includes(id.toString())) dict = shared.tags;
|
||||
else if (Object.keys(shared.others).includes(id.toString())) dict = shared.others;
|
||||
else continue;
|
||||
|
||||
// Check if the key exists in the dict
|
||||
|
|
Loading…
Reference in New Issue