Added utils/url for functions in StatusCard
• Added: - utils/url for functions in StatusCard
This commit is contained in:
24
app/javascript/gabsocial/utils/urls.js
Normal file
24
app/javascript/gabsocial/utils/urls.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const IDNA_PREFIX = 'xn--'
|
||||
|
||||
export const decodeIDNA = (domain) => {
|
||||
return domain
|
||||
.split('.')
|
||||
.map(part => part.indexOf(IDNA_PREFIX) === 0 ? punycode.decode(part.slice(IDNA_PREFIX.length)) : part)
|
||||
.join('.')
|
||||
}
|
||||
|
||||
export const getHostname = (url) => {
|
||||
const parser = document.createElement('a')
|
||||
parser.href = url
|
||||
return parser.hostname
|
||||
}
|
||||
|
||||
export const trim = (text, len) => {
|
||||
const cut = text.indexOf(' ', len)
|
||||
|
||||
if (cut === -1) {
|
||||
return text
|
||||
}
|
||||
|
||||
return text.substring(0, cut) + (text.length > len ? '…' : '')
|
||||
}
|
||||
Reference in New Issue
Block a user