Skip to content

Replace JSON.parse with parseJsonWithSchema #5881

@fehmer

Description

@fehmer

Replace JSON.parse with Misc.parseJsonWithSchema for type safety.

Example:

const customThemeUrlDataSchema = z.object({
c: CustomThemeColorsSchema,
i: z.string().optional(),
s: CustomBackgroundSizeSchema.optional(),
f: CustomBackgroundFilterSchema.optional(),
});
export function loadCustomThemeFromUrl(getOverride?: string): void {
const getValue = Misc.findGetParameter("customTheme", getOverride);
if (getValue === null) return;
let decoded: z.infer<typeof customThemeUrlDataSchema>;
try {
decoded = Misc.parseJsonWithSchema(
atob(getValue),
customThemeUrlDataSchema
);
} catch (e) {
console.log("Custom theme URL decoding failed", e);
Notifications.add(
"Failed to load theme from URL: " + (e as Error).message,
0
);
return;
}

Metadata

Metadata

Labels

help wantedExtra attention is neededimprovementChange or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions