Adds global default properties to the web fetch API, allowing developers to set default headers, methods, and lifecycle hooks (beforeSend, dataFilter, fail) without wrapping every fetch call. Stable version 1.0.18 with infrequent updates. Differentiates from similar utilities by offering beforeSend and dataFilter interceptors, and by extending the global fetch object rather than requiring a proxy or wrapper.
npm install fetch-defaultNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to import fetch-default, set global defaults via fetch.default(), and make a fetch call with per-request overrides.
Call fetch.default() once at application startup, not inside components or request handlers.
Use regular function expressions for hooks: `beforeSend() { ... }` instead of `beforeSend: () => { ... }`.In dataFilter, return the transformed value synchronously or return a promise (e.g., `response.json()`). The fetch promise will resolve with that value.
Be aware that using fetch.default() makes your code reliant on this specific package. If you switch to another fetch enhancer, remove fetch.default() calls.
Add `import 'fetch-default'` or `require('fetch-default')` at the top of your entry file.Ensure dataFilter returns a valid value (or throws) and that fail(e) is defined to handle exceptions.
Do not use arrow functions in beforeSend; use `function()` syntax so `this` points to the request options.
No dependency data recorded yet.