avoid json errors in firefox

This commit is contained in:
Jade (Rose) Rowland 2024-01-19 23:04:41 -05:00
parent af52ac30ba
commit 0a349e1707
3 changed files with 17 additions and 7 deletions

View file

@ -52,6 +52,15 @@ export async function initCode() {
}
}
export const parseJSON = (json) => {
json = json != null && json.length ? json : '{}';
try {
return JSON.parse(json);
} catch {
return '{}';
}
};
export function getRandomTune() {
const allTunes = Object.entries(stockPatterns);
const randomItem = (arr) => arr[Math.floor(Math.random() * arr.length)];