refactor: consolidate PNG encoder and safeParseJson utilities (#12457)
- Create shared PNG encoder module (src/media/png-encode.ts) - Refactor qr-image.ts and live-image-probe.ts to use shared encoder - Add safeParseJson to utils.ts and plugin-sdk exports - Update msteams and pairing-store to use centralized safeParseJson
This commit is contained in:
11
src/utils.ts
11
src/utils.ts
@@ -31,6 +31,17 @@ export function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely parse JSON, returning null on error instead of throwing.
|
||||
*/
|
||||
export function safeParseJson<T>(raw: string): T | null {
|
||||
try {
|
||||
return JSON.parse(raw) as T;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export type WebChannel = "web";
|
||||
|
||||
export function assertWebChannel(input: string): asserts input is WebChannel {
|
||||
|
||||
Reference in New Issue
Block a user