Fix JSON parsing and file reading with default values and safe parsing

Co-authored-by: jordi.err <jordi.err@gmail.com>
This commit is contained in:
Cursor Agentandjordi.err committed 2025-08-11 15:05:37 +00:00
1 parent 87292512b9
commit dbecb20976
3 files changed
+4 -4

No files matched your search

@@ -54,7 +54,7 @@ const withQueryParams =
!new URLSearchParams(window.location.search).has(queryGroupRef.current)
) {
try {
const storedValues = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) ?? '')
const storedValues = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) ?? 'null')
if (storedValues === null || typeof storedValues !== 'object') return
let storedValue: any = null
@@ -83,7 +83,7 @@ const withQueryParams =
if (queryGroupRef.current && queryTab) {
let updatedValues: Record<string, unknown> = {}
try {
const oldValues = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) ?? '')
const oldValues = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY) ?? '{}')
if (oldValues && typeof oldValues === 'object') {
updatedValues = oldValues
}
@@ -3,7 +3,7 @@ const path = require('path')
// Read the JSON file
try {
const rawData = fs.readFileSync('./tokens/design-tokens.tokens.json')
const rawData = fs.readFileSync('./tokens/design-tokens.tokens.json', 'utf8')
const jsonData = JSON.parse(rawData)
// Extract "core"
+1 -1
View File
@@ -14,7 +14,7 @@ export function mergeDeep(target: any, ...sources: any[]): any {
const source = sources.shift()
if (isObject(target) && isObject(source)) {
for (const key in source) {
for (const key of Object.keys(source)) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} })
mergeDeep(target[key], source[key])