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

Tokenize Regex as Parameter #268

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jongaull-nimbly
Copy link

This PR adds support for a tokenizer parameter which gives the user more control over what constitutes a "token". If the tokenizer parameter is not set then the default regex is used.

@kpdecker
Copy link
Owner

What's the use case here?

@jongaull-nimbly
Copy link
Author

The default regex is /(\s+|[()[\]{}'"]|\b)/ and the one I am using is /(\s+|[()[\]{}'"_]|\b)/.

It's been a while since I worked on this, but it looks like I wanted to add _ as a tokenizing character. I could also see a use-case here for using , for diff-ing CSV data or maybe . for diff-ing file names.

@SkySor44
Copy link

SkySor44 commented Dec 1, 2021

I second this functionality. I have a use case for diffing two html strings and this would enable me to adjust the tokenizer to meet my needs.

* `options` : An object with options. Currently, only `context` is supported and describes how many lines of context should be included.
* `options` : An object with options.
* `context` : describes how many lines of context should be included.
* `tokenizer` : Overrides the default regex used to split text into words. supported by `diffWords` and `diffWordsWithSpace`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is in the wrong place; you've documented it as a parameter of createTwoFilesPatch instead of diffWords.

@ExplodingCabbage
Copy link
Collaborator

Worth thinking about before I merge this - for Chinese and Japanese support, we might need tokenization logic too complicated to be encompassed in a regex, either built in to jsdiff or as something you can plug in yourself: #328 (comment). I want to carefully think through what I ultimately want the API to look like before merging this PR and make sure it's not gonna commit us to an API that's fundamentally incompatible with supporting Chinese and Japanese.

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

Successfully merging this pull request may close these issues.

4 participants