Skip to content

Commit 990cf29

Browse files
committed
update test cases
1 parent 09c47d2 commit 990cf29

File tree

5 files changed

+320
-422
lines changed

5 files changed

+320
-422
lines changed

src/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,7 @@ class ImageKit {
4545
* A static method to generate URL for the given transformation parameters. This method is useful when you want to generate URL without creating an instance of the SDK.
4646
*/
4747
static url(urlOptions: UrlOptions & Required<Pick<ImageKitOptions, "urlEndpoint">> & Pick<ImageKitOptions, "transformationPosition">): string {
48-
const options = urlOptions;
49-
if (!options.urlEndpoint || options.urlEndpoint.length === 0) {
50-
throw {
51-
message: "urlEndpoint is required",
52-
}
53-
}
54-
if (!options.src || options.src.length === 0) {
55-
throw {
56-
message: "src is required",
57-
}
58-
}
59-
return buildURL(options);
48+
return buildURL(urlOptions);
6049
}
6150

6251
/**

src/url/builder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ function pathJoin(parts: string[], sep?: string) {
2626
}
2727

2828
export const buildURL = (opts: UrlOptions & Required<Pick<ImageKitOptions, "urlEndpoint">> & Pick<ImageKitOptions, "transformationPosition">) => {
29+
opts.urlEndpoint = opts.urlEndpoint || "";
30+
opts.src = opts.src || "";
31+
2932
if (!opts.src) {
3033
return "";
3134
}
3235

33-
const isRelativePath = opts.src && opts.src.startsWith("/");
36+
const isAbsoluteURL = opts.src.startsWith("http://") || opts.src.startsWith("https://");
3437

3538
var urlObj, isSrcParameterUsedForURL, urlEndpointPattern;
3639

3740
try {
38-
if (isRelativePath) {
41+
if (!isAbsoluteURL) {
3942
urlEndpointPattern = new URL(opts.urlEndpoint).pathname;
4043
urlObj = new URL(pathJoin([opts.urlEndpoint.replace(urlEndpointPattern, ""), opts.src]));
4144
} else {

0 commit comments

Comments
 (0)