fetch-har
Advanced tools
Comparing version 6.0.2 to 6.1.0
@@ -0,1 +1,7 @@ | ||
## 6.1.0 (2022-01-27) | ||
* feat: automatically polyfilling FormData with formdata-node if present (#241) ([da94dfc](https://github.com/readmeio/fetch-har/commit/da94dfc)), closes [#241](https://github.com/readmeio/fetch-har/issues/241) | ||
## <small>6.0.2 (2022-01-27)</small> | ||
@@ -2,0 +8,0 @@ |
/* eslint-disable import/no-extraneous-dependencies, no-console */ | ||
require('isomorphic-fetch'); | ||
// If executing from an environment that dodoesn't normally provide `fetch()` | ||
// we'll automatically polyfill in the `Blob`, `File`, and `FormData` APIs | ||
// with the optional `formdata-node` package (provided you've installed it). | ||
const fetchHar = require('.'); | ||
// If executing from an environment that dodoesn't normally provide fetch() you'll need to polyfill some APIs in order | ||
// to make `multipart/form-data` requests. | ||
if (!globalThis.FormData) { | ||
globalThis.Blob = require('formdata-node').Blob; | ||
globalThis.File = require('formdata-node').File; | ||
globalThis.FormData = require('formdata-node').FormData; | ||
} | ||
const har = { | ||
@@ -14,0 +10,0 @@ log: { |
11
index.js
@@ -26,2 +26,13 @@ const { Readable } = require('readable-stream'); | ||
if (!globalThis.FormData) { | ||
try { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
globalThis.FormData = require('formdata-node').FormData; | ||
} catch (e) { | ||
throw new Error( | ||
'Since you do not have the FormData API available in this environment you must install the optional `formdata-node` dependency.' | ||
); | ||
} | ||
} | ||
function isBrowser() { | ||
@@ -28,0 +39,0 @@ return typeof window !== 'undefined' && typeof document !== 'undefined'; |
{ | ||
"name": "fetch-har", | ||
"version": "6.0.2", | ||
"version": "6.1.0", | ||
"description": "Make a fetch request from a HAR definition", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,13 +17,8 @@ # fetch-har | ||
require('isomorphic-fetch'); | ||
// If executing from an environment that dodoesn't normally provide `fetch()` | ||
// we'll automatically polyfill in the `Blob`, `File`, and `FormData` APIs | ||
// with the optional `formdata-node` package (provided you've installed it). | ||
const fetchHar = require('.'); | ||
// If executing from an environment that dodoesn't normally provide fetch() | ||
// you'll need to polyfill some APIs in order to make `multipart/form-data` | ||
// requests. | ||
if (!globalThis.FormData) { | ||
globalThis.Blob = require('formdata-node').Blob; | ||
globalThis.File = require('formdata-node').File; | ||
globalThis.FormData = require('formdata-node').FormData; | ||
} | ||
const har = { | ||
@@ -70,3 +65,3 @@ log: { | ||
We recommend either [formdata-node](https://npm.im/formdata-node) or [formdata-polyfill](https://npm.im/formdata-polyfill). | ||
Though we recommend either [formdata-node](https://npm.im/formdata-node) or [formdata-polyfill](https://npm.im/formdata-polyfill) we prefer [formdata-node](https://npm.im/formdata-node) right now as it's CJS-compatible. | ||
@@ -94,3 +89,3 @@ #### Options | ||
##### multipartEncoder | ||
> ❗ If you are using `fetch-har` in Node you may need this option! | ||
> ❗ If you are using `fetch-har` in Node you may need this option to execute `multipart/form-data` requests! | ||
@@ -97,0 +92,0 @@ If you are running `fetch-har` within a Node environment and you're using `node-fetch@2`, or another `fetch` polyfill that does not support a spec-compliant `FormData` API, you will need to specify an encoder that will transform your `FormData` object into something that can be used with [Request.body](https://developer.mozilla.org/en-US/docs/Web/API/Request/body). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69331
323
100