mirror of
https://github.com/ritz078/transform.git
synced 2026-11-22 09:01:31 +03:00
added json to interface conversion
This commit is contained in:
1 parent
87151e4657
commit
882761f482
10 files changed
+261
-22
No files matched your search
@@ -17,19 +17,18 @@ if (isBrowser) {
|
||||
require('brace/theme/tomorrow')
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
static propTypes = {
|
||||
plugin: PropTypes.func.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
leftMode: PropTypes.string,
|
||||
rightMode: PropTypes.string
|
||||
rightMode: PropTypes.string,
|
||||
pathname: PropTypes.string
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
leftMode: 'javascript',
|
||||
rightMode: 'javascript'
|
||||
rightMode: 'javascript',
|
||||
pathname: '/'
|
||||
}
|
||||
|
||||
constructor (props) {
|
||||
@@ -88,11 +87,11 @@ export default class ConversionPanel extends PureComponent {
|
||||
|
||||
render () {
|
||||
return (
|
||||
<Layout>
|
||||
<Layout pathname={this.props.pathname}>
|
||||
<div className="wrapper">
|
||||
<Head>
|
||||
<title>Transform | Convert an object to propTypes</title>
|
||||
<meta rel="description" content="Convert an object to propTypes"/>
|
||||
<title>Transform | Online code transformation</title>
|
||||
<meta rel="description" content="An online utility to convert a JSON object to prop-types or Typescript Interface."/>
|
||||
</Head>
|
||||
<style jsx>{`
|
||||
@import url('https://fonts.googleapis.com/css?family=Lato');
|
||||
@@ -183,7 +182,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
<div className="section left">
|
||||
{isBrowser &&
|
||||
<AceEditor
|
||||
mode="javascript"
|
||||
mode={this.props.leftMode}
|
||||
theme="tomorrow"
|
||||
onChange={this.onChange}
|
||||
name="code"
|
||||
@@ -202,7 +201,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
<div className="section right">
|
||||
{isBrowser &&
|
||||
<AceEditor
|
||||
mode="javascript"
|
||||
mode={this.props.rightMode}
|
||||
theme="tomorrow"
|
||||
name="code"
|
||||
readOnly
|
||||
|
||||
+66
-8
@@ -2,6 +2,16 @@ import React from 'react'
|
||||
import isBrowser from 'is-in-browser'
|
||||
import Link from 'next/link'
|
||||
import Head from 'next/head'
|
||||
import NProgress from 'nprogress'
|
||||
import Router from 'next/router'
|
||||
import GithubCorner from 'react-github-corner'
|
||||
|
||||
Router.onRouteChangeStart = (url) => {
|
||||
console.log(`Loading: ${url}`)
|
||||
NProgress.start()
|
||||
}
|
||||
Router.onRouteChangeComplete = () => NProgress.done()
|
||||
Router.onRouteChangeError = () => NProgress.done()
|
||||
|
||||
function isActiveRoute (routeName) {
|
||||
if (isBrowser) {
|
||||
@@ -28,11 +38,16 @@ function trackingScript() {
|
||||
ga('send', 'pageview');
|
||||
}
|
||||
|
||||
export default function ({children}) {
|
||||
export default function ({children, pathname}) {
|
||||
function getClass (path) {
|
||||
return path === pathname ? "active" : ""
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="main-wrapper">
|
||||
<Head>
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
||||
<link rel='stylesheet' type='text/css' href='/static/nprogress.css' />
|
||||
<script>
|
||||
{isBrowser && trackingScript()}
|
||||
</script>
|
||||
@@ -65,16 +80,24 @@ export default function ({children}) {
|
||||
li {
|
||||
color: whitesmoke;
|
||||
font-family: 'Lato', sans-serif;
|
||||
line-height: 40px;
|
||||
padding-left: 15px;
|
||||
line-height: 44px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
li.active {
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
color: #fff;
|
||||
background-color: #2d2d2d;
|
||||
}
|
||||
|
||||
a:not(.twitter):not(.github) {
|
||||
display: block;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #fff;
|
||||
}
|
||||
@@ -85,30 +108,65 @@ export default function ({children}) {
|
||||
}
|
||||
|
||||
.footer {
|
||||
height: 70px;
|
||||
height: 90px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: 'Lato', sans-serif;
|
||||
}
|
||||
|
||||
.footer svg {
|
||||
height: 30px;
|
||||
height: 36px;
|
||||
width: 30px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
position: absolute;
|
||||
margin-top: 6px;
|
||||
margin-left: 4px;
|
||||
background-color: #2196f3;
|
||||
height: 13px;
|
||||
padding: 2px 4px;
|
||||
border-radius: 2px;
|
||||
line-height: 12px;
|
||||
}
|
||||
|
||||
iframe {
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: table;
|
||||
margin: 0 auto;
|
||||
width: 61px;
|
||||
height: 20px;
|
||||
}
|
||||
`}</style>
|
||||
|
||||
<div className="sidebar">
|
||||
<GithubCorner
|
||||
href="https://github.com/ritz078/transform-www"
|
||||
height={80}
|
||||
width={80}
|
||||
direction="left"
|
||||
/>
|
||||
<div className="logo">
|
||||
<Logo/>
|
||||
</div>
|
||||
<ul>
|
||||
<li><Link prefetch href="/"><a>JS Object to React PropTypes</a></Link></li>
|
||||
<li className={getClass("/")}><Link prefetch href="/"><a>JS Object to React PropTypes</a></Link></li>
|
||||
<li className={getClass("/json-to-ts-interface")}><Link prefetch href="/json-to-ts-interface"><a>JSON to Typescript Interface <span className="badge">new</span></a></Link></li>
|
||||
</ul>
|
||||
|
||||
<div className="footer">
|
||||
<a href="https://github.com/ritz078/transform-www"><svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#ffffff" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414"><path d="M8 0C3.58 0 0 3.582 0 8c0 3.535 2.292 6.533 5.47 7.59.4.075.547-.172.547-.385 0-.19-.007-.693-.01-1.36-2.226.483-2.695-1.073-2.695-1.073-.364-.924-.89-1.17-.89-1.17-.725-.496.056-.486.056-.486.803.056 1.225.824 1.225.824.714 1.223 1.873.87 2.33.665.072-.517.278-.87.507-1.07-1.777-.2-3.644-.888-3.644-3.953 0-.873.31-1.587.823-2.147-.09-.202-.36-1.015.07-2.117 0 0 .67-.215 2.2.82.64-.178 1.32-.266 2-.27.68.004 1.36.092 2 .27 1.52-1.035 2.19-.82 2.19-.82.43 1.102.16 1.915.08 2.117.51.56.82 1.274.82 2.147 0 3.073-1.87 3.75-3.65 3.947.28.24.54.73.54 1.48 0 1.07-.01 1.93-.01 2.19 0 .21.14.46.55.38C13.71 14.53 16 11.53 16 8c0-4.418-3.582-8-8-8"/></svg></a>
|
||||
<br />Created by <a href="https://twitter.com/ritz078">@ritz078</a>
|
||||
<iframe
|
||||
src="https://platform.twitter.com/widgets/tweet_button.html?size=s&url=https%3A%2F%2Ftransform.now.sh&via=ritz078&text=An online utility to convert a JSON object to prop-types or Typescript Interface.&hashtags=propTypes,typescript"
|
||||
width="140"
|
||||
height="28"
|
||||
title="Twitter Tweet Button"
|
||||
style={{border: 0, overflow: 'hidden'}}>
|
||||
</iframe>
|
||||
<br />Created by <a className="twitter" href="https://twitter.com/ritz078">@ritz078</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="content">
|
||||
|
||||
@@ -7,6 +7,13 @@ module.exports = {
|
||||
config.node = {
|
||||
fs: 'empty'
|
||||
}
|
||||
|
||||
if (!dev) {
|
||||
config.plugins.push(
|
||||
new BabiliPlugin()
|
||||
)
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
};
|
||||
+4
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "transform",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -18,13 +18,16 @@
|
||||
"copy-text-to-clipboard": "^1.0.2",
|
||||
"is-in-browser": "^1.1.3",
|
||||
"js-beautify": "^1.6.14",
|
||||
"json2dts": "^0.0.2",
|
||||
"lodash": "^4.17.4",
|
||||
"next": "^2.4.9",
|
||||
"nprogress": "^0.2.0",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^15.6.1",
|
||||
"react-ace": "^5.1.2",
|
||||
"react-alert": "^2.2.0",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-github-corner": "^0.3.0",
|
||||
"react-toastify": "^1.7.0",
|
||||
"store2": "^2.5.1"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import React, {PureComponent} from 'react'
|
||||
import { transform } from 'babel-standalone'
|
||||
import plugin from '../utils/plugin'
|
||||
import plugin from '../utils/babel-plugin-js-to-prop-types'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
|
||||
const defaultText = `// Enter the object you want to convert in the
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import { Json2dts, toValidJSON } from 'json2dts'
|
||||
import isBrowser from 'is-in-browser'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
|
||||
let brace
|
||||
let AceEditor
|
||||
if (isBrowser) {
|
||||
brace = require('brace').default
|
||||
AceEditor = require('react-ace').default
|
||||
require('brace/mode/json')
|
||||
}
|
||||
|
||||
const defaultText = `
|
||||
{
|
||||
"foo": "bar",
|
||||
"ids": [1, 2, 3],
|
||||
"hello": {
|
||||
"x": "lkjlj",
|
||||
"y": "kjhkjhkjh"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = (newValue) => {
|
||||
const converter = new Json2dts()
|
||||
let text2Obj = JSON.parse(toValidJSON(newValue))
|
||||
if (typeof text2Obj !== 'object' || Array.isArray(text2Obj)) {
|
||||
throw new Error('Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON.')
|
||||
}
|
||||
converter.parse(text2Obj, 'RootJson')
|
||||
return converter.getCode()
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<ConversionPanel
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'prop_types'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
pathname={this.props.url.pathname}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
# transform-www
|
||||
|
||||
> Website for https://transform.now.sh
|
||||
|
||||
This project is based on [next.js](https://github.com/zeit/next.js/)
|
||||
|
||||
## Development
|
||||
|
||||
- Fork the repo
|
||||
- Create a new branch.
|
||||
- `yarn install`
|
||||
- `yarn dev` then fix issues or add features.
|
||||
- Make a pull request.
|
||||
|
||||
## License
|
||||
MIT @ Ritesh Kumar
|
||||
@@ -0,0 +1,74 @@
|
||||
/* Make clicks pass-through */
|
||||
#nprogress {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#nprogress .bar {
|
||||
background: #29d;
|
||||
|
||||
position: fixed;
|
||||
z-index: 1031;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
}
|
||||
|
||||
/* Fancy blur effect */
|
||||
#nprogress .peg {
|
||||
display: block;
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
width: 100px;
|
||||
height: 100%;
|
||||
box-shadow: 0 0 10px #29d, 0 0 5px #29d;
|
||||
opacity: 1.0;
|
||||
|
||||
-webkit-transform: rotate(3deg) translate(0px, -4px);
|
||||
-ms-transform: rotate(3deg) translate(0px, -4px);
|
||||
transform: rotate(3deg) translate(0px, -4px);
|
||||
}
|
||||
|
||||
/* Remove these to get rid of the spinner */
|
||||
#nprogress .spinner {
|
||||
display: block;
|
||||
position: fixed;
|
||||
z-index: 1031;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
}
|
||||
|
||||
#nprogress .spinner-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
box-sizing: border-box;
|
||||
|
||||
border: solid 2px transparent;
|
||||
border-top-color: #29d;
|
||||
border-left-color: #29d;
|
||||
border-radius: 50%;
|
||||
|
||||
-webkit-animation: nprogress-spinner 400ms linear infinite;
|
||||
animation: nprogress-spinner 400ms linear infinite;
|
||||
}
|
||||
|
||||
.nprogress-custom-parent {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.nprogress-custom-parent #nprogress .spinner,
|
||||
.nprogress-custom-parent #nprogress .bar {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
@-webkit-keyframes nprogress-spinner {
|
||||
0% { -webkit-transform: rotate(0deg); }
|
||||
100% { -webkit-transform: rotate(360deg); }
|
||||
}
|
||||
@keyframes nprogress-spinner {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
File renamed without changes.
@@ -1165,6 +1165,10 @@ camelcase@^1.0.2:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
|
||||
|
||||
camelcase@^2.0.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f"
|
||||
|
||||
camelcase@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-3.0.0.tgz#32fc4b9fcdaf845fcdf7e73bb97cac2261f0ab0a"
|
||||
@@ -1241,7 +1245,7 @@ cliui@^2.1.0:
|
||||
right-align "^0.1.1"
|
||||
wordwrap "0.0.2"
|
||||
|
||||
cliui@^3.2.0:
|
||||
cliui@^3.0.3, cliui@^3.2.0:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
|
||||
dependencies:
|
||||
@@ -2316,6 +2320,12 @@ json-stringify-safe@~5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
|
||||
|
||||
json2dts@^0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/json2dts/-/json2dts-0.0.2.tgz#2799bde183420b804ad7ffcd2c487e6bbcfa6ec5"
|
||||
dependencies:
|
||||
yargs "^3.15.0"
|
||||
|
||||
json5@^0.5.0, json5@^0.5.1:
|
||||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
|
||||
@@ -2734,6 +2744,10 @@ npmlog@^4.0.2:
|
||||
gauge "~2.7.3"
|
||||
set-blocking "~2.0.0"
|
||||
|
||||
nprogress@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
|
||||
|
||||
number-is-nan@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
|
||||
@@ -3096,6 +3110,10 @@ react-dom@^15.6.1:
|
||||
object-assign "^4.1.0"
|
||||
prop-types "^15.5.10"
|
||||
|
||||
react-github-corner@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-github-corner/-/react-github-corner-0.3.0.tgz#b34c613e6f9cceb49fbe51378b78a9061af4da98"
|
||||
|
||||
react-hot-loader@3.0.0-beta.7:
|
||||
version "3.0.0-beta.7"
|
||||
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-3.0.0-beta.7.tgz#d5847b8165d731c4d5b30d86d5d4716227a0fa83"
|
||||
@@ -3898,6 +3916,10 @@ window-size@0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"
|
||||
|
||||
window-size@^0.1.4:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"
|
||||
|
||||
window@3.1.5:
|
||||
version "3.1.5"
|
||||
resolved "https://registry.yarnpkg.com/window/-/window-3.1.5.tgz#dacd813d54efa5da9647dbc281855f12b89664bb"
|
||||
@@ -3945,7 +3967,7 @@ xtend@^4.0.0:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
|
||||
|
||||
y18n@^3.2.1:
|
||||
y18n@^3.2.0, y18n@^3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41"
|
||||
|
||||
@@ -3959,6 +3981,18 @@ yargs-parser@^4.2.0:
|
||||
dependencies:
|
||||
camelcase "^3.0.0"
|
||||
|
||||
yargs@^3.15.0:
|
||||
version "3.32.0"
|
||||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995"
|
||||
dependencies:
|
||||
camelcase "^2.0.1"
|
||||
cliui "^3.0.3"
|
||||
decamelize "^1.1.1"
|
||||
os-locale "^1.4.0"
|
||||
string-width "^1.0.1"
|
||||
window-size "^0.1.4"
|
||||
y18n "^3.2.0"
|
||||
|
||||
yargs@^6.0.0:
|
||||
version "6.6.0"
|
||||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208"
|
||||
|
||||
Reference in new issue
Block a user