mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 07:07:33 +00:00
Replace deprecated substr with substring (#355)
* Make the QueryRunner more readable * Remove use of deprecated substr and replace with substring, and some formatting
This commit is contained in:
parent
65dd876252
commit
5b01e1be17
9 changed files with 66 additions and 61 deletions
|
|
@ -9,16 +9,20 @@ class GameResolver {
|
|||
}
|
||||
|
||||
lookup(type) {
|
||||
if(!type) throw Error('No game specified');
|
||||
if(!type)
|
||||
throw Error('No game specified');
|
||||
|
||||
if(type.substr(0,9) === 'protocol-') {
|
||||
if(type.substring(0,9) === 'protocol-') {
|
||||
return {
|
||||
protocol: type.substr(9)
|
||||
protocol: type.substring(9)
|
||||
};
|
||||
}
|
||||
|
||||
const game = this.gamesByKey.get(type);
|
||||
if(!game) throw Error('Invalid game: '+type);
|
||||
|
||||
if(!game)
|
||||
throw Error('Invalid game: '+type);
|
||||
|
||||
return game.options;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +65,7 @@ class GameResolver {
|
|||
for (let line of lines) {
|
||||
// strip comments
|
||||
const comment = line.indexOf('#');
|
||||
if(comment !== -1) line = line.substr(0,comment);
|
||||
if(comment !== -1) line = line.substring(0,comment);
|
||||
line = line.trim();
|
||||
if(!line) continue;
|
||||
|
||||
|
|
@ -82,27 +86,34 @@ class GameResolver {
|
|||
for (const key of keys) {
|
||||
gamesByKey.set(key, game);
|
||||
}
|
||||
|
||||
games.push(game);
|
||||
}
|
||||
return { gamesByKey, games };
|
||||
}
|
||||
|
||||
_parseList(str) {
|
||||
if(!str) return {};
|
||||
const out = {};
|
||||
if(!str)
|
||||
return {};
|
||||
|
||||
let out = {};
|
||||
for (const one of str.split(',')) {
|
||||
const equals = one.indexOf('=');
|
||||
const key = equals === -1 ? one : one.substr(0,equals);
|
||||
const key = equals === -1 ? one : one.substring(0, equals);
|
||||
|
||||
/** @type {string|number|boolean} */
|
||||
let value = equals === -1 ? '' : one.substr(equals+1);
|
||||
let value = equals === -1 ? '' : one.substring(equals + 1);
|
||||
|
||||
if(value === 'true' || value === '') value = true;
|
||||
else if(value === 'false') value = false;
|
||||
else if(!isNaN(parseInt(value))) value = parseInt(value);
|
||||
if(value === 'true' || value === '')
|
||||
value = true;
|
||||
else if(value === 'false')
|
||||
value = false;
|
||||
else if(!isNaN(parseInt(value)))
|
||||
value = parseInt(value);
|
||||
|
||||
out[key] = value;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue