diff options
Diffstat (limited to 'src/cdp/types.ts')
| -rw-r--r-- | src/cdp/types.ts | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/cdp/types.ts b/src/cdp/types.ts index d57255f..33ab202 100644 --- a/src/cdp/types.ts +++ b/src/cdp/types.ts @@ -1,3 +1,5 @@ +import { isRecord } from "../util/guards"; + export type CdpEvent = { readonly method: string; readonly params: unknown; @@ -51,11 +53,8 @@ const INTERNAL_PREFIXES: ReadonlyArray<string> = [ export const isInternalUrl = (url: string): boolean => INTERNAL_PREFIXES.some((p) => url.startsWith(p)); -const isObject = (v: unknown): v is Readonly<Record<string, unknown>> => - typeof v === "object" && v !== null && !Array.isArray(v); - export const isCdpRawMessage = (v: unknown): v is CdpRawMessage => { - if (!isObject(v)) return false; + if (!isRecord(v)) return false; const id = v["id"]; if (id !== undefined && typeof id !== "number") return false; const method = v["method"]; @@ -64,7 +63,7 @@ export const isCdpRawMessage = (v: unknown): v is CdpRawMessage => { if (sessionId !== undefined && typeof sessionId !== "string") return false; const errVal = v["error"]; if (errVal !== undefined) { - if (!isObject(errVal)) return false; + if (!isRecord(errVal)) return false; if (typeof errVal["message"] !== "string") return false; const code = errVal["code"]; if (code !== undefined && typeof code !== "number") return false; |
