Skip to content

Commit 54a0803

Browse files
authored
Merge pull request #416 from cloudinary/feature/add-shortened-notation
Feature/add shortened notation
2 parents 3914735 + d82e60b commit 54a0803

File tree

21 files changed

+261
-41
lines changed

21 files changed

+261
-41
lines changed

__TESTS__/unit/actions/Adjust.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ describe('Tests for Transformation Action -- Adjust', () => {
165165
expect(url).toContain('e_improve:outdoor:0');
166166
});
167167

168+
it('can use shortened improve notation', () => {
169+
const url = createNewImage('sample')
170+
.adjust(Adjust.improve().mode("outdoor").blend(0))
171+
.toURL();
172+
173+
expect(url).toContain('e_improve:outdoor:0');
174+
});
175+
168176
it('tests by3dLut', () => {
169177
expect(Adjust
170178
.by3dLut('sample')

__TESTS__/unit/actions/Background.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ describe('Tests for Transformation Action -- Background', () => {
7676
expect(url).toContain('image/upload/b_auto:border_gradient_contrast:2:horizontal:palette_red_green_blue,c_pad,h_250,w_250/b_auto:border_gradient,c_pad,h_250,w_250/sample');
7777
});
7878

79+
it('can use shortened GradientDirection notation', () => {
80+
const url = createNewImage('sample')
81+
.resize(Resize.pad(250, 250)
82+
.background(borderGradient()
83+
.gradientDirection("horizontal")
84+
)
85+
)
86+
.toURL();
87+
88+
expect(url).toContain('image/upload/b_auto:border_gradient:horizontal,c_pad,h_250,w_250/sample');
89+
});
90+
7991
it('Background.predominantGradient().gradientDirection().gradientColors()', () => {
8092
const url = createNewImage('sample')
8193
.resize(Resize.pad(250, 250)

__TESTS__/unit/actions/Delivery.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ describe('Tests for Transformation Action -- Delivery', () => {
247247
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/cs_no_cmyk/sample');
248248
});
249249

250+
it('Creates a cloudinaryURL with shortened ColorSpaceType', () => {
251+
const url = createNewImage('sample')
252+
.delivery(Delivery.colorSpace("no_cmyk"))
253+
.toURL();
254+
255+
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/cs_no_cmyk/sample');
256+
});
257+
250258
it('Creates a cloudinaryURL with Delivery.ColorSpaceFromICC', () => {
251259
const url = createNewImage('sample')
252260
.delivery(Delivery.colorSpaceFromICC('sample'))
@@ -284,6 +292,15 @@ describe('Tests for Transformation Action -- Delivery', () => {
284292
expect(url).toContain('f_jpg,fl_progressive:semi');
285293
});
286294

295+
it('Can use shortened progressive:semi notation', () => {
296+
// f_jpg,fl_progressive
297+
const url = createNewImage('sample').delivery(
298+
Delivery.format(Format.jpg()).progressive("semi")
299+
).toString();
300+
301+
expect(url).toContain('f_jpg,fl_progressive:semi');
302+
});
303+
287304
it('Created delivery formats with progressive:steep', () => {
288305
// f_jpg,fl_progressive
289306
const url = createNewImage('sample').delivery(

__TESTS__/unit/actions/Effect.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ describe('Tests for Transformation Action -- Effect', () => {
299299
).toBe('co_blue,e_outline:fill:10:25');
300300
});
301301

302+
it('Can use shortened Effect.outline notation', () => {
303+
expect(Effect.outline()
304+
.mode("fill")
305+
.width(10)
306+
.blurLevel(25)
307+
.color(Color.BLUE)
308+
.toString()
309+
).toBe('co_blue,e_outline:fill:10:25');
310+
});
311+
302312
it('Test simulateColorBlind', () => {
303313
expect(Effect.simulateColorBlind()
304314
.toString()
@@ -310,6 +320,13 @@ describe('Tests for Transformation Action -- Effect', () => {
310320
).toBe('e_simulate_colorblind:rod_monochromacy');
311321
});
312322

323+
it('Can shorten simulateColorBlindType notation', () => {
324+
expect(Effect.simulateColorBlind()
325+
.condition("deuteranomaly")
326+
.toString()
327+
).toBe('e_simulate_colorblind:deuteranomaly');
328+
});
329+
313330
it('Test removeBackground', () => {
314331
expect(Effect.removeBackground().toString()).toBe('e_bgremoval');
315332
expect(Effect.removeBackground().screen().toString()).toBe('e_bgremoval:screen');

__TESTS__/unit/actions/Flag.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,18 @@ describe('Tests for Transformation Action -- Flag', () => {
106106

107107
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/ar_1.0,c_fill,fl_keep_attribution,fl_keep_iptc,w_400/sample');
108108
});
109+
110+
it('Can use shortened flag notation', () => {
111+
const url = createNewImage('sample')
112+
.resize(
113+
Resize.fill(400)
114+
.aspectRatio(1.0)
115+
.addFlag("keep_iptc")
116+
.addFlag("keep_attribution")
117+
)
118+
.setPublicID('sample')
119+
.toURL();
120+
121+
expect(url).toBe('https://res.cloudinary.com/demo/image/upload/ar_1.0,c_fill,fl_keep_attribution,fl_keep_iptc,w_400/sample');
122+
});
109123
});

__TESTS__/unit/actions/Overlay.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ describe('Tests for overlay actions', () => {
4646
expect(asset.toString()).toBe('l_sample/e_screen,fl_layer_apply,g_face');
4747
});
4848

49+
it('Can use shortened BlendMode notation', () => {
50+
const asset = createNewImage();
51+
52+
asset.overlay(Overlay.source(Source.image("sample"))
53+
.position(sampleFacePosition())
54+
.blendMode("mask")
55+
);
56+
57+
expect(asset.toString()).toBe('l_sample/e_mask,fl_layer_apply,g_face');
58+
});
59+
4960
it('Tests Image on Image with Transformation', () => {
5061
const asset = createNewImage();
5162

__TESTS__/unit/actions/Rotate.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ describe('Tests for Transformation Action -- Rotate', () => {
1717

1818
expect(url).toContain('/a_vflip/a_hflip/a_auto_left/a_auto_right/a_ignore/a_40/');
1919
});
20+
21+
it('Can use shortened Rotate notation', () => {
22+
const url = createNewImage('sample')
23+
.rotate(Rotate.mode("hflip"))
24+
.rotate(Rotate.byAngle(40))
25+
.toURL();
26+
27+
expect(url).toContain('a_hflip/a_40/');
28+
});
2029
});

__TESTS__/unit/actions/Transcode.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ describe('Tests for Transformation Action -- Transcode', () => {
5757
expect(url).toBe('https://res.cloudinary.com/demo/video/upload/af_11025/sample');
5858
});
5959

60+
it('Can use shortened audioFrequency notation', () => {
61+
const url = createNewVideo('sample')
62+
.transcode(Transcode
63+
.audioFrequency(11025))
64+
.setPublicID('sample')
65+
.toURL();
66+
67+
expect(url).toBe('https://res.cloudinary.com/demo/video/upload/af_11025/sample');
68+
});
69+
6070
it('Creates a cloudinaryURL with fps', () => {
6171
const url = createNewVideo('sample')
6272
.transcode(Transcode
@@ -109,6 +119,16 @@ describe('Tests for Transformation Action -- Transcode', () => {
109119
expect(url).toBe('https://res.cloudinary.com/demo/video/upload/sp_full_hd/sample');
110120
});
111121

122+
it('Can use shortened streamingProfile notation', () => {
123+
const url = createNewVideo('sample')
124+
.transcode(Transcode
125+
.streamingProfile("full_hd"))
126+
.setPublicID('sample')
127+
.toURL();
128+
129+
expect(url).toBe('https://res.cloudinary.com/demo/video/upload/sp_full_hd/sample');
130+
});
131+
112132
it('Creates a cloudinaryURL with toAnimated', () => {
113133
const url = createNewVideo('sample')
114134
.transcode(Transcode

__TESTS__/unit/values/TextStyle/TextStyle.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ describe('Text Style tests', () => {
3737
expect(res).toBe('arial_50_bold_italic_strikethrough_justify_stroke_letter_spacing_10_line_spacing_20_antialias_good_hinting_full');
3838
});
3939

40+
it('Can use shortened text notation', () => {
41+
const res = new TextStyle('arial', 50)
42+
.fontAntialias("good")
43+
.fontWeight("bold")
44+
.fontStyle("italic")
45+
.textDecoration("strikethrough")
46+
.textAlignment("center")
47+
.toString();
48+
expect(res).toBe('arial_50_bold_italic_strikethrough_center_antialias_good');
49+
});
50+
4051
it('Create a new instance with stroke solid', () => {
4152
const res = new TextStyle('arial', 50)
4253
.stroke(Stroke.solid(2, Color.WHITE))

src/actions/delivery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {FormatQualifier} from "../qualifiers/format/FormatQualifier";
1212
import {toFloatAsString} from "../internal/utils/toFloatAsString";
1313
import {DeliveryColorSpaceFromICC} from "./delivery/DeliveryColorSpaceFromICC";
1414
import {DeliveryAction} from "./delivery/DeliveryAction";
15+
import {ColorSpaceType} from "../types/types";
1516
import {QualityTypes} from "../types/types";
1617
import {ImageFormatType, VideoFormatType} from "../types/types";
1718

@@ -90,7 +91,7 @@ function dpr(dpr: string|number):DeliveryAction {
9091
* quality('auto'),
9192
* );
9293
*/
93-
function quality(qualityType:QualityTypes|string | number) :DeliveryQualityAction {
94+
function quality(qualityType:QualityTypes | string | number) :DeliveryQualityAction {
9495
return new DeliveryQualityAction(qualityType);
9596
}
9697

@@ -155,7 +156,7 @@ function defaultImage(publicIdWithExtension:string) :DeliveryAction {
155156
* colorSpace(trueColor()),
156157
* );
157158
*/
158-
function colorSpace(mode:string): DeliveryAction {
159+
function colorSpace(mode:ColorSpaceType|string): DeliveryAction {
159160
return new DeliveryAction('cs', mode);
160161
}
161162

0 commit comments

Comments
 (0)