Type Alias Match

Source
Expand description

Determines whether a rule matches an incoming request.

A string does a case-insensitive substring match on the last user message. A RegExp gets tested against the last user message. A MatchObject checks multiple fields at once with AND logic. A function receives the normalised request and returns a boolean.

example
server.when("hello").reply("Hi!");
server.when(/explain (\w+)/i).reply("Here's an explanation.");
server.when({ model: /claude/, format: "anthropic" }).reply("Bonjour!");
server.when((req) => req.messages.length > 5).reply("Long conversation!");
type Match = string | RegExp | MatchObject | ((req: MockRequest) => boolean)