the-superpirate ad8f0b2700 - feat(nexus): Change user_id to str type due to needs of e...
1 internal commit(s)

GitOrigin-RevId: 8bba552568b30f42662051baa2cb2fb088361b96
2021-05-01 12:11:09 +03:00

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
}