MCPcopy
hub / github.com/premieroctet/openchakra / loadFromJSON

Function loadFromJSON

src/utils/import.ts:4–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { INITIAL_COMPONENTS } from '~core/models/components'
3
4export async function loadFromJSON() {
5 const blob = await fileOpen({
6 extensions: ['json'],
7 mimeTypes: ['application/json'],
8 })
9
10 const contents: string = await new Promise(resolve => {
11 const reader = new FileReader()
12 reader.readAsText(blob, 'utf8')
13 reader.onloadend = () => {
14 if (reader.readyState === FileReader.DONE) {
15 resolve(reader.result as string)
16 }
17 }
18 })
19
20 try {
21 return JSON.parse(contents)
22 } catch (error) {}
23
24 return INITIAL_COMPONENTS
25}
26
27export async function saveAsJSON(components: IComponents) {
28 const serialized = JSON.stringify(components)

Callers 1

ImportMenuItemFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected