Files
start-os/ui/src/app/util/web.util.ts
Aiden McClelland 95d3845906 0.2.5 initial commit
Makefile incomplete
2020-11-23 13:44:28 -07:00

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
}