mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-11 16:41:36 -04:00
feat(json-viewer): add json repair option
This commit is contained in:
parent
08d977b8cd
commit
e88a2454a4
6 changed files with 76 additions and 139 deletions
|
@ -1,5 +1,6 @@
|
|||
import { type MaybeRef, get } from '@vueuse/core';
|
||||
import JSON5 from 'json5';
|
||||
import { jsonrepair } from 'jsonrepair';
|
||||
|
||||
export { sortObjectKeys, formatJson };
|
||||
|
||||
|
@ -24,12 +25,16 @@ function formatJson({
|
|||
rawJson,
|
||||
sortKeys = true,
|
||||
indentSize = 3,
|
||||
repairJson = false,
|
||||
}: {
|
||||
rawJson: MaybeRef<string>
|
||||
sortKeys?: MaybeRef<boolean>
|
||||
indentSize?: MaybeRef<number>
|
||||
repairJson?: MaybeRef<boolean>
|
||||
}) {
|
||||
const parsedObject = JSON5.parse(get(rawJson));
|
||||
const unwrappedJson = get(rawJson);
|
||||
const jsonString = get(repairJson) ? jsonrepair(unwrappedJson) : unwrappedJson;
|
||||
const parsedObject = JSON5.parse(jsonString);
|
||||
|
||||
return JSON.stringify(get(sortKeys) ? sortObjectKeys(parsedObject) : parsedObject, null, get(indentSize));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue