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:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user