Skip to content

Commit

Permalink
fix: json5 parser error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
minsgy committed Jun 11, 2024
1 parent 1cb1eed commit 8e4c120
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"clsx": "^2.1.1",
"codemirror-json5": "^1.0.3",
"constate": "^3.3.2",
"json5": "^2.2.3",
"lucide-react": "0.378.0",
"msw": "2.2.13",
"postcss": "^8.4.38",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/shared/utils/createHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EnhancedDevtoolsRoute } from "@/types"
import json5 from "json5"
import { faker } from "@faker-js/faker"
import {
HttpHandler,
Expand All @@ -25,17 +26,15 @@ export const createHandler = (
return passthrough()
}

const jsonResponse = JSON.parse(selectedHandler.response)
const jsonResponse = json5.parse(selectedHandler.response)
if (jsonResponse) {
recursiveTransform(jsonResponse, (key, value) => {
if (typeof value === "number") {
return value
}

if (value.startsWith("faker.")) {
return resolveFakerValue(key, value)
}

return value
})
}
Expand Down

0 comments on commit 8e4c120

Please sign in to comment.