mswjs/msw ? reverse-engineered prompt

Reverse engineered prompt

Build me a TypeScript library for mocking API requests in JavaScript, kind of like Mock Service Worker.

I want it to let me define request handlers in one place and reuse them in the browser and in Node for tests and local development. In the browser it should intercept network calls through a service worker so my app code does not need to know anything is mocked, and the mocked requests should still show up in DevTools. In Node it should intercept requests without stubbing fetch or axios directly, so the same handlers can power tests there too.

Please make it support common request matching like exact routes, path params, wildcards, and regex, and let handlers return mocked JSON, custom status codes, headers, cookies, and delays. If you need current docs or best practices, look them up online. Keep the API simple and pleasant to use, with good TypeScript types and a small example app or tests showing how to start the worker or server and define a few mocks.

Are you gonna build this?

make sure you review the code using coderabbit

Try freeSponsored — opens CodeRabbit in a new tab