diff --git a/src/asLink.ts b/src/asLink.ts index 5e848de..9047ff1 100644 --- a/src/asLink.ts +++ b/src/asLink.ts @@ -2,15 +2,13 @@ import { LinkField, LinkType } from "@prismicio/types"; import { ArgumentError } from "./ArgumentError"; import { LinkResolverFunction } from "./types"; -// TODO: provide a way to handle v1 fields - /** * Resolves any type of link field to a URL * * @param linkField - Any kind of link field to resolve * @param linkResolver - A link resolver function, without it you're expected to use the `routes` from the API * - * @returns Resolved URL, an empty string if provided link is empty + * @returns Resolved URL, null if provided link is empty * * @typeParam LinkResolverFunctionReturnType - Link resolver function return type * @@ -29,8 +27,8 @@ export function asLink( } switch (linkField.link_type) { - case LinkType.Web: case LinkType.Media: + case LinkType.Web: return linkField.url; case LinkType.Document: diff --git a/src/types.ts b/src/types.ts index 8381260..c267a1b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,16 @@ -import { FilledLinkToDocumentField } from "@prismicio/types"; +import type { FilledLinkToDocumentField } from "@prismicio/types"; +/** + * Resolves a link to a Prismic document to a URL + * + * @param linkToDocumentField - A document link field to resolve + * + * @returns Resolved URL + * + * @typeParam ReturnType - Return type of your link resolver function, useful if you prefer to return a complex object + * + * @see Prismic link resolver documentation: {@link https://prismic.io/docs/technologies/link-resolver-javascript} + */ export type LinkResolverFunction = ( - doc: Omit + linkToDocumentField: Omit ) => ReturnType;