Continued work on the send dialog

This commit is contained in:
Philipp Heckel 2022-03-29 15:22:26 -04:00
parent b6426f0417
commit 3e121f5d3c
7 changed files with 212 additions and 98 deletions

View file

@ -22,10 +22,28 @@ export const shortUrl = (url) => url.replaceAll(/https?:\/\//g, "");
export const expandUrl = (url) => [`https://${url}`, `http://${url}`];
export const expandSecureUrl = (url) => `https://${url}`;
export const splitTopicUrl = (url) => {
if (!validTopicUrl(url)) {
throw new Error("Invalid topic URL");
}
const parts = url.split("/");
if (parts.length < 2) {
throw new Error("Invalid topic URL");
}
return {
baseUrl: parts.slice(0, parts.length-1).join("/"),
topic: parts[parts.length-1]
};
};
export const validUrl = (url) => {
return url.match(/^https?:\/\//);
}
export const validTopicUrl = (url) => {
return url.match(/^https?:\/\/.+\/.*[^/]/); // At least one other slash
}
export const validTopic = (topic) => {
if (disallowedTopic(topic)) {
return false;
@ -115,6 +133,13 @@ export const shuffle = (arr) => {
return arr;
}
export const splitNoEmpty = (s, delimiter) => {
return s
.split(delimiter)
.map(x => x.trim())
.filter(x => x !== "");
}
/** Non-cryptographic hash function, see https://stackoverflow.com/a/8831937/1440785 */
export const hashCode = async (s) => {
let hash = 0;