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

Conversation

CommanderRoot
Copy link

String.prototype.substr() is deprecated so we replace it with String.prototype.slice() or String.prototype.substring() which work similarily but aren't deprecated.
.substr() probably isn't going away anytime soon but the change is trivial so it doesn't hurt to do it.

.substr() is deprecated so we replace it with .slice() or .substring() which work similarily but aren't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
@poltak
Copy link
Member

poltak commented Mar 23, 2022

This looks good! Thanks for the contribution.
One thing I noticed was your two replacements of .substr with .substring still contain the exact same args, even though the two functions treat the second arg differently. Though, from a quick read of the surrounding code, it seems like the original author might have thought .substr works the same as .substring (or just confused them), hence that second arg doesn't need to be changed? Is that how you interpreted it?

@CommanderRoot
Copy link
Author

CommanderRoot commented Mar 23, 2022

The reason I used substring() instead of slice() in these instances is because the second parameter is normally positive but it could be negative.
Example:

"0123456789".substr(0, -1) == ""
"0123456789".substring(0, -1) == ""
"0123456789".slice(0, -1) == "012345678"

So to replicate the current behaviour I used substring().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants