@lorenzopant/tmdb 0.0.19 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/images/images.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { ImagesConfig } from "../types";
|
|
1
2
|
import { BackdropSize, LogoSize, PosterSize, ProfileSize, StillSize } from "../types/images";
|
|
2
3
|
export declare class ImageAPI {
|
|
3
|
-
private
|
|
4
|
-
constructor(
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options?: ImagesConfig);
|
|
5
6
|
private buildUrl;
|
|
6
7
|
backdrop(path: string, size?: BackdropSize): string;
|
|
7
8
|
logo(path: string, size?: LogoSize): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/images/images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyC,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpI,qBAAa,QAAQ;IACpB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/images/images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAyC,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpI,qBAAa,QAAQ;IACpB,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,GAAE,YAAiB;IAItC,OAAO,CAAC,QAAQ;IAKT,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAoE,GAAG,MAAM;IAI1G,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,QAA4D,GAAG,MAAM;IAI9F,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,UAAgE,GAAG,MAAM;IAIpG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAkE,GAAG,MAAM;IAIvG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,SAA6D,GAAG,MAAM;CAGvG"}
|
package/dist/images/images.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL } from "../types/images";
|
|
2
2
|
export class ImageAPI {
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
3
|
+
options;
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.options = { secure_images_url: true, ...options };
|
|
6
6
|
}
|
|
7
7
|
buildUrl(path, size) {
|
|
8
|
-
const baseUrl = this.
|
|
8
|
+
const baseUrl = this.options.secure_images_url ? IMAGE_SECURE_BASE_URL : IMAGE_BASE_URL;
|
|
9
9
|
return `${baseUrl}${size}${path}`;
|
|
10
10
|
}
|
|
11
|
-
backdrop(path, size = "w780") {
|
|
11
|
+
backdrop(path, size = this.options.default_image_sizes?.backdrops || "w780") {
|
|
12
12
|
return this.buildUrl(path, size);
|
|
13
13
|
}
|
|
14
|
-
logo(path, size = "w185") {
|
|
14
|
+
logo(path, size = this.options.default_image_sizes?.logos || "w185") {
|
|
15
15
|
return this.buildUrl(path, size);
|
|
16
16
|
}
|
|
17
|
-
poster(path, size = "w500") {
|
|
17
|
+
poster(path, size = this.options.default_image_sizes?.posters || "w500") {
|
|
18
18
|
return this.buildUrl(path, size);
|
|
19
19
|
}
|
|
20
|
-
profile(path, size = "w185") {
|
|
20
|
+
profile(path, size = this.options.default_image_sizes?.profiles || "w185") {
|
|
21
21
|
return this.buildUrl(path, size);
|
|
22
22
|
}
|
|
23
|
-
still(path, size = "w300") {
|
|
23
|
+
still(path, size = this.options.default_image_sizes?.still || "w300") {
|
|
24
24
|
return this.buildUrl(path, size);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -11,10 +11,15 @@ describe("ImageAPI", () => {
|
|
|
11
11
|
});
|
|
12
12
|
test("should generate non-secure poster URL when configured", () => {
|
|
13
13
|
const poster_path = "/1E5baAaEse26fej7uHcjOgEE2t2.jpg"; // Fast X
|
|
14
|
-
const imageAPI = new ImageAPI(false);
|
|
14
|
+
const imageAPI = new ImageAPI({ secure_images_url: false });
|
|
15
15
|
const url = imageAPI.poster(poster_path);
|
|
16
16
|
expect(url).toBe(`${IMAGE_BASE_URL}w500${poster_path}`);
|
|
17
17
|
});
|
|
18
|
+
test("should use default image sizes if defined", () => {
|
|
19
|
+
const imageAPI = new ImageAPI({ default_image_sizes: { posters: "original" } });
|
|
20
|
+
const url = imageAPI.poster(path);
|
|
21
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}original${path}`);
|
|
22
|
+
});
|
|
18
23
|
test("should generate backdrop URL", () => {
|
|
19
24
|
const imageAPI = new ImageAPI();
|
|
20
25
|
const url = imageAPI.backdrop(path, "w1280");
|
package/dist/tmdb.js
CHANGED
|
@@ -26,6 +26,6 @@ export class TMDB {
|
|
|
26
26
|
this.movies = new MoviesAPI(this.client, this.options);
|
|
27
27
|
this.movie_lists = new MovieListsAPI(this.client, this.options);
|
|
28
28
|
this.search = new SearchAPI(this.client, this.options);
|
|
29
|
-
this.images = new ImageAPI(this.options.
|
|
29
|
+
this.images = new ImageAPI(this.options.images);
|
|
30
30
|
}
|
|
31
31
|
}
|
package/dist/types/utility.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CountryISO3166_1 } from "./countries";
|
|
2
|
+
import { BackdropSize, LogoSize, PosterSize, ProfileSize, StillSize } from "./images";
|
|
2
3
|
import { LanguageISO6391 } from "./lang";
|
|
3
4
|
export type TMDBOptions = {
|
|
4
5
|
/**
|
|
@@ -13,11 +14,28 @@ export type TMDBOptions = {
|
|
|
13
14
|
* If not set, TMDB may fall back to a default or global data.
|
|
14
15
|
*/
|
|
15
16
|
region?: CountryISO3166_1;
|
|
17
|
+
/**
|
|
18
|
+
* Provide images default configuration
|
|
19
|
+
*/
|
|
20
|
+
images?: ImagesConfig;
|
|
21
|
+
};
|
|
22
|
+
export type ImagesConfig = {
|
|
16
23
|
/**
|
|
17
24
|
* Whether to use the secure (HTTPS) image base URL.
|
|
18
25
|
* Defaults to true. Set to false only if working in an environment where HTTPS is not supported
|
|
19
26
|
* or where you explicitly need non-secure image URLs.
|
|
20
27
|
*/
|
|
21
28
|
secure_images_url?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Provide default image size configuration for each type of images.
|
|
31
|
+
*/
|
|
32
|
+
default_image_sizes?: Partial<DefaultImageSizesConfig>;
|
|
33
|
+
};
|
|
34
|
+
export type DefaultImageSizesConfig = {
|
|
35
|
+
posters?: PosterSize;
|
|
36
|
+
backdrops?: BackdropSize;
|
|
37
|
+
logos?: LogoSize;
|
|
38
|
+
profiles?: ProfileSize;
|
|
39
|
+
still?: StillSize;
|
|
22
40
|
};
|
|
23
41
|
//# sourceMappingURL=utility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC"}
|
package/package.json
CHANGED