From bb1b5f41fc40f82435e0880b5acb899d6352f748 Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Tue, 22 Mar 2022 20:25:44 +0100 Subject: [PATCH] refactor: replace deprecated String.prototype.substr() .substr() is deprecated so we replace it with .slice() or .substring() which work similarily but aren't deprecated Signed-off-by: Tobias Speicher --- .../background/procedures/restore/index.ts | 2 +- src/common-ui/components/TextInputControlled.tsx | 10 +++++----- src/common-ui/containers/IndexDropdown.tsx | 2 +- src/common-ui/utils.ts | 2 +- src/highlighting/ui/anchoring/anchoring/pdf.js | 3 +-- src/notifications/container.tsx | 2 +- src/page-analysis/extract-page-content.test.ts | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/backup-restore/background/procedures/restore/index.ts b/src/backup-restore/background/procedures/restore/index.ts index 280c69057e..28f1dd0824 100644 --- a/src/backup-restore/background/procedures/restore/index.ts +++ b/src/backup-restore/background/procedures/restore/index.ts @@ -359,7 +359,7 @@ export class BackupRestoreProcedure { _blobFromPngString(s: string) { const prefix = 'data:' - if (s.substr(0, prefix.length) !== prefix) { + if (s.slice(0, prefix.length) !== prefix) { s = 'data:image/png;base64,' + s } return decodeBlob(s, { diff --git a/src/common-ui/components/TextInputControlled.tsx b/src/common-ui/components/TextInputControlled.tsx index 0adf05bac8..7af2ce5980 100644 --- a/src/common-ui/components/TextInputControlled.tsx +++ b/src/common-ui/components/TextInputControlled.tsx @@ -520,7 +520,7 @@ export class SelectionModifiers { static _lastWhitespace(current: SelectionState, cursorToMove: string) { const lastWhitespaces: RegExpMatchArray = matchAll( - current.text.substr(0, current.selection[cursorToMove] - 1), + current.text.substring(0, current.selection[cursorToMove] - 1), /(\s)/gm, ) const lastWhitespaceArray = [...lastWhitespaces] @@ -532,7 +532,7 @@ export class SelectionModifiers { static _nextWhitespace(current: SelectionState, cursorToMove: string) { const nextWhitespaces = matchAll( - current.text.substr(current.selection[cursorToMove] + 1), + current.text.slice(current.selection[cursorToMove] + 1), /(\s)/gm, ) const nextWhitespaceArray = [...nextWhitespaces] as RegExpMatchArray @@ -617,7 +617,7 @@ export class SelectionModifiers { static _distanceFromNewLine(current: SelectionState): number { // find either a newline or the start if no prev newline const lastNewline = current.text - .substr(0, current.selection.end) + .slice(0, current.selection.end) .lastIndexOf('\n') return lastNewline === -1 ? current.selection.end @@ -627,14 +627,14 @@ export class SelectionModifiers { static _indexOfPreviousLine(current: SelectionState): number { // find either a newline or the start if no prev newline let previousNewLine = current.text - .substr(0, current.selection.end) + .slice(0, current.selection.end) .lastIndexOf('\n') if (previousNewLine === -1) { return 0 } else { // If we're on a newline boundary, actually find the one before previousNewLine = current.text - .substr(0, previousNewLine) + .slice(0, previousNewLine) .lastIndexOf('\n') } diff --git a/src/common-ui/containers/IndexDropdown.tsx b/src/common-ui/containers/IndexDropdown.tsx index a232935547..216cabc14e 100644 --- a/src/common-ui/containers/IndexDropdown.tsx +++ b/src/common-ui/containers/IndexDropdown.tsx @@ -209,7 +209,7 @@ class IndexDropdownContainer extends Component { const { hover, source } = this.props // Make first letter capital - const sourceType = source.charAt(0).toUpperCase() + source.substr(1) + const sourceType = source.charAt(0).toUpperCase() + source.slice(1) // Only for add and remove from the popup or overview, we have already covered filter in overview if (this.allowIndexUpdate) { diff --git a/src/common-ui/utils.ts b/src/common-ui/utils.ts index cac5fcb33a..6a5c7dba3a 100644 --- a/src/common-ui/utils.ts +++ b/src/common-ui/utils.ts @@ -47,7 +47,7 @@ export function uninsertTab({ el, tabStr = ' ' }: InsertTabProps) { export function insertIndentedNewLine({ el }: InsertTabProps) { const { value, selectionStart, selectionEnd } = el - let lineNo = value.substr(0, selectionStart).split(/\r?\n|\r/).length + let lineNo = value.slice(0, selectionStart).split(/\r?\n|\r/).length let lineText = el.value.split(/\r?\n|\r/)[lineNo - 1] let indentationCount = 0 let indentationString = '' diff --git a/src/highlighting/ui/anchoring/anchoring/pdf.js b/src/highlighting/ui/anchoring/anchoring/pdf.js index c8044fcbd0..56f023e152 100644 --- a/src/highlighting/ui/anchoring/anchoring/pdf.js +++ b/src/highlighting/ui/anchoring/anchoring/pdf.js @@ -450,9 +450,8 @@ export function anchor(root, selectors) { ({ index, offset, textContent }) => { const start = position.start - offset const end = position.end - offset - const length = end - start - checkQuote(textContent.substr(start, length)) + checkQuote(textContent.slice(start, end)) return anchorByPosition(index, start, end) }, diff --git a/src/notifications/container.tsx b/src/notifications/container.tsx index 47a689c8ca..11bd63505c 100644 --- a/src/notifications/container.tsx +++ b/src/notifications/container.tsx @@ -68,7 +68,7 @@ class NotificationContainer extends Component { ' ', this.props.messageCharLimit, ) - const trunctatedText = message.substr(0, lastSpaceBeforeCutoff) + '...' + const trunctatedText = message.substring(0, lastSpaceBeforeCutoff) + '...' return trunctatedText } diff --git a/src/page-analysis/extract-page-content.test.ts b/src/page-analysis/extract-page-content.test.ts index 5a4b9cc5d4..f00673b3e4 100644 --- a/src/page-analysis/extract-page-content.test.ts +++ b/src/page-analysis/extract-page-content.test.ts @@ -9,7 +9,7 @@ import extractPageMetadataFromRawContent, { describe('Extract page content', () => { // beforeAll(() => { // browser.extension = { - // getURL: rel => path.resolve('extension/lib', rel.substr(1)), + // getURL: rel => path.resolve('extension/lib', rel.slice(1)), // } // })