chore: refactoring and tests, splitting up files (#12495)

This commit is contained in:
Adam
2026-02-06 10:02:31 -06:00
committed by GitHub
parent a4bc883595
commit 2c58dd6203
117 changed files with 9457 additions and 5827 deletions

View File

@@ -0,0 +1,39 @@
type RecordValue = Record<string, unknown>
const isRecord = (value: unknown): value is RecordValue => {
return typeof value === "object" && value !== null
}
export const isDisposable = (value: unknown): value is { dispose: () => void } => {
return isRecord(value) && typeof value.dispose === "function"
}
export const disposeIfDisposable = (value: unknown) => {
if (!isDisposable(value)) return
value.dispose()
}
export const hasSetOption = (value: unknown): value is { setOption: (key: string, next: unknown) => void } => {
return isRecord(value) && typeof value.setOption === "function"
}
export const setOptionIfSupported = (value: unknown, key: string, next: unknown) => {
if (!hasSetOption(value)) return
value.setOption(key, next)
}
export const getHoveredLinkText = (value: unknown) => {
if (!isRecord(value)) return
const link = value.currentHoveredLink
if (!isRecord(link)) return
if (typeof link.text !== "string") return
return link.text
}
export const getSpeechRecognitionCtor = <T>(value: unknown): (new () => T) | undefined => {
if (!isRecord(value)) return
const ctor =
typeof value.webkitSpeechRecognition === "function" ? value.webkitSpeechRecognition : value.SpeechRecognition
if (typeof ctor !== "function") return
return ctor as new () => T
}