<commit_before>/* eslint-disable no-use-before-define, Allows alphabetical order */
/* eslint-disable unicorn/prefer-starts-ends-with, The tested var might not be a string */

import {check as isReserved} from 'github-reserved-names';

// Drops leading and trailing slash to avoid /\/?/ everywhere
export const getCleanPathname = () => location.pathname.replace(/^[/]|[/]$/g, '');

// Parses a repo's subpage, e.g.
// '/user/repo/issues/' -> 'issues'
// '/user/repo/' -> ''
// returns false if the path is not a repo
export const getRepoPath = () => {
	if (!isRepo()) {
		return false;
	}
	const match = /^[^/]+[/][^/]+[/]?(.*)$/.exec(getCleanPathname());
	return match && match[1];
};

export const getRepoURL = () => location.pathname.slice(1).split('/', 2).join('/');

export const getOwnerAndRepo = () => {
	const [, ownerName, repoName] = location.pathname.split('/');
	return {ownerName, repoName};
};

export const is404 = () => document.title.startsWith('Page not found');

export const isBlame = () => /^blame\//.test(getRepoPath());

export const isCommit = () => isSingleCommit() || isPRCommit();

export const isCommitList = () => /^commits\//.test(getRepoPath());

export const isCompare = () => /^compare/.test(getRepoPath());

export const isDashboard = () => /^((orgs[/][^/]+[/])?dashboard([/]index[/]\d+)?)?$/.test(getCleanPathname());

export const isEnterprise = () => location.hostname !== 'github.com' && location.hostname !== 'gist.github.com';
<commit_msg>Fix account switcher on Discover page (#859)<commit_after>/* eslint-disable no-use-before-define, Allows alphabetical order */
/* eslint-disable unicorn/prefer-starts-ends-with, The tested var might not be a string */

import {check as isReserved} from 'github-reserved-names';

// Drops leading and trailing slash to avoid /\/?/ everywhere
export const getCleanPathname = () => location.pathname.replace(/^[/]|[/]$/g, '');

// Parses a repo's subpage, e.g.
// '/user/repo/issues/' -> 'issues'
// '/user/repo/' -> ''
// returns false if the path is not a repo
export const getRepoPath = () => {
	if (!isRepo()) {
		return false;
	}
	const match = /^[^/]+[/][^/]+[/]?(.*)$/.exec(getCleanPathname());
	return match && match[1];
};

export const getRepoURL = () => location.pathname.slice(1).split('/', 2).join('/');

export const getOwnerAndRepo = () => {
	const [, ownerName, repoName] = location.pathname.split('/');
	return {ownerName, repoName};
};

export const is404 = () => document.title.startsWith('Page not found');

export const isBlame = () => /^blame\//.test(getRepoPath());

export const isCommit = () => isSingleCommit() || isPRCommit();

export const isCommitList = () => /^commits\//.test(getRepoPath());

export const isCompare = () => /^compare/.test(getRepoPath());

export const isDashboard = () => /^$|^(orgs[/][^/]+[/])?dashboard([/]|$)/.test(getCleanPathname());

export const isEnterprise = () => location.hostname !== 'github.com' && location.hostname !== 'gist.github.com';

{'fraction_non_alphanumeric': 0.2196104768300873, 'fraction_numerical': 0.005036937541974479, 'mean_word_length': 4.1808695652173915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2457871', 'n_tokens_mistral': 1006, 'n_tokens_neox': 994, 'n_words': 232}