8000 feat: add todos for queryparams as a string · cloudinary/js-url-gen@0cef320 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cef320

Browse files
feat: add todos for queryparams as a string
1 parent 4eaca9e commit 0cef320

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

__TESTS__/unit/url/url.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,6 @@ describe('Tests for URL configuration', () => {
111111
const url = image.toURL({trackedAnalytics: analyticsOptions});
112112
expect(url).toEqual(`https://res.cloudinary.com/demo/image/upload/sample?_i=abcde&_a=BATAABAQ0`);
113113
});
114+
115+
// TODO: Write test(s): Should include query params as a string
114116
});

src/assets/CloudinaryFile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ class CloudinaryFile {
283283
.replace(/\?/g, '%3F')
284284
.replace(/=/g, '%3D');
285285

286+
// TODO
287+
// 1. First we have to check if `this.urlConfig.queryParams` is an object and therefore needs parsing
288+
// 2. If we got an object we have to check if URLSearchParams is available, and only then use it
289+
// Beause we want to throw a meaningful Error in case it's not - we can wrap the below code in a try catch clause
290+
// 3. If it already was a string then we can skip the parsing but still we need to assign it to `queryParamsString`
286291
const queryParams = new URLSearchParams(this.urlConfig.queryParams as Record<string, string>);
287292

288293
// urlConfig.analytics is true by default, has to be explicitly set to false to overwrite

src/config/URLConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class URLConfig extends Config implements IURLConfig {
1313
useRootPath?: boolean;
1414
secure?: boolean;
1515
forceVersion?: boolean;
16+
// TODO: We need to change the type here to accept string
1617
queryParams?: Record<string, string | number | boolean>;
1718

1819
/**
@@ -106,6 +107,7 @@ class URLConfig extends Config implements IURLConfig {
106107
/**
107108
* @param params Sets additional params
108109
*/
110+
// TODO: We need to change the type here to accept string
109111
setQueryParams(params: Record<string, string | number | boolean>):this {
110112
this.queryParams = params;
111113
return this;

src/config/interfaces/Config/IURLConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @prop {boolean} [secure]
1414
* @prop {boolean} [forceVersion]
1515
* @prop {boolean} [analytics]
16+
* // TODO: This is just for generating docs - we need to change the type here to accept string
1617
* @prop {object} [queryParams]
1718
* @example
1819
* import Cloudinary from '@cloudinary/url-gen';
@@ -98,6 +99,7 @@ interface IURLConfig {
9899
/**
99100
* Additional params to be added to the URL
100101
*/
102+
// TODO: We need to change the type here to accept string
101103
queryParams?: Record<string, string | number | boolean>
102104
}
103105

0 commit comments

Comments
 (0)
0