mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
33 lines
549 B
JavaScript
33 lines
549 B
JavaScript
export function safeDecodeURIComponent(value) {
|
|
if (typeof value !== "string") {
|
|
return "";
|
|
}
|
|
|
|
if (value === "") {
|
|
return "";
|
|
}
|
|
|
|
try {
|
|
return decodeURIComponent(value);
|
|
} catch (err) {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
export function safeDecodeURIComponentLoose(value, { trim = true } = {}) {
|
|
if (typeof value !== "string") {
|
|
return "";
|
|
}
|
|
|
|
const working = trim ? value.trim() : value;
|
|
if (trim && !working) {
|
|
return "";
|
|
}
|
|
|
|
try {
|
|
return decodeURIComponent(working);
|
|
} catch (err) {
|
|
return working;
|
|
}
|
|
}
|