Skip to content

Commit 56813fc

Browse files
committed
fix: improve getQueryObject to exclude empty arrays from output (#49)
- Replace double negation (`!!`) with explicit length checks for better readability - Add explicit deletion of empty include and sort arrays from query object - Use consistent double quotes for string literals - Prevents empty arrays from appearing in generated query parameters This ensures cleaner query strings by excluding empty include/sort parameters instead of including them as empty strings.
1 parent a28124b commit 56813fc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,19 @@ export class DrupalJsonApiParams implements DrupalJsonApiParamsInterface {
380380
*/
381381
public getQueryObject(): ParamBag<any> {
382382
const foo: ParamBag<any> = JSON.parse(JSON.stringify(this.data));
383-
if (!!this.data.include.length) {
384-
foo.include = this.data.include.join(',');
383+
384+
if (this.data.include.length > 0) {
385+
foo.include = this.data.include.join(",");
386+
} else {
387+
delete foo.include;
385388
}
386-
if (!!this.data.sort.length) {
387-
foo.sort = this.data.sort.join(',');
389+
390+
if (this.data.sort.length > 0) {
391+
foo.sort = this.data.sort.join(",");
392+
} else {
393+
delete foo.sort;
388394
}
395+
389396
return foo;
390397
}
391398

0 commit comments

Comments
 (0)