Skip to content

Commit 78e1a09

Browse files
author
utkace
committed
helpers: add url generator helper
1 parent a2c6a55 commit 78e1a09

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/helpers/urlGenerators.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import ImageKit from 'imagekit-javascript';
2+
3+
export const generateUrl = ({publicKey, urlEndpoint, src, path, transformation}) => {
4+
5+
if(!publicKey) {
6+
throw new Error("Missing publicKey during initialization");
7+
}
8+
9+
if(!urlEndpoint) {
10+
throw new Error("Missing urlEndpoint during initialization");
11+
}
12+
13+
const ik = new ImageKit({
14+
publicKey: publicKey,
15+
urlEndpoint: urlEndpoint,
16+
});
17+
18+
if(path){
19+
return ik.url({path: path, transformation: transformation});
20+
} else {
21+
return ik.url({src: src, transformation: transformation});
22+
}
23+
}

0 commit comments

Comments
 (0)