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

chore: replace deprecated String.prototype.substr() #280

Merged
merged 1 commit into from
Mar 25, 2022
Merged

chore: replace deprecated String.prototype.substr() #280

merged 1 commit into from
Mar 25, 2022

Conversation

CommanderRoot
Copy link
Contributor

String.prototype.substr() is deprecated so we replace it with String.prototype.slice() or String.prototype.substring() (if the second parameter could be negative) which works 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 aren't deprecated
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
const wildcardDirPath = wildcardRequire.substr(0, dirIndex);
const patternPath = wildcardRequire.substr(dirIndex);
const wildcardDirPath = wildcardRequire.substring(0, dirIndex);
const patternPath = wildcardRequire.slice(dirIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some substring and others slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intend was to copy the behaviour of the current substr()

slice() and substring() behave differently if the second parameter is negative.
Examples

"test".slice(0, -1) == "tes"
"test".substring(0, -1) == ""
"test".substr(0, -1) == ""

Sometimes you want to remove the last x chars in which case slice() is what you want but if the second parameter can be positive or negative it's better to use substring* (if the first param is 0, if not it can depend as well)

@codecov
Copy link

codecov bot commented Mar 19, 2022

Codecov Report

Merging #280 (471640e) into main (435005a) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 471640e differs from pull request most recent head 0fcf4ee. Consider uploading reports for the commit 0fcf4ee to get more accurate results

@@           Coverage Diff           @@
##             main     #280   +/-   ##
=======================================
  Coverage   80.65%   80.65%           
=======================================
  Files          13       13           
  Lines        1463     1463           
  Branches      544      544           
=======================================
  Hits         1180     1180           
  Misses        116      116           
  Partials      167      167           
Impacted Files Coverage Δ
src/analyze.ts 86.58% <100.00%> (ø)
src/node-file-trace.ts 86.69% <100.00%> (ø)
src/resolve-dependency.ts 69.81% <100.00%> (ø)
src/utils/get-package-base.ts 73.33% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@styfle styfle merged commit cb5f3f9 into vercel:main Mar 25, 2022
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