Skip to content

Commit b628d95

Browse files
committedDec 4, 2024
Add parseAsPageIndex
1 parent 2779419 commit b628d95

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

Diff for: ‎packages/nuqs/src/parsers.ts

+11
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ export const parseAsInteger = createParser({
155155
serialize: v => Math.round(v).toFixed()
156156
})
157157

158+
export const parseAsPageIndex = createParser({
159+
parse: (v) => {
160+
const int = parseInt(v);
161+
if (Number.isNaN(int)) {
162+
return null;
163+
}
164+
return int - 1;
165+
},
166+
serialize: (v) => Math.round(v + 1).toFixed(),
167+
});
168+
158169
export const parseAsHex = createParser({
159170
parse: v => {
160171
const int = parseInt(v, 16)

0 commit comments

Comments
 (0)