search: add prefix for app search

This commit is contained in:
end-4
2025-10-10 23:33:21 +02:00
parent 8541dd3178
commit fe19cea6c9
3 changed files with 50 additions and 14 deletions
@@ -257,4 +257,32 @@ Singleton {
}
return false;
}
/**
* Removes the given prefix from the string if present.
* @param { string } str
* @param { string } prefix
* @returns { string }
*/
function cleanPrefix(str, prefix) {
if (str.startsWith(prefix)) {
return str.slice(prefix.length);
}
return str;
}
/**
* Removes the first matching prefix from the string if present.
* @param { string } str
* @param { string[] } prefixes
* @returns { string }
*/
function cleanOnePrefix(str, prefixes) {
for (let i = 0; i < prefixes.length; ++i) {
if (str.startsWith(prefixes[i])) {
return str.slice(prefixes[i].length);
}
}
return str;
}
}