Registry / testing / fetch-addons

fetch-addons

JSON →
library1.3.0jsnpmunverified

A TypeScript-first collection of utility addons for the Fetch API, including helpers to serialize a Request to a cURL command (toCurl), create Request or Headers objects from init parameters (getRequest, getHeaders), and remove empty headers (deleteEmptyHeaders). Version 1.3.0 is stable, requires Node >= 16, and ships TypeScript declarations. Unlike manual fetch wrappers, fetch-addons focuses on debugging and transforming fetch inputs/outputs without patching global fetch.

npm install fetch-addons
INSTALL
IMPORT
SIG · FETCH-ADDONS
F
fetch-addons
testingjavascriptv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toCurl
✓ import { toCurl } from 'fetch-addons'
✗ import toCurl from 'fetch-addons'
Named export, not default. Works with ESM and CJS via bundler.
getRequest
✓ import { getRequest } from 'fetch-addons'
✗ const { getRequest } = require('fetch-addons')
CommonJS require is possible in Node but ESM is preferred. TypeScript types included.
getHeaders
✓ import { getHeaders } from 'fetch-addons'
✗ import { getHeaders } from 'fetch-addons/getHeaders'
All exports are from the package root; no subpath exports.
deleteEmptyHeaders
✓ import { deleteEmptyHeaders } from 'fetch-addons'
Works on Headers objects, not plain objects.
*
✓ import * as addons from 'fetch-addons'
Namespace import for all exports. Recommended for non-tree-shaking environments.

Demonstrates the four main exports: creating a Request from fetch arguments, manipulating headers, and converting to cURL command.

import { toCurl, getRequest, getHeaders, deleteEmptyHeaders } from 'fetch-addons'; // Convert fetch arguments to a Request object const url = 'https://api.example.com/data'; const init = { method: 'POST', headers: { 'content-type': 'application/json', 'x-api-key': process.env.API_KEY ?? '' }, body: JSON.stringify({ foo: 'bar' }) }; const request = getRequest(url, init); console.log(request.method); // 'POST' // Remove headers with empty values const headers = getHeaders(init.headers); deleteEmptyHeaders(headers); console.log(headers.get('x-api-key')); // '' (if env not set) // Serialize to cURL for debugging const curl = toCurl(request); console.log(curl); // curl --url 'https://api.example.com/data' --request 'POST' --header 'content-type: application/json' --data '{"foo":"bar"}'
Debug
Known issues
gotchatoCurl does not redact sensitive headers like Authorization; the cURL output may leak credentials in logs.
fix
Manually strip or mask sensitive headers before calling toCurl, or use a wrapper.
affects: >=1.0.0 <=1.3.0
gotchadeleteEmptyHeaders only mutates the passed Headers object; it does not return a new Headers instance nor affect the original Request/Response.
fix
Pass the Headers object directly and be aware of mutation.
affects: >=1.0.0
gotchagetRequest expects (input, init) signature matching fetch; passing a single Request object is also supported but may cause confusion.
fix
If passing a single Request, omit the second argument or pass undefined.
affects: >=1.0.0
gotchaPackage has no runtime dependencies, but requires Node 16+ due to global fetch availability or a fetch polyfill.
fix
Use Node 16+ or provide a global fetch polyfill (e.g., undici, node-fetch).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'fetch-addons' or its corresponding type declarations.
Package not installed or incorrect import path.
fix
Run 'npm install fetch-addons' and ensure import uses the package name exactly: 'import { toCurl } from 'fetch-addons'.
TypeError: deleteEmptyHeaders is not a function
Using default import instead of named import.
fix
Change 'import deleteEmptyHeaders from 'fetch-addons'' to 'import { deleteEmptyHeaders } from 'fetch-addons'.
toCurl does not convert multipart/form-data bodies correctly.
toCurl only serializes string bodies; FormData is not supported.
fix
Convert FormData to a string or use a different tool for multipart requests.
getHeaders(init.headers) is undefined when init.headers is not provided.
getHeaders does not handle undefined or null headersInit gracefully.
fix
Provide a default empty Headers: 'getHeaders(init.headers ?? {})'.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
typescriptoptionalDev dependency for type checking; package ships types
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-addons — npm install fetch-addons · libregistry