UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

21 lines (20 loc) 1.05 kB
const require_errors = require("./errors.cjs"); //#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 require_errors.PrismicError(`An invalid Prismic Document API endpoint was provided: ${repositoryEndpoint}`, void 0, void 0); }; //#endregion exports.getRepositoryName = getRepositoryName; //# sourceMappingURL=getRepositoryName.cjs.map