UNPKG

msw

Version:

Seamless REST/GraphQL API mocking library for browser and Node.js.

1 lines 975 B
{"version":3,"sources":["../../../../src/core/utils/internal/isHandlerKind.ts"],"sourcesContent":["import type { AnyHandler } from '../../experimental/handlers-controller'\nimport type { RequestHandler } from '../../handlers/RequestHandler'\nimport type { WebSocketHandler } from '../../handlers/WebSocketHandler'\nimport { isObject } from './isObject'\n\n/**\n * A filter function that ensures that the provided argument\n * is a handler of the given kind. This helps differentiate\n * between different kinds of handlers, e.g. request and event handlers.\n */\nexport function isHandlerKind<K extends AnyHandler['kind']>(kind: K) {\n return (\n input: unknown,\n ): input is K extends 'websocket' ? WebSocketHandler : RequestHandler => {\n return isObject(input) && 'kind' in input && input.kind === kind\n }\n}\n"],"mappings":"AAGA,SAAS,gBAAgB;AAOlB,SAAS,cAA4C,MAAS;AACnE,SAAO,CACL,UACuE;AACvE,WAAO,SAAS,KAAK,KAAK,UAAU,SAAS,MAAM,SAAS;AAAA,EAC9D;AACF;","names":[]}