-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Replace substr with substring #7188
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of these things (is not like the others)
@@ -111,7 +111,7 @@ function getFullMatchOffset( | |||
): number { | |||
let triggerOffset = offset; | |||
for (let i = triggerOffset; i <= entryText.length; i++) { | |||
if (documentText.substr(-i) === entryText.substr(0, i)) { | |||
if (documentText.substring(-i) === entryText.substring(0, i)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not equivalent, substr(startIndex, length)
and substring(startIndex, endIndex)
don't work the same for substr(-i)
and substring(-i)
. Probably should be something like documentText.substring(documentText.length - i)
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Will fix this evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just occurred to me that there's also the slice method, documentText.slice(-i)
is shorter and does the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'slice' shout out is a good one. updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, could've been slice all around to save a few bytes, but this works just the same!
Should probably reuse the utils method in all other plugins in playground and should probably save more bytes, if minifaction doesn't pick those up already behind the scenes |
substr is deprecated, replacing with the current equivalent to silence the linters