-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clean up build and prettify stuffs
- Loading branch information
1 parent
4752015
commit c598ebe
Showing
10 changed files
with
156 additions
and
14 deletions.
There are no files selected for viewing
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
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,86 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { prettify } from './lib/prettify' | ||
|
||
const _prettify = (contents, type) => { | ||
console.log(`prettifying for type: ${type}`) | ||
return prettify(contents, type) | ||
} | ||
|
||
const PrettifyHeader = () => { | ||
return ( | ||
<section className='row mt-4'> | ||
<div className='col'> | ||
<div className='d-flex flex-column p-2 '> | ||
<h1>Prettify</h1> | ||
<p>The <i>Prettify</i> utility contains utilities related to making structured data look prettier to humans.</p> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
const PrettifyBody = ({ contents, handleChange, handleClick }) => { | ||
return ( | ||
<section className='row mt-4'> | ||
<div className='col'> | ||
<div className='d-flex flex-column p-2 text-center'> | ||
<h3 className='text-start'>Content To Prettify</h3> | ||
<textarea | ||
required | ||
rows='8' | ||
className='form-control my-3' | ||
placeholder='Contents here...' | ||
value={contents} | ||
onChange={handleChange} | ||
/> | ||
</div> | ||
<div className='p-2'> | ||
<button className='btn btn-primary me-2 mb-3' onClick={handleClick} value='json'>JSON <strong>{}</strong></button> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
const PrettifyResult = ({ result, setResult }) => { | ||
return ( | ||
<section> | ||
<div className='d-flex flex-column p-2'> | ||
<h3 className='text-start'>Result</h3> | ||
<textarea | ||
rows='8' | ||
className='form-control my-3' | ||
placeholder='Results will go here...' | ||
value={result} | ||
onChange={(e) => setResult(e.target.value)} | ||
/> | ||
</div> | ||
</section> | ||
) | ||
} | ||
|
||
function Prettify () { | ||
const [contents, setContents] = useState('') | ||
const [result, setResult] = useState('') | ||
|
||
const handleChange = (e) => setContents(e.target.value) | ||
|
||
const handleClick = (e) => { | ||
e.preventDefault() | ||
const type = e.target.value.toLowerCase() | ||
const _result = _prettify(contents, type) | ||
setResult(_result) | ||
} | ||
|
||
return ( | ||
<div> | ||
<PrettifyHeader /> | ||
<hr /> | ||
<PrettifyBody contents={contents} handleChange={handleChange} handleClick={handleClick} /> | ||
<PrettifyResult result={result} setResult={setResult} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Prettify |
31 changes: 31 additions & 0 deletions
31
utilities_for_me/web_app/client/react/lib/prettify/index.js
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,31 @@ | ||
const JSON_TYPE = "json" | ||
const HTML_TYPE = "html" | ||
const JS_TYPE = "js" | ||
const CSS_TYPE = "css" | ||
|
||
const prettifyJSON = (contents) => { | ||
let obj | ||
try { | ||
obj = JSON.parse(contents) | ||
} catch (error) { | ||
return 'data could not be parsed' | ||
} | ||
const result = JSON.stringify(obj, null, 2) | ||
return result | ||
} | ||
|
||
const prettify = (contents, type) => { | ||
let result | ||
switch(type){ | ||
case JSON_TYPE: | ||
result = prettifyJSON(contents) | ||
default: | ||
result = `unsupported content type ${type}` | ||
} | ||
|
||
return result | ||
} | ||
|
||
module.exports = { | ||
prettify | ||
} |