Skip to content

Commit f64294e

Browse files
authored
Merge pull request #448 from cloudinary/feature/add-format-quality-alias
2 parents 6b7e868 + 14f010d commit f64294e

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

__TESTS__/unit/actions/Delivery.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ describe('Tests for Transformation Action -- Delivery', () => {
2222
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/f_auto/sample');
2323
});
2424

25+
it('Creates a cloudinaryURL with quality alias', () => {
26+
const url = createNewImage('sample')
27+
.quality('auto')
28+
.toURL();
29+
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/q_auto/sample');
30+
});
31+
32+
it('Creates a cloudinaryURL with format alias', () => {
33+
const url = createNewImage('sample')
34+
.format('gif')
35+
.toURL();
36+
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/f_gif/sample');
37+
});
38+
2539
it('Creates a cloudinaryURL with Format', () => {
2640
const url = createNewImage('sample')
2741
.delivery(format(Format.gif()))

__TESTS__/unit/actions/Quality.test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ import {createNewImage} from "../../TestUtils/createCloudinaryImage";
55

66

77
describe('Tests for Transformation Action -- Delivery.quality', () => {
8-
it('Ensures auto is accepted as an action to ImageTransformation', () => {
9-
const tImage = createNewImage();
10-
// Ensures it compiles and doesn't throw
11-
expect(
12-
tImage.quality(Delivery.quality('80'))
13-
).toEqual(tImage);
14-
});
15-
168
it('Creates a cloudinaryURL with quality', () => {
179
const url = createNewImage('sample')
1810
.delivery(Delivery.quality(Quality.auto()))

src/assets/CloudinaryTransformable.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {IAdjustAction} from "../actions/adjust.js";
2525
import {DeliveryQualityAction} from "../actions/delivery/DeliveryQuality.js";
2626
import {ITrackedPropertiesThroughAnalytics} from "../sdkAnalytics/interfaces/ITrackedPropertiesThroughAnalytics.js";
2727
import {AnimatedAction} from "../actions/animated.js";
28+
import {DeliveryFormat} from "../actions/delivery/DeliveryFormat.js";
2829

2930
/**
3031
* @desc Cloudinary Transformable interface, extended by any class that needs a Transformation Interface
@@ -80,12 +81,22 @@ class CloudinaryTransformable extends CloudinaryFile {
8081
}
8182

8283
/**
83-
* @desc A proxy to {@link SDK.Transformation| Transformation} - Calls the same method contained in this.transformation
84-
* @param {Actions.Delivery} quality
84+
* @desc An alias to Action Delivery.quality
85+
* @param {string|number} quality
86+
* @return {this}
87+
*/
88+
quality(quality: string|number): this {
89+
this.addAction(new DeliveryFormat('q', quality));
90+
return this;
91+
}
92+
93+
/**
94+
* @desc An alias to Action Delivery.format
95+
* @param {string} format
8596
* @return {this}
8697
*/
87-
quality(quality: DeliveryQualityAction): this {
88-
this.transformation.quality(quality);
98+
format(format: string): this {
99+
this.addAction(new DeliveryFormat('f', format));
89100
return this;
90101
}
91102

0 commit comments

Comments
 (0)