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

Shave Only Delimits by a Space. #411

Open
CJames95 opened this issue Jun 3, 2024 · 4 comments
Open

Shave Only Delimits by a Space. #411

CJames95 opened this issue Jun 3, 2024 · 4 comments

Comments

@CJames95
Copy link

CJames95 commented Jun 3, 2024

What Is the issue?

When shave interacts with a string of text, it delimits the text by spaces which means that if a different character such as a newline is the only character separating two words, it does not create two tokens. Instead it creates a single token with the newline character between the words.

This means that it may shave a word from the end of a line if the word after the newline character would be shaved but the word before the newline character would otherwise fit.

Provide issue context below using code examples, images, or links

const example = 'I am a cow.\nHear me moo!'

Currently shave would group cow.\nHear as a single token when it would make more sense to have it split the tokens as cow. and Hear. This is especially a problem for a textarea where new lines are possible and the user may not realize that their input would be shaved in a way that is likely not expected.

Edit: To be more clear, the issue is when I am a cow. would be the final line before shave removed the rest of the string. The string currently is tokenized like this ['I', 'am', 'a', 'cow.\nHear', 'me' 'moo!']. Since the final word on the line should be cow. it doesn't actually appear because Hear would be truncated therefore cow.\nHear is all truncated causing the sentence to appear as I am a... on the final line.


Read about references issues here. Provide paragraph text responses to each header.

@CJames95
Copy link
Author

CJames95 commented Jun 3, 2024

I added this functionality by turning your package into a helper file in my project. I went ahead and made a pull request on #412 that has my changes. I may have not copied all the changes since I had to do more for my project, but I'd be happy to revise or fix what I missed if I did.

@yowainwright
Copy link
Owner

Can you provide a code sandbox of some sort to the issue you have?
I have some concerns with this feature request but want to ensure I'm understanding you fully!
~Thanks!

@CJames95
Copy link
Author

CJames95 commented Jun 4, 2024

Yeah, I should be able to recreate an example of what I was dealing with in code sandbox. It might take a day or two unfortunately, but I'll post a link to it when I have it up for you to see.

@CJames95
Copy link
Author

CJames95 commented Jun 5, 2024

Sorry for the wait. I have the code sandbox environment mostly working. Code sandbox has some weird quirks I'm unfamiliar with with how it renders the DOM versus what I have experienced in my project's environment, but hopefully this is more clear versus my original description.

I also updated my original description with a better explanation hopefully. I also realize in retrospect that the way I handled adding the delimiters into the array wouldn't be supported by IE since it uses positive lookbehinds and lookaheads, so if IE support is something that shave wants to maintain, then a different method would have to be done to capture delimiters for reconstructing the string afterwards.

Code Sandbox link

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

No branches or pull requests

2 participants