Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace deprecated String.prototype.substr() #1237

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backup-restore/background/procedures/restore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
10 changes: 5 additions & 5 deletions src/common-ui/components/TextInputControlled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')
}

Expand Down
2 changes: 1 addition & 1 deletion src/common-ui/containers/IndexDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class IndexDropdownContainer extends Component<Props, State> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/common-ui/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
3 changes: 1 addition & 2 deletions src/highlighting/ui/anchoring/anchoring/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NotificationContainer extends Component<Props> {
' ',
this.props.messageCharLimit,
)
const trunctatedText = message.substr(0, lastSpaceBeforeCutoff) + '...'
const trunctatedText = message.substring(0, lastSpaceBeforeCutoff) + '...'
return trunctatedText
}

Expand Down
2 changes: 1 addition & 1 deletion src/page-analysis/extract-page-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
// }
// })

Expand Down