mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
33 lines
856 B
TypeScript
33 lines
856 B
TypeScript
import { HttpErrorResponse } from '@angular/common/http'
|
|
|
|
export async function copyToClipboard (str: string): Promise<boolean> {
|
|
if (window.isSecureContext) {
|
|
return navigator.clipboard.writeText(str)
|
|
.then(() => {
|
|
return true
|
|
})
|
|
.catch(err => {
|
|
return false
|
|
})
|
|
} else {
|
|
const el = document.createElement('textarea')
|
|
el.value = str
|
|
el.setAttribute('readonly', '')
|
|
el.style.position = 'absolute'
|
|
el.style.left = '-9999px'
|
|
document.body.appendChild(el)
|
|
el.select()
|
|
const copy = document.execCommand('copy')
|
|
document.body.removeChild(el)
|
|
return copy
|
|
}
|
|
}
|
|
|
|
export function isUnauthorized (e: HttpErrorResponse): boolean {
|
|
return !!e.status && 401 === e.status
|
|
}
|
|
|
|
export function isBadRequest (e: HttpErrorResponse): boolean {
|
|
return !!e.status && 400 === e.status
|
|
}
|