Skip to content

Commit 45d2dc3

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
skip transformation if its null or undefined
1 parent 49c8589 commit 45d2dc3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/url/builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function constructTransformationString(transformation: Transformation[] | undefi
8282
for (var i = 0, l = transformation.length; i < l; i++) {
8383
var parsedTransformStep = [];
8484
for (var key in transformation[i]) {
85+
if(transformation[i][key] === undefined || transformation[i][key] === null )
86+
continue;
8587
var transformKey = transformationUtils.getTransformKey(key);
8688
if (!transformKey) {
8789
transformKey = key;

test/url-generation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,19 @@ describe("URL generation", function () {
279279
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:di-test_path.jpg/test_path1.jpg`);
280280
});
281281

282+
it('skip transformation if it is undefined or null', function () {
283+
const url = imagekit.url({
284+
path: "/test_path1.jpg",
285+
transformation: [{
286+
defaultImage: "/test_path.jpg",
287+
quality: undefined,
288+
effectContrast: null
289+
}]
290+
})
291+
292+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:di-test_path.jpg/test_path1.jpg`);
293+
});
294+
282295
it('All combined', function () {
283296
const url = imagekit.url({
284297
path: "/test_path.jpg",

0 commit comments

Comments
 (0)