Skip to content

Commit

Permalink
fix(pagination): always return undfined when there's no link
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Feb 15, 2024
1 parent fae4d5f commit 882ffe9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import type { Link } from "./standard-schemas.ts";
const pageParamRegexp = /^page\[([a-zA-Z0-9]+)]$/;
export type PageParams = Record<string, string>;

export const parsePageParamsFromLink = (
link: Link | undefined | null,
): PageParams | undefined | null => {
export const parsePageParamsFromLink = (link: Link | undefined | null): PageParams | undefined => {
if (link === undefined || link === null) {
return link;
return undefined;
}

const url = new URL(typeof link === "string" ? link : link.href, "http://localhost");
Expand Down
4 changes: 2 additions & 2 deletions test/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { describe, expect, it } from "vitest";
import { injectPageParams, parsePageParamsFromLink } from "../src/index.js";

describe("parsePageParams", () => {
it("should return falsy link", () => {
it("should return undefined on falsy link", () => {
expect(parsePageParamsFromLink(undefined)).toBeUndefined();
expect(parsePageParamsFromLink(null)).toBeNull();
expect(parsePageParamsFromLink(null)).toBeUndefined();
});

it("should throw when not finding page params", () => {
Expand Down

0 comments on commit 882ffe9

Please sign in to comment.