Skip to content

Commit

Permalink
Replace all s.substr(x, 1) with s.charAt(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfent committed Apr 7, 2015
1 parent 9d76d91 commit ce1724e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion command-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ var parse = exports.parse = function (message, room, user, connection, levelsDee
}
}

if (message.substr(0, 1) === '/' && fullCmd) {
if (message.charAt(0) === '/' && fullCmd) {
// To guard against command typos, we now emit an error message
return connection.sendTo(room.id, "The command '/" + fullCmd + "' was unrecognized. To send a message starting with '/" + fullCmd + "', type '//" + fullCmd + "'.");
}
Expand Down
2 changes: 1 addition & 1 deletion config/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ var commands = exports.commands = {
}
prevSourceType = source.substr(0, 2);
prevSourceCount = source.substr(2) ? 0 : -1;
buffer += "<li>gen " + source.substr(0, 1) + " " + sourceNames[source.substr(1, 1)];
buffer += "<li>gen " + source.charAt(0) + " " + sourceNames[source.charAt(1)];
if (prevSourceType === '5E' && template.maleOnlyHidden) buffer += " (cannot have hidden ability)";
if (source.substr(2)) buffer += ": " + source.substr(2);
}
Expand Down
6 changes: 3 additions & 3 deletions config/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ exports.Formats = [

if (lsetData.sources && lsetData.sources.length === 1 && !lsetData.sourcesBefore) {
var source = lsetData.sources[0];
if (source.substr(1, 1) === 'S') {
if (source.charAt(1) === 'S') {
var eventData = null;
var splitSource = source.substr(2).split(' ');
var eventTemplate = this.getTemplate(splitSource[1]);
Expand Down Expand Up @@ -760,7 +760,7 @@ exports.Formats = [
if (!sources) sources = [];
for (var i = 0, len = lsetData.sources.length; i < len; i++) {
learned = lsetData.sources[i];
if (parseInt(learned.substr(0, 1), 10) <= sourcesBefore) {
if (parseInt(learned.charAt(0), 10) <= sourcesBefore) {
sources.push(learned);
}
}
Expand All @@ -770,7 +770,7 @@ exports.Formats = [
if (!lsetData.sources) lsetData.sources = [];
for (var i = 0, len = sources.length; i < len; i++) {
learned = sources[i];
if (parseInt(learned.substr(0, 1), 10) <= lsetData.sourcesBefore) {
if (parseInt(learned.charAt(0), 10) <= lsetData.sourcesBefore) {
lsetData.sources.push(learned);
}
}
Expand Down
4 changes: 2 additions & 2 deletions rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,13 @@ var BattleRoom = (function () {
var oldacre = Math.round(data.p1rating.oldacre);
var acre = Math.round(data.p1rating.acre);
var reasons = '' + (acre - oldacre) + ' for ' + (p1score > 0.99 ? 'winning' : (p1score < 0.01 ? 'losing' : 'tying'));
if (reasons.substr(0, 1) !== '-') reasons = '+' + reasons;
if (reasons.charAt(0) !== '-') reasons = '+' + reasons;
self.addRaw(Tools.escapeHTML(p1) + '\'s rating: ' + oldacre + ' &rarr; <strong>' + acre + '</strong><br />(' + reasons + ')');

oldacre = Math.round(data.p2rating.oldacre);
acre = Math.round(data.p2rating.acre);
reasons = '' + (acre - oldacre) + ' for ' + (p1score > 0.99 ? 'losing' : (p1score < 0.01 ? 'winning' : 'tying'));
if (reasons.substr(0, 1) !== '-') reasons = '+' + reasons;
if (reasons.charAt(0) !== '-') reasons = '+' + reasons;
self.addRaw(Tools.escapeHTML(p2) + '\'s rating: ' + oldacre + ' &rarr; <strong>' + acre + '</strong><br />(' + reasons + ')');

Users.get(p1).cacheMMR(rated.format, data.p1rating);
Expand Down
2 changes: 1 addition & 1 deletion simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ var Battle = (function () {
};
Battle.prototype.getPlayer = function (slot) {
if (typeof slot === 'string') {
if (slot.substr(0, 1) === 'p') {
if (slot.charAt(0) === 'p') {
slot = parseInt(slot.substr(1), 10) - 1;
} else {
slot = parseInt(slot, 10);
Expand Down
6 changes: 3 additions & 3 deletions team-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Validator = (function () {
if (lsetData.sources && lsetData.sources.length === 1 && !lsetData.sourcesBefore) {
// we're restricted to a single source
var source = lsetData.sources[0];
if (source.substr(1, 1) === 'S') {
if (source.charAt(1) === 'S') {
// it's an event
var eventData = null;
var splitSource = source.substr(2).split(' ');
Expand Down Expand Up @@ -768,7 +768,7 @@ Validator = (function () {
if (!sources) sources = [];
for (var i = 0, len = lsetData.sources.length; i < len; i++) {
learned = lsetData.sources[i];
if (parseInt(learned.substr(0, 1), 10) <= sourcesBefore) {
if (parseInt(learned.charAt(0), 10) <= sourcesBefore) {
sources.push(learned);
}
}
Expand All @@ -778,7 +778,7 @@ Validator = (function () {
if (!lsetData.sources) lsetData.sources = [];
for (var i = 0, len = sources.length; i < len; i++) {
learned = sources[i];
if (parseInt(learned.substr(0, 1), 10) <= lsetData.sourcesBefore) {
if (parseInt(learned.charAt(0), 10) <= lsetData.sourcesBefore) {
lsetData.sources.push(learned);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ module.exports = (function () {
Tools.prototype.getType = function (type) {
if (!type || typeof type === 'string') {
var id = toId(type);
id = id.substr(0, 1).toUpperCase() + id.substr(1);
id = id.charAt(0).toUpperCase() + id.substr(1);
type = {};
if (id && this.data.TypeChart[id]) {
type = this.data.TypeChart[id];
Expand Down
6 changes: 3 additions & 3 deletions users.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Users.socketReceive = function (worker, workerid, socketid, message) {
// from propagating out of this function.

// drop legacy JSON messages
if (message.substr(0, 1) === '{') return;
if (message.charAt(0) === '{') return;

// drop invalid messages without a pipe character
var pipeIndex = message.indexOf('|');
Expand Down Expand Up @@ -392,7 +392,7 @@ function importUsergroups() {
function exportUsergroups() {
var buffer = '';
for (var i in usergroups) {
buffer += usergroups[i].substr(1).replace(/,/g, '') + ',' + usergroups[i].substr(0, 1) + "\n";
buffer += usergroups[i].substr(1).replace(/,/g, '') + ',' + usergroups[i].charAt(0) + "\n";
}
fs.writeFile('config/usergroups.csv', buffer);
}
Expand Down Expand Up @@ -851,7 +851,7 @@ User = (function () {
return false;
}

if (token && token.substr(0, 1) !== ';') {
if (token && token.charAt(0) !== ';') {
var tokenSemicolonPos = token.indexOf(';');
var tokenData = token.substr(0, tokenSemicolonPos);
var tokenSig = token.substr(tokenSemicolonPos + 1);
Expand Down

0 comments on commit ce1724e

Please sign in to comment.