Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c35fc16

Browse files
Replace deprecated String#substr with String#slice (#8314)
1 parent 0e68c16 commit c35fc16

File tree

17 files changed

+37
-37
lines changed

17 files changed

+37
-37
lines changed

src/Avatar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function isValidHexColor(color: string): boolean {
5757
return typeof color === "string" &&
5858
(color.length === 7 || color.length === 9) &&
5959
color.charAt(0) === "#" &&
60-
!color.substr(1).split("").some(c => isNaN(parseInt(c, 16)));
60+
!color.slice(1).split("").some(c => isNaN(parseInt(c, 16)));
6161
}
6262

6363
function urlForColor(color: string): string {

src/autocomplete/CommandProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class CommandProvider extends AutocompleteProvider {
5555
// check if the full match differs from the first word (i.e. returns false if the command has args)
5656
if (command[0] !== command[1]) {
5757
// The input looks like a command with arguments, perform exact match
58-
const name = command[1].substr(1); // strip leading `/`
58+
const name = command[1].slice(1); // strip leading `/`
5959
if (CommandMap.has(name) && CommandMap.get(name).isEnabled()) {
6060
// some commands, namely `me` don't suit having the usage shown whilst typing their arguments
6161
if (CommandMap.get(name).hideCompletionAfterSpace) return [];

src/components/views/dialogs/CreateRoomDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
103103
createOpts.preset = Preset.PublicChat;
104104
opts.guestAccess = false;
105105
const { alias } = this.state;
106-
createOpts.room_alias_name = alias.substr(1, alias.indexOf(":") - 1);
106+
createOpts.room_alias_name = alias.substring(1, alias.indexOf(":"));
107107
} else {
108108
// If we cannot change encryption we pass `true` for safety, the server should automatically do this for us.
109109
opts.encryption = this.state.canChangeEncryption ? this.state.isEncrypted : true;

src/components/views/elements/EffectsOverlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const EffectsOverlay: FunctionComponent<IProps> = ({ roomWidth }) => {
5555
const onAction = (payload: { action: string }) => {
5656
const actionPrefix = 'effects.';
5757
if (payload.action.indexOf(actionPrefix) === 0) {
58-
const effect = payload.action.substr(actionPrefix.length);
58+
const effect = payload.action.slice(actionPrefix.length);
5959
lazyLoadEffectModule(effect).then((module) => module?.start(canvasRef.current));
6060
}
6161
};

src/components/views/rooms/BasicMessageComposer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
364364
private insertText(textToInsert: string, inputType = "insertText"): void {
365365
const sel = document.getSelection();
366366
const { caret, text } = getCaretOffsetAndText(this.editorRef.current, sel);
367-
const newText = text.substr(0, caret.offset) + textToInsert + text.substr(caret.offset);
367+
const newText = text.slice(0, caret.offset) + textToInsert + text.slice(caret.offset);
368368
caret.offset += textToInsert.length;
369369
this.modifiedFlag = true;
370370
this.props.model.update(newText, inputType, caret);

src/components/views/rooms/MemberList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export default class MemberList extends React.Component<IProps, IState> {
274274

275275
this.sortNames.set(
276276
member,
277-
(member.name[0] === '@' ? member.name.substr(1) : member.name).replace(SORT_REGEX, ""),
277+
(member.name[0] === '@' ? member.name.slice(1) : member.name).replace(SORT_REGEX, ""),
278278
);
279279

280280
// XXX: this user may have no lastPresenceTs value!

src/components/views/spaces/SpaceCreateMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const createSpace = async (
5656
events_default: 100,
5757
invite: isPublic ? 0 : 50,
5858
},
59-
room_alias_name: isPublic && alias ? alias.substr(1, alias.indexOf(":") - 1) : undefined,
59+
room_alias_name: isPublic && alias ? alias.substring(1, alias.indexOf(":")) : undefined,
6060
topic,
6161
...createOpts,
6262
},

src/editor/deserialize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function parseCodeBlock(n: Node, pc: PartCreator): Part[] {
9797
if (n.firstChild?.nodeName === "CODE") {
9898
for (const className of (n.firstChild as HTMLElement).classList) {
9999
if (className.startsWith("language-") && !className.startsWith("language-_")) {
100-
language = className.substr("language-".length);
100+
language = className.slice("language-".length);
101101
break;
102102
}
103103
}
@@ -118,7 +118,7 @@ function parseCodeBlock(n: Node, pc: PartCreator): Part[] {
118118
}
119119

120120
function parseHeader(n: Node, pc: PartCreator): Part[] {
121-
const depth = parseInt(n.nodeName.substr(1), 10);
121+
const depth = parseInt(n.nodeName.slice(1), 10);
122122
const prefix = pc.plain("#".repeat(depth) + " ");
123123
return [prefix, ...parseChildren(n, pc)];
124124
}

src/editor/diff.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ function firstDiff(a: string, b: string): number {
3333

3434
function diffStringsAtEnd(oldStr: string, newStr: string): IDiff {
3535
const len = Math.min(oldStr.length, newStr.length);
36-
const startInCommon = oldStr.substr(0, len) === newStr.substr(0, len);
36+
const startInCommon = oldStr.slice(0, len) === newStr.slice(0, len);
3737
if (startInCommon && oldStr.length > newStr.length) {
38-
return { removed: oldStr.substr(len), at: len };
38+
return { removed: oldStr.slice(len), at: len };
3939
} else if (startInCommon && oldStr.length < newStr.length) {
40-
return { added: newStr.substr(len), at: len };
40+
return { added: newStr.slice(len), at: len };
4141
} else {
4242
const commonStartLen = firstDiff(oldStr, newStr);
4343
return {
44-
removed: oldStr.substr(commonStartLen),
45-
added: newStr.substr(commonStartLen),
44+
removed: oldStr.slice(commonStartLen),
45+
added: newStr.slice(commonStartLen),
4646
at: commonStartLen,
4747
};
4848
}
@@ -55,7 +55,7 @@ export function diffDeletion(oldStr: string, newStr: string): IDiff {
5555
}
5656
const firstDiffIdx = firstDiff(oldStr, newStr);
5757
const amount = oldStr.length - newStr.length;
58-
return { at: firstDiffIdx, removed: oldStr.substr(firstDiffIdx, amount) };
58+
return { at: firstDiffIdx, removed: oldStr.slice(firstDiffIdx, firstDiffIdx + amount) };
5959
}
6060

6161
/**
@@ -70,7 +70,7 @@ export function diffDeletion(oldStr: string, newStr: string): IDiff {
7070
export function diffAtCaret(oldValue: string, newValue: string, caretPosition: number): IDiff {
7171
const diffLen = newValue.length - oldValue.length;
7272
const caretPositionBeforeInput = caretPosition - diffLen;
73-
const oldValueBeforeCaret = oldValue.substr(0, caretPositionBeforeInput);
74-
const newValueBeforeCaret = newValue.substr(0, caretPosition);
73+
const oldValueBeforeCaret = oldValue.substring(0, caretPositionBeforeInput);
74+
const newValueBeforeCaret = newValue.substring(0, caretPosition);
7575
return diffStringsAtEnd(oldValueBeforeCaret, newValueBeforeCaret);
7676
}

src/editor/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export function toggleInlineFormat(range: Range, prefix: string, suffix = prefix
281281
if (isFormatted) {
282282
// remove prefix and suffix formatting string
283283
const partWithoutPrefix = parts[base].serialize();
284-
partWithoutPrefix.text = partWithoutPrefix.text.substr(prefix.length);
284+
partWithoutPrefix.text = partWithoutPrefix.text.slice(prefix.length);
285285
parts[base] = partCreator.deserializePart(partWithoutPrefix);
286286

287287
const partWithoutSuffix = parts[index - 1].serialize();

0 commit comments

Comments
 (0)