Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/utils/functions.js
/** | /** | ||||
* Copyright (C) 2018-2019 The Software Heritage developers | * Copyright (C) 2018-2020 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
// utility functions | // utility functions | ||||
export function handleFetchError(response) { | export function handleFetchError(response) { | ||||
Show All 23 Lines | return fetch(url, { | ||||
headers: headers, | headers: headers, | ||||
method: 'POST', | method: 'POST', | ||||
body: body | body: body | ||||
}); | }); | ||||
} | } | ||||
export function isGitRepoUrl(url, domain) { | export function isGitRepoUrl(url, domain) { | ||||
let endOfPattern = '\\/[\\w\\.-]+\\/?(?!=.git)(?:\\.git(?:\\/?|\\#[\\w\\.\\-_]+)?)?$'; | let endOfPattern = '\\/[\\w\\.-]+\\/?(?!=.git)(?:\\.git(?:\\/?|\\#[\\w\\.\\-_]+)?)?$'; | ||||
let pattern = `(?:git|https?|git@)(?:\\:\\/\\/)?${domain}[/|:][A-Za-z0-9-]+?` + endOfPattern; | let pattern = `(?:git|https?|git@)(?:\\:\\/\\/)?${domain}[/|:][A-Za-z0-9-/]+?` + endOfPattern; | ||||
let re = new RegExp(pattern); | let re = new RegExp(pattern); | ||||
return re.test(url); | return re.test(url); | ||||
}; | }; | ||||
export function removeUrlFragment() { | export function removeUrlFragment() { | ||||
history.replaceState('', document.title, window.location.pathname + window.location.search); | history.replaceState('', document.title, window.location.pathname + window.location.search); | ||||
} | } | ||||
Show All 25 Lines |