mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-01 01:59:33 +00:00
Parse and stringify JSON with comments (#187)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { DataModel, ModelPath } from '@mcschema/core'
|
||||
import json from 'comment-json'
|
||||
import yaml from 'js-yaml'
|
||||
import { useCallback, useEffect, useRef, useState } from 'preact/hooks'
|
||||
import { Btn, BtnMenu } from '..'
|
||||
@@ -23,8 +24,8 @@ const FORMATS: Record<string, {
|
||||
stringify: (v: any, indentation: string | number | undefined) => string,
|
||||
}> = {
|
||||
json: {
|
||||
parse: JSON.parse,
|
||||
stringify: (v, i) => JSON.stringify(v, null, i),
|
||||
parse: json.parse,
|
||||
stringify: (v, i) => json.stringify(v, null, i),
|
||||
},
|
||||
yaml: {
|
||||
parse: yaml.load,
|
||||
|
||||
@@ -11,7 +11,6 @@ type HomeProps = {
|
||||
export function Home({ lang, changeTitle }: HomeProps) {
|
||||
const loc = locale.bind(null, lang)
|
||||
changeTitle(loc('title.home'))
|
||||
console.log(config.generators)
|
||||
return <main>
|
||||
<div class="home">
|
||||
<ToolCard title="Data packs">
|
||||
|
||||
@@ -16,9 +16,13 @@ export const transformOutput: Hook<[any, OutputProps], any> = {
|
||||
|
||||
list({ children }, path, value, props) {
|
||||
if (!Array.isArray(value)) return value
|
||||
return value.map((obj, index) =>
|
||||
const res = value.map((obj, index) =>
|
||||
children.hook(this, path.push(index), obj.node, props)
|
||||
)
|
||||
for (const a of Object.getOwnPropertySymbols(value)) {
|
||||
res[a as any] = value[a as any]
|
||||
}
|
||||
return res
|
||||
},
|
||||
|
||||
map({ children, config }, path, value, props) {
|
||||
@@ -31,6 +35,9 @@ export const transformOutput: Hook<[any, OutputProps], any> = {
|
||||
}
|
||||
res[f] = children.hook(this, path.push(f), value[f], props)
|
||||
})
|
||||
for (const a of Object.getOwnPropertySymbols(value)) {
|
||||
res[a as any] = value[a]
|
||||
}
|
||||
return res
|
||||
},
|
||||
|
||||
@@ -48,6 +55,9 @@ export const transformOutput: Hook<[any, OutputProps], any> = {
|
||||
res[f] = out
|
||||
}
|
||||
})
|
||||
for (const a of Object.getOwnPropertySymbols(value)) {
|
||||
res[a as any] = value[a]
|
||||
}
|
||||
return res
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user