Skip to content

Commit d6359a7

Browse files
CommanderRootJonathan Ginsburg
authored andcommitted
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 <[email protected]>
1 parent f068854 commit d6359a7

8 files changed

Lines changed: 14 additions & 14 deletions

File tree

client/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var socket = io(location.host, {
1515
reconnectionDelay: 500,
1616
reconnectionDelayMax: Infinity,
1717
timeout: BROWSER_SOCKET_TIMEOUT,
18-
path: KARMA_PROXY_PATH + KARMA_URL_ROOT.substr(1) + 'socket.io',
18+
path: KARMA_PROXY_PATH + KARMA_URL_ROOT.slice(1) + 'socket.io',
1919
'sync disconnect on unload': true,
2020
useNativeTimers: true
2121
})

common/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports.isDefined = function (value) {
2020

2121
exports.parseQueryParams = function (locationSearch) {
2222
var params = {}
23-
var pairs = locationSearch.substr(1).split('&')
23+
var pairs = locationSearch.slice(1).split('&')
2424
var keyValue
2525

2626
for (var i = 0; i < pairs.length; i++) {

lib/completion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const options = {
3636

3737
function opositeWord (word) {
3838
if (word.startsWith('-')) {
39-
return word.startsWith('--no-') ? `--${word.substr(5)}` : `--no-${word.substr(2)}`
39+
return word.startsWith('--no-') ? `--${word.slice(5)}` : `--no-${word.slice(2)}`
4040
} else {
4141
return null
4242
}

lib/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class KarmaEventEmitter extends EventEmitter {
3535
bind (object) {
3636
for (const method in object) {
3737
if (method.startsWith('on') && helper.isFunction(object[method])) {
38-
this.on(helper.camelToSnake(method.substr(2)), function () {
38+
this.on(helper.camelToSnake(method.slice(2)), function () {
3939
// We do not use an arrow function here, to supply the caller as this.
4040
object[method].apply(object, Array.from(arguments).concat(this))
4141
})

lib/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ exports.camelToSnake = (camelCase) => {
9696
}
9797

9898
exports.ucFirst = (word) => {
99-
return word.charAt(0).toUpperCase() + word.substr(1)
99+
return word.charAt(0).toUpperCase() + word.slice(1)
100100
}
101101

102102
exports.dashToCamel = (dash) => {

lib/launcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Launcher {
6060
protocol = upstreamProxy.protocol
6161
hostname = upstreamProxy.hostname
6262
port = upstreamProxy.port
63-
urlRoot = upstreamProxy.path + urlRoot.substr(1)
63+
urlRoot = upstreamProxy.path + urlRoot.slice(1)
6464
}
6565

6666
return (name) => {

lib/middleware/karma.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const FILE_TYPES = [
3232

3333
function filePathToUrlPath (filePath, basePath, urlRoot, proxyPath) {
3434
if (filePath.startsWith(basePath)) {
35-
return proxyPath + urlRoot.substr(1) + 'base' + filePath.substr(basePath.length)
35+
return proxyPath + urlRoot.slice(1) + 'base' + filePath.slice(basePath.length)
3636
}
37-
return proxyPath + urlRoot.substr(1) + 'absolute' + filePath
37+
return proxyPath + urlRoot.slice(1) + 'absolute' + filePath
3838
}
3939

4040
function getQuery (urlStr) {
@@ -85,8 +85,8 @@ function createKarmaMiddleware (
8585
const requestedRangeHeader = request.headers.range
8686

8787
// redirect /__karma__ to /__karma__ (trailing slash)
88-
if (requestUrl === urlRoot.substr(0, urlRoot.length - 1)) {
89-
response.setHeader('Location', proxyPath + urlRoot.substr(1))
88+
if (requestUrl === urlRoot.slice(0, -1)) {
89+
response.setHeader('Location', proxyPath + urlRoot.slice(1))
9090
response.writeHead(301)
9191
return response.end('MOVED PERMANENTLY')
9292
}
@@ -97,7 +97,7 @@ function createKarmaMiddleware (
9797
}
9898

9999
// remove urlRoot prefix
100-
requestUrl = requestUrl.substr(urlRoot.length - 1)
100+
requestUrl = requestUrl.slice(urlRoot.length - 1)
101101

102102
// serve client.html
103103
if (requestUrl === '/') {

lib/runner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function parseExitCode (buffer, defaultExitCode, failOnEmptyTestSuite) {
1818

1919
const tail = buffer.slice(tailPos)
2020
const tailStr = tail.toString()
21-
if (tailStr.substr(0, tailStr.length - 2) === constant.EXIT_CODE) {
22-
const emptyInt = parseInt(tailStr.substr(-2, 1), 10)
23-
let exitCode = parseInt(tailStr.substr(-1), 10)
21+
if (tailStr.slice(0, -2) === constant.EXIT_CODE) {
22+
const emptyInt = parseInt(tailStr.slice(-2, -1), 10)
23+
let exitCode = parseInt(tailStr.slice(-1), 10)
2424
if (failOnEmptyTestSuite === false && emptyInt === 0) {
2525
log.warn('Test suite was empty.')
2626
exitCode = 0

0 commit comments

Comments
 (0)