Skip to content

Commit 607521a

Browse files
committed
support for webpack 5
1 parent faece17 commit 607521a

File tree

3 files changed

+75
-130
lines changed

3 files changed

+75
-130
lines changed

src/parseQuery.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ const specialValues: LooseObject = {
1111
}
1212

1313
function parseQuery(query: string): LooseObject {
14-
if (query.substring(0, 1) !== '?') {
14+
if (query.substr(0, 1) !== '?') {
1515
throw new Error("A valid query string passed to parseQuery should begin with '?'")
1616
}
1717

18-
query = query.substring(1)
18+
query = query.substr(1)
1919

2020
if (!query) {
2121
return {}
2222
}
2323

24-
if (query.substring(0, 1) === '{' && query.substring(-1) === '}') {
24+
if (query.substr(0, 1) === '{' && query.substr(-1) === '}') {
2525
return JSON5.parse(query)
2626
}
2727

@@ -40,8 +40,8 @@ function parseQuery(query: string): LooseObject {
4040
if (specialValues.hasOwnProperty(value)) {
4141
value = specialValues[value]
4242
}
43-
if (name.substring(-2) === '[]') {
44-
name = decodeURIComponent(name.substring(0, name.length - 2))
43+
if (name.substr(-2) === '[]') {
44+
name = decodeURIComponent(name.substr(0, name.length - 2))
4545

4646
if (!Array.isArray(result[name])) {
4747
result[name] = []
@@ -53,10 +53,10 @@ function parseQuery(query: string): LooseObject {
5353
result[name] = value
5454
}
5555
} else {
56-
if (arg.substring(0, 1) === '-') {
57-
result[decodeURIComponent(arg.substring(1))] = false
58-
} else if (arg.substring(0, 1) === '+') {
59-
result[decodeURIComponent(arg.substring(1))] = true
56+
if (arg.substr(0, 1) === '-') {
57+
result[decodeURIComponent(arg.substr(1))] = false
58+
} else if (arg.substr(0, 1) === '+') {
59+
result[decodeURIComponent(arg.substr(1))] = true
6060
} else {
6161
result[decodeURIComponent(arg)] = true
6262
}

test/jimp/build/__snapshots__/test.js.snap

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@ Object {
2020
exports[`doesn't emit file 1`] = `
2121
Object {
2222
"default": Object {
23-
"height": 900,
23+
"height": 225,
2424
"images": Array [
2525
Object {
26-
"height": 450,
27-
"path": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg",
28-
"width": 500,
29-
},
30-
Object {
31-
"height": 675,
32-
"path": "foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg",
33-
"width": 750,
34-
},
35-
Object {
36-
"height": 900,
37-
"path": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
38-
"width": 1000,
26+
"height": 225,
27+
"path": "foobar/8869f9dd68c1b99a89c642f1b8ade3ad-250.jpg",
28+
"width": 250,
3929
},
4030
],
41-
"src": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
42-
"srcSet": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg 500w,foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg 750w,foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg 1000w",
31+
"src": "foobar/8869f9dd68c1b99a89c642f1b8ade3ad-250.jpg",
32+
"srcSet": "foobar/8869f9dd68c1b99a89c642f1b8ade3ad-250.jpg 250w",
4333
"toString": [Function],
44-
"width": 1000,
34+
"width": 250,
4535
},
4636
}
4737
`;
@@ -56,19 +46,14 @@ Object {
5646
"path": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg",
5747
"width": 500,
5848
},
59-
Object {
60-
"height": 675,
61-
"path": "foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg",
62-
"width": 750,
63-
},
6449
Object {
6550
"height": 900,
6651
"path": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
6752
"width": 1000,
6853
},
6954
],
7055
"src": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
71-
"srcSet": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg 500w,foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg 750w,foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg 1000w",
56+
"srcSet": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg 500w,foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg 1000w",
7257
"toString": [Function],
7358
"width": 1000,
7459
},
@@ -174,62 +159,52 @@ Object {
174159
exports[`override min and max with sizes 1`] = `
175160
Object {
176161
"default": Object {
177-
"height": 270,
162+
"height": 180,
178163
"images": Array [
179164
Object {
180165
"height": 90,
181166
"path": "foobar/32708317aa6a3e07c17ed98fc519f791-100.jpg",
182167
"width": 100,
183168
},
184169
Object {
185-
"height": 150,
186-
"path": "foobar/734736ef066c39120760fd69e8d2eaa7-167.jpg",
187-
"width": 167,
188-
},
189-
Object {
190-
"height": 211,
191-
"path": "foobar/192a0bafe1555e25e65afd6390e58a84-234.jpg",
192-
"width": 234,
193-
},
194-
Object {
195-
"height": 270,
196-
"path": "foobar/9ce71322d2da0a01ef90cfc44e592171-300.jpg",
197-
"width": 300,
170+
"height": 180,
171+
"path": "foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg",
172+
"width": 200,
198173
},
199174
],
200-
"src": "foobar/9ce71322d2da0a01ef90cfc44e592171-300.jpg",
201-
"srcSet": "foobar/32708317aa6a3e07c17ed98fc519f791-100.jpg 100w,foobar/734736ef066c39120760fd69e8d2eaa7-167.jpg 167w,foobar/192a0bafe1555e25e65afd6390e58a84-234.jpg 234w,foobar/9ce71322d2da0a01ef90cfc44e592171-300.jpg 300w",
175+
"src": "foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg",
176+
"srcSet": "foobar/32708317aa6a3e07c17ed98fc519f791-100.jpg 100w,foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg 200w",
202177
"toString": [Function],
203-
"width": 300,
178+
"width": 200,
204179
},
205180
}
206181
`;
207182

208183
exports[`parses json notation 1`] = `
209184
Object {
210185
"default": Object {
211-
"height": 900,
186+
"height": 180,
212187
"images": Array [
213188
Object {
214-
"height": 450,
215-
"path": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg",
216-
"width": 500,
189+
"height": 45,
190+
"path": "foobar/8df7f84b5cc05ee5c20f57f31376f4fb-50.jpg",
191+
"width": 50,
217192
},
218193
Object {
219-
"height": 675,
220-
"path": "foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg",
221-
"width": 750,
194+
"height": 90,
195+
"path": "foobar/32708317aa6a3e07c17ed98fc519f791-100.jpg",
196+
"width": 100,
222197
},
223198
Object {
224-
"height": 900,
225-
"path": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
226-
"width": 1000,
199+
"height": 180,
200+
"path": "foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg",
201+
"width": 200,
227202
},
228203
],
229-
"src": "foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg",
230-
"srcSet": "foobar/2756dba88775137f3a131197fee4ba11-500.jpg 500w,foobar/5b62cc7550ffe13de26a9abe0965803b-750.jpg 750w,foobar/ce1f7cab922695ef86906a04192b055d-1000.jpg 1000w",
204+
"src": "foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg",
205+
"srcSet": "foobar/8df7f84b5cc05ee5c20f57f31376f4fb-50.jpg 50w,foobar/32708317aa6a3e07c17ed98fc519f791-100.jpg 100w,foobar/d1632154d15da263ba52fe0a6de45cdd-200.jpg 200w",
231206
"toString": [Function],
232-
"width": 1000,
207+
"width": 200,
233208
},
234209
}
235210
`;

test/sharp/build/__snapshots__/test.js.snap

Lines changed: 38 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,18 @@ Object {
5151

5252
exports[`doesn't emit file 1`] = `
5353
Object {
54-
"height": 900,
54+
"height": 225,
5555
"images": Array [
5656
Object {
57-
"height": 450,
58-
"path": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg",
59-
"width": 500,
60-
},
61-
Object {
62-
"height": 675,
63-
"path": "foobar/7d2980f5976397657aae4e66161cc660-750.jpg",
64-
"width": 750,
65-
},
66-
Object {
67-
"height": 900,
68-
"path": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
69-
"width": 1000,
57+
"height": 225,
58+
"path": "foobar/96ace3b661e096e716b4a62bcc3934d2-250.jpg",
59+
"width": 250,
7060
},
7161
],
72-
"src": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
73-
"srcSet": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg 500w,foobar/7d2980f5976397657aae4e66161cc660-750.jpg 750w,foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg 1000w",
62+
"src": "foobar/96ace3b661e096e716b4a62bcc3934d2-250.jpg",
63+
"srcSet": "foobar/96ace3b661e096e716b4a62bcc3934d2-250.jpg 250w",
7464
"toString": [Function],
75-
"width": 1000,
65+
"width": 250,
7666
}
7767
`;
7868

@@ -112,19 +102,14 @@ Object {
112102
"path": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg",
113103
"width": 500,
114104
},
115-
Object {
116-
"height": 675,
117-
"path": "foobar/7d2980f5976397657aae4e66161cc660-750.jpg",
118-
"width": 750,
119-
},
120105
Object {
121106
"height": 900,
122107
"path": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
123108
"width": 1000,
124109
},
125110
],
126111
"src": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
127-
"srcSet": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg 500w,foobar/7d2980f5976397657aae4e66161cc660-750.jpg 750w,foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg 1000w",
112+
"srcSet": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg 500w,foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg 1000w",
128113
"toString": [Function],
129114
"width": 1000,
130115
}
@@ -220,60 +205,50 @@ Object {
220205

221206
exports[`override min and max with sizes 1`] = `
222207
Object {
223-
"height": 270,
208+
"height": 180,
224209
"images": Array [
225210
Object {
226211
"height": 90,
227212
"path": "foobar/0049f565d3e598f80b744f888ccaf30d-100.jpg",
228213
"width": 100,
229214
},
230215
Object {
231-
"height": 150,
232-
"path": "foobar/aa3b8300ebda3fea987abdf9d9882114-167.jpg",
233-
"width": 167,
234-
},
235-
Object {
236-
"height": 211,
237-
"path": "foobar/3f3eeb68a9bed05267734028c5aecb8b-234.jpg",
238-
"width": 234,
239-
},
240-
Object {
241-
"height": 270,
242-
"path": "foobar/7c60c8715bec52ab753a83903b738d58-300.jpg",
243-
"width": 300,
216+
"height": 180,
217+
"path": "foobar/5f2f5155b26fa7fed6fcc32f01aca2fa-200.jpg",
218+
"width": 200,
244219
},
245220
],
246-
"src": "foobar/7c60c8715bec52ab753a83903b738d58-300.jpg",
247-
"srcSet": "foobar/0049f565d3e598f80b744f888ccaf30d-100.jpg 100w,foobar/aa3b8300ebda3fea987abdf9d9882114-167.jpg 167w,foobar/3f3eeb68a9bed05267734028c5aecb8b-234.jpg 234w,foobar/7c60c8715bec52ab753a83903b738d58-300.jpg 300w",
221+
"src": "foobar/5f2f5155b26fa7fed6fcc32f01aca2fa-200.jpg",
222+
"srcSet": "foobar/0049f565d3e598f80b744f888ccaf30d-100.jpg 100w,foobar/5f2f5155b26fa7fed6fcc32f01aca2fa-200.jpg 200w",
248223
"toString": [Function],
249-
"width": 300,
224+
"width": 200,
250225
}
251226
`;
252227

253228
exports[`parses json notation 1`] = `
254229
Object {
255-
"height": 900,
230+
"height": 180,
256231
"images": Array [
257232
Object {
258-
"height": 450,
259-
"path": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg",
260-
"width": 500,
233+
"height": 45,
234+
"path": "foobar/d29e4bda309a28b94d101aeeac15e622-50.webp",
235+
"width": 50,
261236
},
262237
Object {
263-
"height": 675,
264-
"path": "foobar/7d2980f5976397657aae4e66161cc660-750.jpg",
265-
"width": 750,
238+
"height": 90,
239+
"path": "foobar/ab4bef82e752b1d075af5236c458073e-100.webp",
240+
"width": 100,
266241
},
267242
Object {
268-
"height": 900,
269-
"path": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
270-
"width": 1000,
243+
"height": 180,
244+
"path": "foobar/004bbcf97542aa5c1e2434233b53ac16-200.webp",
245+
"width": 200,
271246
},
272247
],
273-
"src": "foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg",
274-
"srcSet": "foobar/78a57c37d73de1a0df2e5e84a7c3a493-500.jpg 500w,foobar/7d2980f5976397657aae4e66161cc660-750.jpg 750w,foobar/03fe31cc7d34b5317390ef55eaf9bc12-1000.jpg 1000w",
248+
"src": "foobar/004bbcf97542aa5c1e2434233b53ac16-200.webp",
249+
"srcSet": "foobar/d29e4bda309a28b94d101aeeac15e622-50.webp 50w,foobar/ab4bef82e752b1d075af5236c458073e-100.webp 100w,foobar/004bbcf97542aa5c1e2434233b53ac16-200.webp 200w",
275250
"toString": [Function],
276-
"width": 1000,
251+
"width": 200,
277252
}
278253
`;
279254

@@ -406,28 +381,23 @@ Object {
406381

407382
exports[`progressive image 1`] = `
408383
Object {
409-
"height": 900,
384+
"height": 864,
410385
"images": Array [
411386
Object {
412-
"height": 450,
413-
"path": "foobar/9e9c5875ebfbb1857cfdb4bad0034153-500.jpg",
414-
"width": 500,
415-
},
416-
Object {
417-
"height": 675,
418-
"path": "foobar/89ff9c2e034e9b961b13f28f8dfe0507-750.jpg",
419-
"width": 750,
387+
"height": 684,
388+
"path": "foobar/a366eedb0a0ae21632438e6d488e8365-760.jpg",
389+
"width": 760,
420390
},
421391
Object {
422-
"height": 900,
423-
"path": "foobar/263472fca3eb3f5a70962e754ea03ee6-1000.jpg",
424-
"width": 1000,
392+
"height": 864,
393+
"path": "foobar/481f41d88cf3a0a41fd3f6a076222c68-960.jpg",
394+
"width": 960,
425395
},
426396
],
427-
"src": "foobar/263472fca3eb3f5a70962e754ea03ee6-1000.jpg",
428-
"srcSet": "foobar/9e9c5875ebfbb1857cfdb4bad0034153-500.jpg 500w,foobar/89ff9c2e034e9b961b13f28f8dfe0507-750.jpg 750w,foobar/263472fca3eb3f5a70962e754ea03ee6-1000.jpg 1000w",
397+
"src": "foobar/481f41d88cf3a0a41fd3f6a076222c68-960.jpg",
398+
"srcSet": "foobar/a366eedb0a0ae21632438e6d488e8365-760.jpg 760w,foobar/481f41d88cf3a0a41fd3f6a076222c68-960.jpg 960w",
429399
"toString": [Function],
430-
"width": 1000,
400+
"width": 960,
431401
}
432402
`;
433403

0 commit comments

Comments
 (0)