You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
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 <rootcommander@gmail.com>
This commit is contained in:
@ -341,7 +341,7 @@ function printLine(event) {
|
|||||||
|
|
||||||
var maxNameWidth = 15;
|
var maxNameWidth = 15;
|
||||||
if (name.length > maxNameWidth) {
|
if (name.length > maxNameWidth) {
|
||||||
name = name.substr(0, maxNameWidth-1) + "\u2026";
|
name = name.slice(0, maxNameWidth-1) + "\u2026";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getType() === "m.room.message") {
|
if (event.getType() === "m.room.message") {
|
||||||
@ -398,7 +398,7 @@ function print(str, formatter) {
|
|||||||
|
|
||||||
function fixWidth(str, len) {
|
function fixWidth(str, len) {
|
||||||
if (str.length > len) {
|
if (str.length > len) {
|
||||||
return str.substr(0, len-2) + "\u2026";
|
return str.substring(0, len-2) + "\u2026";
|
||||||
}
|
}
|
||||||
else if (str.length < len) {
|
else if (str.length < len) {
|
||||||
return str + new Array(len - str.length).join(" ");
|
return str + new Array(len - str.length).join(" ");
|
||||||
|
@ -73,8 +73,8 @@ export function getHttpUriForMxc(
|
|||||||
const fragmentOffset = serverAndMediaId.indexOf("#");
|
const fragmentOffset = serverAndMediaId.indexOf("#");
|
||||||
let fragment = "";
|
let fragment = "";
|
||||||
if (fragmentOffset >= 0) {
|
if (fragmentOffset >= 0) {
|
||||||
fragment = serverAndMediaId.substr(fragmentOffset);
|
fragment = serverAndMediaId.slice(fragmentOffset);
|
||||||
serverAndMediaId = serverAndMediaId.substr(0, fragmentOffset);
|
serverAndMediaId = serverAndMediaId.slice(0, fragmentOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlParams = (Object.keys(params).length === 0 ? "" : ("?" + utils.encodeParams(params)));
|
const urlParams = (Object.keys(params).length === 0 ? "" : ("?" + utils.encodeParams(params)));
|
||||||
|
@ -228,8 +228,8 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
|
|||||||
// (hence 43 characters long).
|
// (hence 43 characters long).
|
||||||
|
|
||||||
func({
|
func({
|
||||||
senderKey: key.substr(KEY_INBOUND_SESSION_PREFIX.length, 43),
|
senderKey: key.slice(KEY_INBOUND_SESSION_PREFIX.length, KEY_INBOUND_SESSION_PREFIX.length + 43),
|
||||||
sessionId: key.substr(KEY_INBOUND_SESSION_PREFIX.length + 44),
|
sessionId: key.slice(KEY_INBOUND_SESSION_PREFIX.length + 44),
|
||||||
sessionData: getJsonItem(this.store, key),
|
sessionData: getJsonItem(this.store, key),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -299,7 +299,7 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
|
|||||||
for (let i = 0; i < this.store.length; ++i) {
|
for (let i = 0; i < this.store.length; ++i) {
|
||||||
const key = this.store.key(i);
|
const key = this.store.key(i);
|
||||||
if (key.startsWith(prefix)) {
|
if (key.startsWith(prefix)) {
|
||||||
const roomId = key.substr(prefix.length);
|
const roomId = key.slice(prefix.length);
|
||||||
result[roomId] = getJsonItem(this.store, key);
|
result[roomId] = getJsonItem(this.store, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,8 +313,8 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore {
|
|||||||
for (const session in sessionsNeedingBackup) {
|
for (const session in sessionsNeedingBackup) {
|
||||||
if (Object.prototype.hasOwnProperty.call(sessionsNeedingBackup, session)) {
|
if (Object.prototype.hasOwnProperty.call(sessionsNeedingBackup, session)) {
|
||||||
// see getAllEndToEndInboundGroupSessions for the magic number explanations
|
// see getAllEndToEndInboundGroupSessions for the magic number explanations
|
||||||
const senderKey = session.substr(0, 43);
|
const senderKey = session.slice(0, 43);
|
||||||
const sessionId = session.substr(44);
|
const sessionId = session.slice(44);
|
||||||
this.getEndToEndInboundGroupSession(
|
this.getEndToEndInboundGroupSession(
|
||||||
senderKey, sessionId, null,
|
senderKey, sessionId, null,
|
||||||
(sessionData) => {
|
(sessionData) => {
|
||||||
|
@ -418,8 +418,8 @@ export class MemoryCryptoStore implements CryptoStore {
|
|||||||
// (hence 43 characters long).
|
// (hence 43 characters long).
|
||||||
|
|
||||||
func({
|
func({
|
||||||
senderKey: key.substr(0, 43),
|
senderKey: key.slice(0, 43),
|
||||||
sessionId: key.substr(44),
|
sessionId: key.slice(44),
|
||||||
sessionData: this.inboundGroupSessions[key],
|
sessionData: this.inboundGroupSessions[key],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -482,8 +482,8 @@ export class MemoryCryptoStore implements CryptoStore {
|
|||||||
for (const session in this.sessionsNeedingBackup) {
|
for (const session in this.sessionsNeedingBackup) {
|
||||||
if (this.inboundGroupSessions[session]) {
|
if (this.inboundGroupSessions[session]) {
|
||||||
sessions.push({
|
sessions.push({
|
||||||
senderKey: session.substr(0, 43),
|
senderKey: session.slice(0, 43),
|
||||||
sessionId: session.substr(44),
|
sessionId: session.slice(44),
|
||||||
sessionData: this.inboundGroupSessions[session],
|
sessionData: this.inboundGroupSessions[session],
|
||||||
});
|
});
|
||||||
if (limit && session.length >= limit) {
|
if (limit && session.length >= limit) {
|
||||||
|
@ -36,7 +36,7 @@ import {
|
|||||||
function matchesWildcard(actualValue: string, filterValue: string): boolean {
|
function matchesWildcard(actualValue: string, filterValue: string): boolean {
|
||||||
if (filterValue.endsWith("*")) {
|
if (filterValue.endsWith("*")) {
|
||||||
const typePrefix = filterValue.slice(0, -1);
|
const typePrefix = filterValue.slice(0, -1);
|
||||||
return actualValue.substr(0, typePrefix.length) === typePrefix;
|
return actualValue.slice(0, typePrefix.length) === typePrefix;
|
||||||
} else {
|
} else {
|
||||||
return actualValue === filterValue;
|
return actualValue === filterValue;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ WebStorageSessionStore.prototype = {
|
|||||||
const devices = {};
|
const devices = {};
|
||||||
for (let i = 0; i < this.store.length; ++i) {
|
for (let i = 0; i < this.store.length; ++i) {
|
||||||
const key = this.store.key(i);
|
const key = this.store.key(i);
|
||||||
const userId = key.substr(prefix.length);
|
const userId = key.slice(prefix.length);
|
||||||
if (key.startsWith(prefix)) devices[userId] = getJsonItem(this.store, key);
|
if (key.startsWith(prefix)) devices[userId] = getJsonItem(this.store, key);
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
@ -125,7 +125,7 @@ WebStorageSessionStore.prototype = {
|
|||||||
const deviceKeys = getKeysWithPrefix(this.store, keyEndToEndSessions(''));
|
const deviceKeys = getKeysWithPrefix(this.store, keyEndToEndSessions(''));
|
||||||
const results = {};
|
const results = {};
|
||||||
for (const k of deviceKeys) {
|
for (const k of deviceKeys) {
|
||||||
const unprefixedKey = k.substr(keyEndToEndSessions('').length);
|
const unprefixedKey = k.slice(keyEndToEndSessions('').length);
|
||||||
results[unprefixedKey] = getJsonItem(this.store, k);
|
results[unprefixedKey] = getJsonItem(this.store, k);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
@ -158,8 +158,8 @@ WebStorageSessionStore.prototype = {
|
|||||||
// (hence 43 characters long).
|
// (hence 43 characters long).
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
senderKey: key.substr(prefix.length, 43),
|
senderKey: key.slice(prefix.length, prefix.length + 43),
|
||||||
sessionId: key.substr(prefix.length + 44),
|
sessionId: key.slice(prefix.length + 44),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -182,7 +182,7 @@ WebStorageSessionStore.prototype = {
|
|||||||
const roomKeys = getKeysWithPrefix(this.store, keyEndToEndRoom(''));
|
const roomKeys = getKeysWithPrefix(this.store, keyEndToEndRoom(''));
|
||||||
const results = {};
|
const results = {};
|
||||||
for (const k of roomKeys) {
|
for (const k of roomKeys) {
|
||||||
const unprefixedKey = k.substr(keyEndToEndRoom('').length);
|
const unprefixedKey = k.slice(keyEndToEndRoom('').length);
|
||||||
results[unprefixedKey] = getJsonItem(this.store, k);
|
results[unprefixedKey] = getJsonItem(this.store, k);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
@ -427,7 +427,7 @@ export function globToRegexp(glob: string, extended?: any): string {
|
|||||||
|
|
||||||
export function ensureNoTrailingSlash(url: string): string {
|
export function ensureNoTrailingSlash(url: string): string {
|
||||||
if (url && url.endsWith("/")) {
|
if (url && url.endsWith("/")) {
|
||||||
return url.substr(0, url.length - 1);
|
return url.slice(0, -1);
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user