Skip to content

Commit

Permalink
refactor: replace deprecated String.prototype.substr()
Browse files Browse the repository at this point in the history
.substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
  • Loading branch information
CommanderRoot authored and Jonathan Ginsburg committed Mar 27, 2022
1 parent f068854 commit d6359a7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var socket = io(location.host, {
reconnectionDelay: 500,
reconnectionDelayMax: Infinity,
timeout: BROWSER_SOCKET_TIMEOUT,
path: KARMA_PROXY_PATH + KARMA_URL_ROOT.substr(1) + 'socket.io',
path: KARMA_PROXY_PATH + KARMA_URL_ROOT.slice(1) + 'socket.io',
'sync disconnect on unload': true,
useNativeTimers: true
})
Expand Down
2 changes: 1 addition & 1 deletion common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports.isDefined = function (value) {

exports.parseQueryParams = function (locationSearch) {
var params = {}
var pairs = locationSearch.substr(1).split('&')
var pairs = locationSearch.slice(1).split('&')
var keyValue

for (var i = 0; i < pairs.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const options = {

function opositeWord (word) {
if (word.startsWith('-')) {
return word.startsWith('--no-') ? `--${word.substr(5)}` : `--no-${word.substr(2)}`
return word.startsWith('--no-') ? `--${word.slice(5)}` : `--no-${word.slice(2)}`
} else {
return null
}
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class KarmaEventEmitter extends EventEmitter {
bind (object) {
for (const method in object) {
if (method.startsWith('on') && helper.isFunction(object[method])) {
this.on(helper.camelToSnake(method.substr(2)), function () {
this.on(helper.camelToSnake(method.slice(2)), function () {
// We do not use an arrow function here, to supply the caller as this.
object[method].apply(object, Array.from(arguments).concat(this))
})
Expand Down
2 changes: 1 addition & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ exports.camelToSnake = (camelCase) => {
}

exports.ucFirst = (word) => {
return word.charAt(0).toUpperCase() + word.substr(1)
return word.charAt(0).toUpperCase() + word.slice(1)
}

exports.dashToCamel = (dash) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Launcher {
protocol = upstreamProxy.protocol
hostname = upstreamProxy.hostname
port = upstreamProxy.port
urlRoot = upstreamProxy.path + urlRoot.substr(1)
urlRoot = upstreamProxy.path + urlRoot.slice(1)
}

return (name) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const FILE_TYPES = [

function filePathToUrlPath (filePath, basePath, urlRoot, proxyPath) {
if (filePath.startsWith(basePath)) {
return proxyPath + urlRoot.substr(1) + 'base' + filePath.substr(basePath.length)
return proxyPath + urlRoot.slice(1) + 'base' + filePath.slice(basePath.length)
}
return proxyPath + urlRoot.substr(1) + 'absolute' + filePath
return proxyPath + urlRoot.slice(1) + 'absolute' + filePath
}

function getQuery (urlStr) {
Expand Down Expand Up @@ -85,8 +85,8 @@ function createKarmaMiddleware (
const requestedRangeHeader = request.headers.range

// redirect /__karma__ to /__karma__ (trailing slash)
if (requestUrl === urlRoot.substr(0, urlRoot.length - 1)) {
response.setHeader('Location', proxyPath + urlRoot.substr(1))
if (requestUrl === urlRoot.slice(0, -1)) {
response.setHeader('Location', proxyPath + urlRoot.slice(1))
response.writeHead(301)
return response.end('MOVED PERMANENTLY')
}
Expand All @@ -97,7 +97,7 @@ function createKarmaMiddleware (
}

// remove urlRoot prefix
requestUrl = requestUrl.substr(urlRoot.length - 1)
requestUrl = requestUrl.slice(urlRoot.length - 1)

// serve client.html
if (requestUrl === '/') {
Expand Down
6 changes: 3 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function parseExitCode (buffer, defaultExitCode, failOnEmptyTestSuite) {

const tail = buffer.slice(tailPos)
const tailStr = tail.toString()
if (tailStr.substr(0, tailStr.length - 2) === constant.EXIT_CODE) {
const emptyInt = parseInt(tailStr.substr(-2, 1), 10)
let exitCode = parseInt(tailStr.substr(-1), 10)
if (tailStr.slice(0, -2) === constant.EXIT_CODE) {
const emptyInt = parseInt(tailStr.slice(-2, -1), 10)
let exitCode = parseInt(tailStr.slice(-1), 10)
if (failOnEmptyTestSuite === false && emptyInt === 0) {
log.warn('Test suite was empty.')
exitCode = 0
Expand Down

0 comments on commit d6359a7

Please # to comment.