-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from SureshPradhana/json-to-yaml
Json to yaml
- Loading branch information
Showing
9 changed files
with
180 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Editor } from "@monaco-editor/react"; | ||
|
||
export default function CodeEditor({ language, theme, value, onChange }) { | ||
return ( | ||
<Editor | ||
height="100vh" | ||
width="50vw" | ||
language={language} | ||
theme={theme} | ||
value={value} | ||
onChange={onChange} | ||
className=" sticky" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { NavBar } from "@/app/components/navbar"; | ||
import CodeEditor from "../components/editor"; | ||
const YAML = require('json-to-pretty-yaml'); | ||
|
||
export default function HTML_JSX() { | ||
const [isDarkMode, setIsDarkMode] = useState(false); | ||
const [value, setValue] = useState(`{"name": "Alice", "age": 25, "email": "[email protected]", "isStudent": false, "courses": ["Math", "Science", "History"]}`); | ||
const handleChange = (val) => { | ||
setValue(val); | ||
}; | ||
|
||
const toggleTheme = () => { | ||
const newTheme = !isDarkMode; | ||
setIsDarkMode(newTheme); | ||
localStorage.setItem("theme", JSON.stringify(newTheme)); | ||
}; | ||
|
||
const generateYAML = () => { | ||
let yaml='' | ||
try{ | ||
yaml = YAML.stringify(JSON.parse(value)); | ||
}catch(error){ | ||
yaml =error | ||
} | ||
if(value=== ''){ | ||
yaml ='' | ||
} | ||
return `${yaml}`; | ||
}; | ||
|
||
return ( | ||
<main | ||
className={`h-screen overflow-auto ${isDarkMode ? "bg-gray-900 text-white" : "bg-white text-black"}`} | ||
> | ||
<NavBar | ||
title={"JSON to YAML"} | ||
toggleTheme={toggleTheme} | ||
isDarkMode={isDarkMode} | ||
/> | ||
<div className="flex h-full"> | ||
<div> | ||
<h1 className="text-center p-2">JSON</h1> | ||
<CodeEditor | ||
theme={isDarkMode ? "vs-dark" : "vs-light"} | ||
value={value} | ||
language={"json"} | ||
onChange={handleChange} | ||
/> | ||
</div> | ||
<div> | ||
<h1 className="text-center p-2">YAML</h1> | ||
<CodeEditor | ||
theme={isDarkMode ? "vs-dark" : "vs-light"} | ||
language={"yaml"} | ||
value={generateYAML()} | ||
onChange={() => {}} | ||
/> | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.