perf: lazy-load js-yaml (~107KB) as needed (#2551)

- Closes: #2532
This commit is contained in:
Dermot Duffy
2026-06-30 17:45:13 -07:00
committed by dermotduffy
parent 3fe5e4004a
commit d833edb65b
18 changed files with 413 additions and 134 deletions
+7 -8
View File
@@ -1,12 +1,11 @@
import { AdvancedCameraCardError } from '../types.js';
import { isRecord } from './basic.js';
// Narrows an unknown error to its structured object `context` -- non-null and
// of object type -- or null if the error is not an AdvancedCameraCardError or
// has no usable context. Consolidates the instanceof + typeof + null-guard
// dance that notification builders and error handlers would otherwise repeat.
export const getContextFromError = (error: unknown): object | null =>
error instanceof AdvancedCameraCardError &&
typeof error.context === 'object' &&
error.context !== null
// Narrows an unknown error to its structured object `context` -- a non-null
// record -- or null if the error is not an AdvancedCameraCardError or has no
// usable context. Consolidates the instanceof + null-guard dance that
// notification builders and error handlers would otherwise repeat.
export const getContextFromError = (error: unknown): Record<string, unknown> | null =>
error instanceof AdvancedCameraCardError && isRecord(error.context)
? error.context
: null;