Skip to content

Commit

Permalink
Add parseAsPageIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
cenobitedk committed Dec 4, 2024
1 parent 2779419 commit b628d95
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/nuqs/src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ export const parseAsInteger = createParser({
serialize: v => Math.round(v).toFixed()
})

export const parseAsPageIndex = createParser({
parse: (v) => {
const int = parseInt(v);
if (Number.isNaN(int)) {
return null;
}
return int - 1;
},
serialize: (v) => Math.round(v + 1).toFixed(),
});

export const parseAsHex = createParser({
parse: v => {
const int = parseInt(v, 16)
Expand Down

0 comments on commit b628d95

Please sign in to comment.