UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

25 lines (23 loc) 1.02 kB
import { PrismicError } from "./errors.js"; //#region src/getRepositoryName.ts /** * Get a Prismic repository's name from its standard Prismic Document API or * GraphQL endpoint. * * @param repositoryEndpoint - Prismic Document API endpoint for the repository. * * @returns The Prismic repository's name. * * @throws {@link Error} Thrown if an invalid Prismic Document API endpoint is * provided. */ const getRepositoryName = (repositoryEndpoint) => { try { const hostname = new URL(repositoryEndpoint).hostname; if (hostname.endsWith("prismic.io") || hostname.endsWith("wroom.io") || hostname.endsWith("dev-tools-wroom.com") || hostname.endsWith("marketing-tools-wroom.com") || hostname.endsWith("platform-wroom.com") || hostname.endsWith("wroom.test")) return hostname.split(".")[0]; } catch {} throw new PrismicError(`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`, void 0, void 0); }; //#endregion export { getRepositoryName }; //# sourceMappingURL=getRepositoryName.js.map