mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-02 19:13:25 +09:00
refactor: improve types in the frontend, misc fixes (#39142)
This commit is contained in:
+9
-5
@@ -21,7 +21,7 @@ export function extname(path: string): string {
|
||||
}
|
||||
|
||||
/** test whether a variable is an object */
|
||||
export function isObject<T = Record<string, any>>(obj: any): obj is T {
|
||||
export function isObject(obj: unknown): obj is Record<string, unknown> {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||
}
|
||||
|
||||
@@ -49,17 +49,21 @@ export function stripTags(text: string): string {
|
||||
return text;
|
||||
}
|
||||
|
||||
export function parseIssueHref(href: string): IssuePathInfo {
|
||||
export function parseIssueHref(href: string): IssuePathInfo | null {
|
||||
// FIXME: it should use pathname and trim the appSubUrl ahead
|
||||
const path = (href || '').replace(/[#?].*$/, '');
|
||||
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || [];
|
||||
const match = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path);
|
||||
if (!match) return null;
|
||||
const [, ownerName, repoName, pathType, indexString] = match;
|
||||
return {ownerName, repoName, pathType, indexString};
|
||||
}
|
||||
|
||||
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo {
|
||||
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo | null {
|
||||
const appSubUrl = window.config.appSubUrl;
|
||||
if (appSubUrl && pathname.startsWith(appSubUrl)) pathname = pathname.substring(appSubUrl.length);
|
||||
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(pathname) || [];
|
||||
const match = /([^/]+)\/([^/]+)/.exec(pathname);
|
||||
if (!match) return null;
|
||||
const [, ownerName, repoName] = match;
|
||||
return {ownerName, repoName};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user