UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

30 lines (28 loc) 926 B
import { PrismicError } from "./errors.js"; import { isRepositoryName } from "./isRepositoryName.js"; //#region src/getRepositoryEndpoint.ts /** * Get a repository's Prismic Content API endpoint. * * @example * * ```ts * getRepositoryEndpoint("my-repo") * // => "https://my-repo.cdn.prismic.io/api/v2" * ``` * * @typeParam RepositoryName - Name of the Prismic repository. * * @param repositoryName - Name of the repository. * * @returns The repository's Prismic Content API endpoint. * * @throws {@link Error} Thrown if an invalid repository name is provided. */ const getRepositoryEndpoint = (repositoryName) => { if (isRepositoryName(repositoryName)) return `https://${repositoryName}.cdn.prismic.io/api/v2`; else throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0); }; //#endregion export { getRepositoryEndpoint }; //# sourceMappingURL=getRepositoryEndpoint.js.map