link: refactor href rewrite

- uses prop instead of attempting to read env variable
- uses URL type instead of custom heuristics
This commit is contained in:
Elijah Duffy
2025-12-12 13:59:21 -08:00
parent ae3abad769
commit 3885ac09a1
4 changed files with 74 additions and 22 deletions

View File

@@ -120,3 +120,26 @@ export const prefixZero = (str: string): string => {
}
return str;
};
/**
* Trims the specified character from the start and/or end of the string.
* @param str The string to trim.
* @param char The character to trim.
* @param trimStart Whether to trim from the start of the string. Default: true.
* @param trimEnd Whether to trim from the end of the string. Default: true.
* @returns The trimmed string.
*/
export const trimEdges = (str: string, char: string, trimStart?: boolean, trimEnd?: boolean) => {
let start = 0,
end = str.length;
if (trimStart || trimStart === undefined) {
while (start < end && str[start] === char) start++;
}
if (trimEnd || trimEnd === undefined) {
while (end > start && str[end - 1] === char) end--;
}
return str.substring(start, end);
};