Skip to content

Commit af96727

Browse files
committed
fix: throw error if URL is provided but fetch is not available
1 parent 8bca3b7 commit af96727

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

PDFMergerBase.js

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export default class PDFMergerBase {
162162

163163
// see https://developer.mozilla.org/en-US/docs/Web/API/URL
164164
if (input instanceof URL) {
165+
if (typeof fetch === 'undefined') {
166+
throw new Error('fetch is not defined. You need to use a polyfill for this to work in Node.js.')
167+
}
165168
const res = await fetch(input)
166169
const aBuffer = await res.arrayBuffer()
167170
return new Uint8Array(aBuffer)

test/PDFMerger.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ describe('PDFMerger', () => {
121121
expect(diff).toBeFalsy()
122122
})
123123

124-
test('provide input as URL', async () => {
124+
const testIfFetch = typeof fetch !== 'undefined' ? test : test.skip
125+
testIfFetch('provide input as URL', async () => {
125126
const merger = new PDFMerger()
126127
const TestfileAURL = new URL('https://raw.githubusercontent.com/nbesli/pdf-merger-js/master/test/fixtures/Testfile_A.pdf')
127128
expect(TestfileAURL).toBeInstanceOf(URL)

0 commit comments

Comments
 (0)