Skip to content

Commit 9bfef5b

Browse files
Feature/add strict checks for typescript (#257)
1 parent 27d5c00 commit 9bfef5b

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
"module": "commonjs",
44
"noImplicitAny": true,
55
"esModuleInterop": true,
6+
"strictNullChecks": true,
7+
"strictFunctionTypes": true,
8+
"strictPropertyInitialization": true,
9+
"noImplicitThis": true,
10+
"alwaysStrict": true,
11+
"noImplicitReturns" : true,
12+
"noUnusedLocals" : true,
13+
"noUnusedParameters": true,
614
"allowSyntheticDefaultImports": true,
715
"typeRoots": ["./types"]
816
}

types/cloudinary-core-tests.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55

66
import {
7-
Cloudinary, Util, Configuration, Transformation, ImageTag, PictureTag, VideoTag, Condition, Layer, TextLayer, HtmlTag,
7+
Cloudinary, Util, Configuration, Transformation, ImageTag, VideoTag, Layer, TextLayer, HtmlTag,
88
ClientHintsMetaTag, Param
99
} from './cloudinary-core';
1010

11-
import cloudinary from './cloudinary-core';
1211

1312
let config: Configuration.Options = { cloud_name: 'demo' };
1413

@@ -26,11 +25,9 @@ cld.injectTransparentVideoElement(document.createElement('div'), 'woman', {
2625
seeThruURL: 'https://...'
2726
}).then((resp) => {
2827
if (resp instanceof HTMLElement) {
29-
let container = resp; // the container we provided
3028
}
3129
}).catch((resp) => {
3230
if (typeof resp.status === 'string') {
33-
let {status, message} = resp;
3431
}
3532
});
3633

@@ -74,13 +71,13 @@ cld.url('sample', {
7471
}) // http://res.cloudinary.com/demo/image/upload/if_w_lt_200,c_fill,h_120,w_80/if_w_gt_400,c_fit,h_150,w_150/e_sepia/sample
7572

7673
const publicId = 'imagePublicId';
77-
let image: HTMLImageElement = cld.image(publicId); // image.src == http://res.cloudinary.com/demo/image/upload/${publicId}
74+
cld.image(publicId); // image.src == http://res.cloudinary.com/demo/image/upload/${publicId}
7875

7976

80-
let video: string = cld.video(publicId); // video == <video poster="http://res.cloudinary.com/demo/video/upload/${publicId}.jpg"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.webm" type="video/webm"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.mp4" type="video/mp4"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.ogv" type="video/ogg"></video>
77+
cld.video(publicId); // video == <video poster="http://res.cloudinary.com/demo/video/upload/${publicId}.jpg"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.webm" type="video/webm"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.mp4" type="video/mp4"><source src="http://res.cloudinary.com/demo/video/upload/${publicId}.ogv" type="video/ogg"></video>
8178

8279

83-
const videoTag: VideoTag = cld.videoTag(publicId); // videoTag.getOption('source_types')) == ['webm', 'mp4', 'ogv']
80+
cld.videoTag(publicId); // videoTag.getOption('source_types')) == ['webm', 'mp4', 'ogv']
8481

8582

8683
cld.transformation_string({
@@ -118,12 +115,12 @@ transformation.serialize();
118115
transformation.toHtmlAttributes();
119116

120117

121-
let url: string = cld.url('sample', cld.transformation().if().width('gt', 100).and().width('lt', 200).then().width(50).crop('scale').endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end/sample
118+
// let url: string = cld.url('sample', cld.transformation().if().width('gt', 100).and().width('lt', 200).then().width(50).crop('scale').endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end/sample
122119

123120

124-
url = cld.url('sample', cld.transformation().if().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end/sample
121+
cld.url('sample', cld.transformation().if().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end/sample
125122

126-
url = cld.url('sample', cld.transformation().if().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").else().width(100).crop("crop").endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_else/c_crop,w_100/if_end/sample
123+
cld.url('sample', cld.transformation().if().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").else().width(100).crop("crop").endIf()); // http://res.cloudinary.com/demo/image/upload/if_w_gt_100_and_w_lt_200/c_scale,w_50/if_else/c_crop,w_100/if_end/sample
127124

128125

129126
transformation = cld.transformation().if("w > 1000 and aspectRatio < 3:4")
@@ -132,21 +129,21 @@ transformation = cld.transformation().if("w > 1000 and aspectRatio < 3:4")
132129
.else()
133130
.width(500)
134131
.crop("scale");
135-
url = cld.url('sample', transformation); // http://res.cloudinary.com/demo/image/upload/if_w_gt_1000_and_ar_lt_3:4,c_scale,w_1000/if_else,c_scale,w_500/sample
132+
cld.url('sample', transformation); // http://res.cloudinary.com/demo/image/upload/if_w_gt_1000_and_ar_lt_3:4,c_scale,w_1000/if_else,c_scale,w_500/sample
136133

137134

138-
image = cld.facebook_profile_image('officialchucknorrispage',
135+
cld.facebook_profile_image('officialchucknorrispage',
139136
{
140137
secure: true,
141138
responsive: true,
142139
effect: ['art', 'hokusai']
143140
}); // image.src == https://res.cloudinary.com/demo/image/facebook/e_art:hokusai/officialchucknorrispage && image.getAttribute('data-src-cache') == expectedImageUrl
144141

145142

146-
let tag = ImageTag.new("publicId");
143+
ImageTag.new("publicId");
147144

148145

149-
let videoHtml = cld.videoTag("movie").setSourceTypes('mp4')
146+
cld.videoTag("movie").setSourceTypes('mp4')
150147
.transformation()
151148
.htmlHeight("100")
152149
.htmlWidth("200")

types/cloudinary-core.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class Util {
8282
static detectIntersection(element: Element, onIntersect: Function): void
8383

8484
static getAnalyticsOptions(options: AnalyticsOptionsParameters) : AnalyticsOptions;
85-
static getSDKAnalyticsSignature(options: AnalyticsOptions):string;;
85+
static getSDKAnalyticsSignature(options: AnalyticsOptions):string;
8686
}
8787

8888

@@ -314,7 +314,7 @@ export class Condition {
314314
export namespace Transformation {
315315
export interface Options extends Configuration.Options {
316316
angle?: Angle; // degrees or mode
317-
aspectRatio?: string | number | string; // ratio or percent, e.g. 1.5 or 16:9
317+
aspectRatio?: string | number; // ratio or percent, e.g. 1.5 or 16:9
318318
background?: string; // color, e.g. "blue" or "rgb:9090ff"
319319
border?: string; // style, e.g. "6px_solid_rgb:00390b60"
320320
color?: string; // e.g. "red" or "rgb:20a020"
@@ -338,7 +338,7 @@ export namespace Transformation {
338338
"else"?: string;
339339
endIf?: string;
340340
opacity?: number | string; // percent, 0-100
341-
overlay?: string | string; // Identifier, e.g. "text:Arial_50:Smile!", or public id of a different resource
341+
overlay?: string; // Identifier, e.g. "text:Arial_50:Smile!", or public id of a different resource
342342
page?: number | string; // Given a multi-page file (PDF, animated GIF, TIFF), generate an image of a single page using the given index.
343343
prefix?: string;
344344
quality?: string | number; // percent or percent[:chroma_subsampling] or auto[:quality_level]
@@ -850,8 +850,9 @@ export class Cloudinary {
850850

851851
interface TransparentVideoOptions extends Transformation.Options {
852852
externalLibraries?: {
853-
seeThru?: string,
854853
[future:string]:string
854+
} & {
855+
seeThru?: string,
855856
}
856857
loop?: boolean,
857858
autoplay?: true,
@@ -896,14 +897,14 @@ export namespace Configuration {
896897
api_secret?: string;
897898
cdn_subdomain?: boolean;
898899
cloud_name?: string;
899-
cname?: string;
900+
cname?: string | null;
900901
private_cdn?: boolean;
901902
protocol?: string;
902903
resource_type?: string;
903904
responsive?: boolean;
904905
responsive_width?: string;
905906
secure_cdn_subdomain?: boolean;
906-
secure_distribution?: string;
907+
secure_distribution?: string | null;
907908
shorten?: string;
908909
type?: string;
909910
url_suffix?: string;

0 commit comments

Comments
 (0)