From d6359a7160ed9a7397370a4b3c8f06af2614ceee Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Sun, 27 Mar 2022 01:59:31 +0100 Subject: [PATCH] refactor: replace deprecated String.prototype.substr() .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated Signed-off-by: Tobias Speicher --- client/main.js | 2 +- common/util.js | 2 +- lib/completion.js | 2 +- lib/events.js | 2 +- lib/helper.js | 2 +- lib/launcher.js | 2 +- lib/middleware/karma.js | 10 +++++----- lib/runner.js | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/main.js b/client/main.js index 7dfc5b738..f8546ebb5 100644 --- a/client/main.js +++ b/client/main.js @@ -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 }) diff --git a/common/util.js b/common/util.js index 9d406c635..6c251a901 100644 --- a/common/util.js +++ b/common/util.js @@ -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++) { diff --git a/lib/completion.js b/lib/completion.js index 8e2d56f63..eb058527c 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -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 } diff --git a/lib/events.js b/lib/events.js index 6d8280bfc..7d64ce39d 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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)) }) diff --git a/lib/helper.js b/lib/helper.js index cd239ecc3..3c58fe8dc 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -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) => { diff --git a/lib/launcher.js b/lib/launcher.js index 723390c09..e374fbbd1 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -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) => { diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 5f701e7e7..a5c94f399 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -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) { @@ -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') } @@ -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 === '/') { diff --git a/lib/runner.js b/lib/runner.js index 7d07bb08b..2e04065b6 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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