-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add split words method #51
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR implements a new splitWords method to enhance string splitting behavior, especially for CSV-like inputs with quoted phrases.
- Adds the splitWords function with CSV parsing like behavior in src/string.ts
- Updates tests in test/string.test.ts to validate multiple input scenarios
- Updates the module export in src/index.ts to include splitWords
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
test/string.test.ts | Adds tests for various splitWords input cases |
src/string.ts | Implements the CSV-like splitWords function |
src/index.ts | Updates exports to include splitWords |
Comments suppressed due to low confidence (1)
test/string.test.ts:41
- [nitpick] Additional test cases for trailing commas and consecutive delimiters would help ensure that splitWords consistently handles all CSV edge cases.
describe('#splitWords', () => {
size-limit report 📦
|
// Check for mismatched quotes | ||
if (inQuotes) { | ||
throw new Error('Mismatched quotes in input string'); | ||
} |
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.
Do we need to handle this? A query with a single quote should be valid right?
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.
It made sense to do this, although it makes the "
an invalid search candidate, I think it still works.
Since there's not visual feedback on the frontend about how the values were sent, if we allow mismatched quote, we will have to break the sentence through some fallback method which will introduce ambiguity.
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.
@pranavrajs let me know what you think here, we can proceed with merging this
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.
Minor comments. We also need a join words method as well, right?
This PR adds a split words method that goes beyond the naive splitting using
string.split(',')
to a approach more akin to CSV parsing, that allows quoted blocks to be treated as their own candidate.So
"apple, mango", orange
will be split as['apple, mango', 'orange']