Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: add split words method #51

wants to merge 6 commits into from

Conversation

scmmishra
Copy link
Member

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']

@scmmishra scmmishra requested a review from Copilot April 27, 2025 05:46
Copy link

@Copilot Copilot AI left a 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', () => {

Copy link

github-actions bot commented Apr 27, 2025

size-limit report 📦

Path Size
dist/utils.cjs.production.min.js 7.21 KB (+2.21% 🔺)
dist/utils.esm.js 6.63 KB (+2.43% 🔺)

Comment on lines +66 to +69
// Check for mismatched quotes
if (inQuotes) {
throw new Error('Mismatched quotes in input string');
}
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

@pranavrajs pranavrajs left a 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?

@muhsin-k muhsin-k removed their request for review June 24, 2025 10:30
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

Successfully merging this pull request may close these issues.

2 participants