mirror of
https://github.com/nexus-stc/hyperboria
synced 2025-01-25 01:47:36 +01:00
ad8f0b2700
1 internal commit(s) GitOrigin-RevId: 8bba552568b30f42662051baa2cb2fb088361b96
25 lines
703 B
JavaScript
25 lines
703 B
JavaScript
const NON_ALNUMWHITESPACE_REGEX = /([^\s\p{L}\p{Nd}])/gu
|
|
const MULTIWHITESPACE_REGEX = /\s+/g
|
|
|
|
export function castStringToSingleString (s) {
|
|
let processed = s.replace(NON_ALNUMWHITESPACE_REGEX, ' ')
|
|
processed = processed.replace(MULTIWHITESPACE_REGEX, '-')
|
|
return processed
|
|
}
|
|
|
|
export function quoteUrl (url, safe) {
|
|
if (typeof (safe) !== 'string') {
|
|
safe = '/'
|
|
}
|
|
url = encodeURIComponent(url)
|
|
const toUnencode = []
|
|
for (let i = safe.length - 1; i >= 0; --i) {
|
|
const encoded = encodeURIComponent(safe[i])
|
|
if (encoded !== safe.charAt(i)) {
|
|
toUnencode.push(encoded)
|
|
}
|
|
}
|
|
url = url.replace(new RegExp(toUnencode.join('|'), 'ig'), decodeURIComponent)
|
|
return url
|
|
}
|