-
Notifications
You must be signed in to change notification settings - Fork 10
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
Collapse multiple leading and trailing whitespaces into a single whitespace / Does not collapse multiple #16
Conversation
…itespace - Does not collapse multiple into a single whitespace
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.
whooops, forgot to press the "Submit Review" button 🤦♂️
sorry for the long silence!!
utils/helpers.js
Outdated
}; | ||
|
||
const hasLeadingOrTrailingWhiteSpace = function(chars) { | ||
chars = encodeURIComponent(chars); |
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.
why are you encoding the characters here?
utils/helpers.js
Outdated
module.exports = { | ||
stripWhiteSpace, | ||
isWhitespaceTextNode, | ||
WHITESPACE, |
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.
why do we export this? looks unused 🤔
utils/helpers.js
Outdated
chars = encodeURIComponent(chars || ''); | ||
chars = chars.replace(matchHorizontalTABAndNewLineBegin, ' ') | ||
.replace(matchHorizontalTABAndNewLineEnd, ' '); | ||
return decodeURIComponent(chars); |
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.
I've built a similar thing lately for qunit-dom
mostly according to the HTML spec. Might make sense to reuse the same implementation here too. (see https://github.com/simplabs/qunit-dom/blob/master/lib/helpers/collapse-whitespace.js)
I have made the changes suggested. Please have a look at it. |
utils/helpers.js
Outdated
return chars.replace(leadingWhiteSpace, ' ').replace(trailingWhiteSpace, ' '); | ||
}; | ||
|
||
const stripNoMinifyBlocks = function(nodes) { |
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.
why did you not use the normal function syntax here? (e.g. function stripNoMinifyBlocks(nodes) { ... }
instead of the const stripNoMinifyBlocks = function(nodes) { ... }
)
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.
No specific reason, since stripNoMinifyBlocks
is never going to change. I have used const
. Shall I use the normal syntax here?
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.
yeah, I think that would be best, thanks
values(\n,\t, ,\r)
bf775d7
to
5989383
Compare
Please let me know if anything else needs to be changed. |
thanks :) |
This PR collapses multiple leading and trailing whitespaces into a single whitespace as mentioned below.
Actual content:
Minified content: