# @mocat/interceptor

> Interceptor for Mocat

Latest version **0.3.0** (published 2022-01-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mocat/interceptor
pnpm add @mocat/interceptor
yarn add @mocat/interceptor
bun add @mocat/interceptor
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-01-01 |
| First published | 2020-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 66.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 29 |
| Maintainers | lawvs |

## Links

- npm: https://www.npmjs.com/package/@mocat/interceptor
- Repository: https://github.com/lawvs/mocat
- Homepage: https://github.com/lawvs/mocat#readme
- Issues: https://github.com/lawvs/mocat/issues
- npm.io page: https://npm.io/package/@mocat/interceptor

## Dependencies (3)

- [xhr-mock](https://npm.io/package/xhr-mock.md) ^2.5.1
- [fetch-mock](https://npm.io/package/fetch-mock.md) ^9.10.4
- [eventemitter2](https://npm.io/package/eventemitter2.md) ^6.4.3

## Recent versions

- 0.3.0 (latest) — 2022-01-01
- 0.2.5 — 2021-11-28
- 0.2.4 — 2020-12-07
- 0.2.3 — 2020-12-01
- 0.2.2 — 2020-11-26
- 0.2.1 — 2020-11-18
- 0.2.0 — 2020-11-11

## README

# Mocat Interceptor

## Intro

The part of Mocat which is used to interceptor http request.

## Usage

Install dependencies:

```sh
yarn add --dev @mocat/interceptor
```

Then

```ts
import { eventEmitter, setupFetch, setupXHR } from '@mocat/interceptor'

// proxy http request
const resetFetch = setupFetch()
const resetXHR = setupXHR()

eventEmitter.onAny((event, value) => console.log(event, value))

// reset
resetFetch()
resetXHR()
```

## Credits

The implementation of this module is power by the following prior art in the JavaScript ecosystem:

- [xhr-mock](https://github.com/jameslnewell/xhr-mock)
- [fetch-mock](https://github.com/wheresrhys/fetch-mock)

## Caveats

- `@mocat/interceptor` will replaces `window.fetch` and `window.XMLHttpRequest` with a proxy that Mocat can spy on and stub.

---
_Source: https://npm.io/package/@mocat/interceptor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
