Files
start-os/frontend/projects/shared/src/util/misc.util.ts
Lucy C 31952afe1e adjust service marketplace button for installation source relevance (#1571)
* adjust service marketplace button for installation source relevance

* cleanup

* show marketplace name instead of url; cleanup from PR feedback

* fix spacing

* further cleanup
2022-06-27 10:09:27 -06:00

52 lines
1.2 KiB
TypeScript

export function isObject(val: any): boolean {
return val && typeof val === 'object' && !Array.isArray(val)
}
export function isEmptyObject(obj: object): boolean {
return obj === undefined || !Object.keys(obj).length
}
export function pauseFor(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}
export function capitalizeFirstLetter(string: string): string {
return string.charAt(0).toUpperCase() + string.slice(1)
}
export function exists<T>(t: T | undefined): t is T {
return t !== undefined
}
export function debounce(delay: number = 300): MethodDecorator {
return function (
target: any,
propertyKey: string | symbol,
descriptor: PropertyDescriptor,
) {
const timeoutKey = Symbol()
const original = descriptor.value
descriptor.value = function (this: any, ...args: any[]) {
clearTimeout(this[timeoutKey])
this[timeoutKey] = setTimeout(() => original.apply(this, args), delay)
}
return descriptor
}
}
export function removeTrailingSlash(word: string): string {
return word.replace(/\/+$/, '')
}
export function isValidHttpUrl(string: string): boolean {
try {
const _ = new URL(string)
return true
} catch (_) {
return false
}
}