forked from noxious/client
25 lines
740 B
TypeScript
25 lines
740 B
TypeScript
export function uuidv4() {
|
|
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (+c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))).toString(16))
|
|
}
|
|
|
|
export function unduplicateArray(array: any[]) {
|
|
return [...new Set(array.flat())]
|
|
}
|
|
|
|
export function getDomain() {
|
|
// Check if not localhost
|
|
if (window.location.hostname !== 'localhost') {
|
|
return window.location.hostname
|
|
}
|
|
|
|
// Check if not IP address
|
|
if (window.location.hostname.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
|
|
return window.location.hostname
|
|
}
|
|
|
|
if (window.location.hostname.split('.').length < 3) {
|
|
return window.location.hostname
|
|
}
|
|
|
|
return window.location.hostname.split('.').slice(-2).join('.')
|
|
} |