mirror of
https://github.com/graphql-hive/console
synced 2026-05-24 09:38:26 +00:00
13 lines
456 B
TypeScript
13 lines
456 B
TypeScript
/**
|
|
* Verify whether a string is a legit GitHub repository string.
|
|
* Example: `foo/bar`
|
|
*/
|
|
export function isGitHubRepositoryString(repository: string): repository is `${string}/${string}` {
|
|
const [owner, name] = repository.split('/');
|
|
return !!owner && isLegitGitHubName(owner) && !!name && isLegitGitHubName(name);
|
|
}
|
|
|
|
/** @source https://stackoverflow.com/a/59082561 */
|
|
function isLegitGitHubName(str: string) {
|
|
return /^[\w-.]+$/i.test(str);
|
|
}
|