mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-12 04:37:50 +01:00
fff80cd4e7
- fix(nexus): Preparing configs to be published - feat(nexus): Various fixes for opening left sources - fix(nexus): Fine-tune versions 1 internal commit(s) GitOrigin-RevId: 6c834cd3f4f5f18109a159a73503700dac63b0bb
31 lines
811 B
JavaScript
31 lines
811 B
JavaScript
const ALNUMWHITESPACE_REGEX = /\P{L}/gu
|
|
const MULTIWHITESPACE_REGEX = /\s+/g
|
|
|
|
export function castStringToSingleString (s) {
|
|
return s.replace(ALNUMWHITESPACE_REGEX, ' ').replace(MULTIWHITESPACE_REGEX, '-')
|
|
}
|
|
|
|
export function escapeFormat (text) {
|
|
return text.replace(/_+/g, '_')
|
|
.replace(/\*+/g, '*')
|
|
.replace(/`+/g, "'")
|
|
.replace(/\[+/g, '`[`')
|
|
.replace(/]+/g, '`]`')
|
|
}
|
|
|
|
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
|
|
}
|