Skip to content

Commit cc9a0b5

Browse files
Copilotfregante
andcommitted
Add isGistFile function to detect single gist URLs
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent a88244b commit cc9a0b5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,16 @@ TEST: addTests('isGistRevision', [
661661
'https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions',
662662
]);
663663

664+
export const isGistFile = (url: URL | HTMLAnchorElement | Location = location): boolean => {
665+
const pathname = getCleanGistPathname(url);
666+
return pathname?.replace(/[^/]/g, '').length === 1;
667+
};
668+
669+
TEST: addTests('isGistFile', [
670+
'https://gist.github.com/fregante/2205329b71218fa2c1d3',
671+
'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064',
672+
]);
673+
664674
export const isTrending = (url: URL | HTMLAnchorElement | Location = location): boolean => url.pathname === '/trending' || url.pathname.startsWith('/trending/');
665675
TEST: addTests('isTrending', [
666676
'https://github.com/trending',

0 commit comments

Comments
 (0)