UNPKG

@prismicio/client

Version:

The official JavaScript + TypeScript client library for Prismic

1 lines 1.32 kB
{"version":3,"file":"getRepositoryEndpoint.cjs","names":["isRepositoryName","PrismicError"],"sources":["../src/getRepositoryEndpoint.ts"],"sourcesContent":["import { PrismicError } from \"./errors\"\n\nimport { isRepositoryName } from \"./isRepositoryName\"\n\n/**\n * Get a repository's Prismic Content API endpoint.\n *\n * @example\n *\n * ```ts\n * getRepositoryEndpoint(\"my-repo\")\n * // => \"https://my-repo.cdn.prismic.io/api/v2\"\n * ```\n *\n * @typeParam RepositoryName - Name of the Prismic repository.\n *\n * @param repositoryName - Name of the repository.\n *\n * @returns The repository's Prismic Content API endpoint.\n *\n * @throws {@link Error} Thrown if an invalid repository name is provided.\n */\nexport const getRepositoryEndpoint = <RepositoryName extends string>(\n\trepositoryName: RepositoryName,\n): `https://${RepositoryName}.cdn.prismic.io/api/v2` => {\n\tif (isRepositoryName(repositoryName)) {\n\t\treturn `https://${repositoryName}.cdn.prismic.io/api/v2` as const\n\t} else {\n\t\tthrow new PrismicError(\n\t\t\t`An invalid Prismic repository name was given: ${repositoryName}`,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBACZ,mBACuD;AACvD,KAAIA,0CAAiB,eAAe,CACnC,QAAO,WAAW,eAAe;KAEjC,OAAM,IAAIC,4BACT,iDAAiD,kBACjD,QACA,OACA"}