Files
medusa-store/www/reference/.cache/strip-prefix.js
T
2022-12-07 20:28:32 +01:00

21 lines
334 B
JavaScript

/**
* Remove a prefix from a string. Return the input string if the given prefix
* isn't found.
*/
export default function stripPrefix(str, prefix = ``) {
if (!prefix) {
return str
}
if (str === prefix) {
return `/`
}
if (str.startsWith(`${prefix}/`)) {
return str.slice(prefix.length)
}
return str
}