You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.0 KiB

import type { SolidContainerUri, SolidLeafUri, SolidUri } from "../types.js";
/**
* Checks if a provided string is a leaf URI
* @param uri - the string to check
* @returns true if the string is a leaf URI
*/
export function isSolidUri(uri: string): uri is SolidUri {
try {
const url = new URL(uri);
return url.protocol === "https:" || url.protocol === "http:";
} catch {
return false;
}
}
/**
* Checks if a provided string is a Container URI
* @param uri - the string to check
* @returns true if the string is a container URI
*/
export function isSolidContainerUri(uri: string): uri is SolidContainerUri {
try {
const url = new URL(uri);
return url.pathname.endsWith("/");
} catch {
return false;
}
}
/**
* Checks if a provided string is a leaf URI
* @param uri - the string to check
* @returns true if the string is a leaf URI
*/
export function isSolidLeafUri(uri: string): uri is SolidLeafUri {
try {
const url = new URL(uri);
return !url.pathname.endsWith("/");
} catch {
return false;
}
}