Skip to content

Commit cde9356

Browse files
Replace deprecated String.prototype.substr() (#2298)
.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 fbe81ad commit cde9356

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

examples/node/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ function printLine(event) {
341341

342342
var maxNameWidth = 15;
343343
if (name.length > maxNameWidth) {
344-
name = name.substr(0, maxNameWidth-1) + "\u2026";
344+
name = name.slice(0, maxNameWidth-1) + "\u2026";
345345
}
346346

347347
if (event.getType() === "m.room.message") {
@@ -398,7 +398,7 @@ function print(str, formatter) {
398398

399399
function fixWidth(str, len) {
400400
if (str.length > len) {
401-
return str.substr(0, len-2) + "\u2026";
401+
return str.substring(0, len-2) + "\u2026";
402402
}
403403
else if (str.length < len) {
404404
return str + new Array(len - str.length).join(" ");

src/content-repo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export function getHttpUriForMxc(
7373
const fragmentOffset = serverAndMediaId.indexOf("#");
7474
let fragment = "";
7575
if (fragmentOffset >= 0) {
76-
fragment = serverAndMediaId.substr(fragmentOffset);
77-
serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset);
76+
fragment = serverAndMediaId.slice(fragmentOffset);
77+
serverAndMediaId = serverAndMediaId.slice(0, fragmentOffset);
7878
}
7979

8080
const urlParams = (Object.keys(params).length === 0 ? "" : ("?" + utils.encodeParams(params)));

src/crypto/store/localStorage-crypto-store.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
228228
// (hence 43 characters long).
229229

230230
func({
231-
senderKey: key.substr(KEY_INBOUND_SESSION_PREFIX.length, 43),
232-
sessionId: key.substr(KEY_INBOUND_SESSION_PREFIX.length + 44),
231+
senderKey: key.slice(KEY_INBOUND_SESSION_PREFIX.length, KEY_INBOUND_SESSION_PREFIX.length + 43),
232+
sessionId: key.slice(KEY_INBOUND_SESSION_PREFIX.length + 44),
233233
sessionData: getJsonItem(this.store, key),
234234
});
235235
}
@@ -299,7 +299,7 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
299299
for (let i = 0; i < this.store.length; ++i) {
300300
const key = this.store.key(i);
301301
if (key.startsWith(prefix)) {
302-
const roomId = key.substr(prefix.length);
302+
const roomId = key.slice(prefix.length);
303303
result[roomId] = getJsonItem(this.store, key);
304304
}
305305
}
@@ -313,8 +313,8 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
313313
for (const session in sessionsNeedingBackup) {
314314
if (Object.prototype.hasOwnProperty.call(sessionsNeedingBackup, session)) {
315315
// see getAllEndToEndInboundGroupSessions for the magic number explanations
316-
const senderKey = session.substr(0, 43);
317-
const sessionId = session.substr(44);
316+
const senderKey = session.slice(0, 43);
317+
const sessionId = session.slice(44);
318318
this.getEndToEndInboundGroupSession(
319319
senderKey, sessionId, null,
320320
(sessionData) => {

src/crypto/store/memory-crypto-store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ export class MemoryCryptoStore implements CryptoStore {
418418
// (hence 43 characters long).
419419

420420
func({
421-
senderKey: key.substr(0, 43),
422-
sessionId: key.substr(44),
421+
senderKey: key.slice(0, 43),
422+
sessionId: key.slice(44),
423423
sessionData: this.inboundGroupSessions[key],
424424
});
425425
}
@@ -482,8 +482,8 @@ export class MemoryCryptoStore implements CryptoStore {
482482
for (const session in this.sessionsNeedingBackup) {
483483
if (this.inboundGroupSessions[session]) {
484484
sessions.push({
485-
senderKey: session.substr(0, 43),
486-
sessionId: session.substr(44),
485+
senderKey: session.slice(0, 43),
486+
sessionId: session.slice(44),
487487
sessionData: this.inboundGroupSessions[session],
488488
});
489489
if (limit && session.length >= limit) {

src/filter-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
function matchesWildcard(actualValue: string, filterValue: string): boolean {
3737
if (filterValue.endsWith("*")) {
3838
const typePrefix = filterValue.slice(0, -1);
39-
return actualValue.substr(0, typePrefix.length) === typePrefix;
39+
return actualValue.slice(0, typePrefix.length) === typePrefix;
4040
} else {
4141
return actualValue === filterValue;
4242
}

src/store/session/webstorage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ WebStorageSessionStore.prototype = {
7878
const devices = {};
7979
for (let i = 0; i < this.store.length; ++i) {
8080
const key = this.store.key(i);
81-
const userId = key.substr(prefix.length);
81+
const userId = key.slice(prefix.length);
8282
if (key.startsWith(prefix)) devices[userId] = getJsonItem(this.store, key);
8383
}
8484
return devices;
@@ -125,7 +125,7 @@ WebStorageSessionStore.prototype = {
125125
const deviceKeys = getKeysWithPrefix(this.store, keyEndToEndSessions(''));
126126
const results = {};
127127
for (const k of deviceKeys) {
128-
const unprefixedKey = k.substr(keyEndToEndSessions('').length);
128+
const unprefixedKey = k.slice(keyEndToEndSessions('').length);
129129
results[unprefixedKey] = getJsonItem(this.store, k);
130130
}
131131
return results;
@@ -158,8 +158,8 @@ WebStorageSessionStore.prototype = {
158158
// (hence 43 characters long).
159159

160160
result.push({
161-
senderKey: key.substr(prefix.length, 43),
162-
sessionId: key.substr(prefix.length + 44),
161+
senderKey: key.slice(prefix.length, prefix.length + 43),
162+
sessionId: key.slice(prefix.length + 44),
163163
});
164164
}
165165
return result;
@@ -182,7 +182,7 @@ WebStorageSessionStore.prototype = {
182182
const roomKeys = getKeysWithPrefix(this.store, keyEndToEndRoom(''));
183183
const results = {};
184184
for (const k of roomKeys) {
185-
const unprefixedKey = k.substr(keyEndToEndRoom('').length);
185+
const unprefixedKey = k.slice(keyEndToEndRoom('').length);
186186
results[unprefixedKey] = getJsonItem(this.store, k);
187187
}
188188
return results;

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export function globToRegexp(glob: string, extended?: any): string {
427427

428428
export function ensureNoTrailingSlash(url: string): string {
429429
if (url && url.endsWith("/")) {
430-
return url.substr(0, url.length - 1);
430+
return url.slice(0, -1);
431431
} else {
432432
return url;
433433
}

0 commit comments

Comments
 (0)