Skip to content

Commit 430fa0d

Browse files
author
devgioele
authored
Merge pull request #17 from aboutbits/null-value
Null as query value
2 parents e2b3112 + 39c3a9f commit 430fa0d

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/engine/query.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type AbstractQueryValueElement =
88
| boolean
99
| Date
1010
| bigint
11+
| null
1112

1213
export type AbstractQuery = Record<
1314
string,
@@ -54,7 +55,7 @@ export type AbstractQueryOptions = {
5455
/**
5556
* How the abstract query is converted to an actual query.
5657
*
57-
* @default Each value that is not undefined is converted to a string by calling `.toString()`.
58+
* @default Each value that is not undefined and is converted to a string. `null` is converted to an empty string, while other values are converted calling `String(value)`.
5859
*/
5960
convertToQuery: (abstractQuery: Partial<AbstractQuery>) => Query
6061
}
@@ -64,7 +65,7 @@ const DEFAULT_ABSTRACT_QUERY_OPTIONS: AbstractQueryOptions = {
6465
const query: Query = {}
6566
for (const [key, value] of Object.entries(abstractQuery)) {
6667
if (value !== undefined) {
67-
query[key] = value.toString()
68+
query[key] = value === null ? '' : String(value)
6869
}
6970
}
7071
return query

src/routers/__test__/nextRouter.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { expectTypeOf, vi } from 'vitest'
55
import { useQuery, useQueryAndPagination } from '../../zod/routers/nextRouter'
66
import { usePagination } from '../nextRouter'
77

8-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
9-
vi.mock('next/router', () => require('next-router-mock'))
8+
vi.mock('next/router', async () => await import('next-router-mock'))
109

1110
describe('NextRouter', () => {
1211
beforeEach(() => {

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@aboutbits/ts-config/react",
33
"compilerOptions": {
4+
"module": "es2020",
45
"moduleResolution": "node",
56
"skipLibCheck": true
67
},

0 commit comments

Comments
 (0)