Skip to content

Add contains, startsWith, endsWith string query operators#1714

Merged
typicode merged 5 commits intomainfrom
copilot/add-query-operators-for-partial-matching
Feb 26, 2026
Merged

Add contains, startsWith, endsWith string query operators#1714
typicode merged 5 commits intomainfrom
copilot/add-query-operators-for-partial-matching

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

  • Add contains, startsWith, endsWith to WHERE_OPERATORS in where-operators.ts
  • Handle the new operators in matches-where.ts (case-insensitive, ignore non-string fields)
  • Add tests to parse-where.test.ts for parsing
  • Add tests to matches-where.test.ts for matching behavior (43 tests passing)
  • Update README Conditions section to document the three new operators
Original prompt

Add query operators for partial string matching using the colon syntax in typicode/json-server:

  • Support field:contains=..., field:startsWith=..., and field:endsWith=... in query params.
  • Operators are camelCase exactly as above.
  • Matching should be case-insensitive by default.
  • Ignore non-string field values (do not match on numbers, booleans, objects, arrays, etc.).

Add minimal tests covering:

  • Each operator on a string field
  • Case-insensitive behavior
  • Non-string fields are ignored (no match)

Update implementation in the existing query parsing/filtering pipeline (do not add a new syntax), and keep behavior consistent with current filtering.

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… matching

Co-authored-by: typicode <5502029+typicode@users.noreply.github.com>
Copilot AI changed the title [WIP] Add query operators for partial string matching in json-server Add contains, startsWith, endsWith string query operators Feb 26, 2026
@typicode
Copy link
Owner

@copilot update README

Co-authored-by: typicode <5502029+typicode@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 26, 2026

@copilot update README

Done in c9e2f5c. Added contains, startsWith, and endsWith to the Conditions section in the README, including descriptions and examples for each.

@typicode
Copy link
Owner

@copilot in src/matches-where.test.ts add 1 test per operator (contains, startsWith, endsWith) where the value is a number.

…ators

Co-authored-by: typicode <5502029+typicode@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 26, 2026

@copilot in src/matches-where.test.ts add 1 test per operator (contains, startsWith, endsWith) where the value is a number.

Added in f36465d — one test per operator where the search value is a number ({ c: { contains: 1 } }, { c: { startsWith: 1 } }, { c: { endsWith: 1 } }), all returning false since 'x' doesn't contain/start/end with '1'.

@typicode typicode marked this pull request as ready for review February 26, 2026 22:45
@typicode typicode merged commit 43822ad into main Feb 26, 2026
1 check passed
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