2021-05-01 12:10:45 +03:00
|
|
|
const NON_ALNUMWHITESPACE_REGEX = /([^\s\p{L}\p{Nd}])/gu
|
2021-04-30 16:05:39 +03:00
|
|
|
const MULTIWHITESPACE_REGEX = /\s+/g
|
|
|
|
|
|
|
|
export function castStringToSingleString (s) {
|
2021-05-01 12:10:45 +03:00
|
|
|
let processed = s.replace(NON_ALNUMWHITESPACE_REGEX, ' ')
|
2021-04-30 16:05:39 +03:00
|
|
|
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
|
|
|
|
}
|