mirror of
https://github.com/ritz078/transform.git
synced 2026-11-23 01:12:07 +03:00
refactor: run prettier standard on all files
This commit is contained in:
1 parent
50db36a745
commit
d14c57c8b6
31 files changed
+1550
-1554
No files matched your search
+148
-147
@@ -1,58 +1,58 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import cn from "classnames";
|
||||
import isBrowser from "is-in-browser";
|
||||
import copy from "copy-text-to-clipboard";
|
||||
import unfetch from "unfetch";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import React, { PureComponent } from 'react'
|
||||
import cn from 'classnames'
|
||||
import isBrowser from 'is-in-browser'
|
||||
import copy from 'copy-text-to-clipboard'
|
||||
import unfetch from 'unfetch'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
let CodeMirror;
|
||||
let CodeMirror
|
||||
if (isBrowser) {
|
||||
CodeMirror = require("react-codemirror2").default;
|
||||
CodeMirror = require('react-codemirror2').default
|
||||
|
||||
require("codemirror-graphql/mode");
|
||||
require("codemirror/mode/javascript/javascript");
|
||||
require("codemirror/mode/xml/xml");
|
||||
require("codemirror/mode/jsx/jsx");
|
||||
require("codemirror/mode/css/css");
|
||||
require("codemirror/mode/rust/rust");
|
||||
require("codemirror/mode/sql/sql");
|
||||
require("codemirror/mode/clike/clike");
|
||||
require("codemirror/mode/go/go");
|
||||
require('codemirror-graphql/mode')
|
||||
require('codemirror/mode/javascript/javascript')
|
||||
require('codemirror/mode/xml/xml')
|
||||
require('codemirror/mode/jsx/jsx')
|
||||
require('codemirror/mode/css/css')
|
||||
require('codemirror/mode/rust/rust')
|
||||
require('codemirror/mode/sql/sql')
|
||||
require('codemirror/mode/clike/clike')
|
||||
require('codemirror/mode/go/go')
|
||||
}
|
||||
|
||||
const prettierParsers = {
|
||||
css: "postcss",
|
||||
javascript: "babylon",
|
||||
jsx: "babylon",
|
||||
graphql: "graphql",
|
||||
json: "json",
|
||||
typescript: "typescript",
|
||||
flow: "flow"
|
||||
};
|
||||
css: 'postcss',
|
||||
javascript: 'babylon',
|
||||
jsx: 'babylon',
|
||||
graphql: 'graphql',
|
||||
json: 'json',
|
||||
typescript: 'typescript',
|
||||
flow: 'flow'
|
||||
}
|
||||
|
||||
const modeMapping = {
|
||||
javascript: {
|
||||
name: "javascript"
|
||||
name: 'javascript'
|
||||
},
|
||||
json: {
|
||||
name: "javascript",
|
||||
name: 'javascript',
|
||||
json: true
|
||||
},
|
||||
typescript: {
|
||||
name: "javascript",
|
||||
name: 'javascript',
|
||||
typescript: true
|
||||
},
|
||||
html: {
|
||||
name: "xml",
|
||||
name: 'xml',
|
||||
htmlMode: true
|
||||
},
|
||||
flow: {
|
||||
name: "javascript",
|
||||
name: 'javascript',
|
||||
typescript: true
|
||||
},
|
||||
mysql: "text/x-mysql",
|
||||
scala: "text/x-scala"
|
||||
};
|
||||
mysql: 'text/x-mysql',
|
||||
scala: 'text/x-scala'
|
||||
}
|
||||
|
||||
type Props = {
|
||||
leftMode: ?string,
|
||||
@@ -72,158 +72,159 @@ type Props = {
|
||||
showFetchButton: boolean,
|
||||
fetchButtonText: ?string,
|
||||
getTransformedValue: Function
|
||||
};
|
||||
}
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
props: Props;
|
||||
props: Props
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
constructor (props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
resultValue: "",
|
||||
resultValue: '',
|
||||
value: props.defaultText,
|
||||
splitValue: "",
|
||||
info: "",
|
||||
infoType: "",
|
||||
splitValue: '',
|
||||
info: '',
|
||||
infoType: '',
|
||||
isPrettierAvailable: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
leftMode: "javascript",
|
||||
rightMode: "javascript",
|
||||
pathname: "/",
|
||||
leftMode: 'javascript',
|
||||
rightMode: 'javascript',
|
||||
pathname: '/',
|
||||
prettifyRightPanel: true,
|
||||
splitLeft: false,
|
||||
showFetchButton: true,
|
||||
fetchButtonText: "Fetch JSON from URL"
|
||||
};
|
||||
fetchButtonText: 'Fetch JSON from URL'
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { defaultText, splitValue } = this.props;
|
||||
componentDidMount () {
|
||||
const { defaultText, splitValue } = this.props
|
||||
|
||||
this.onChange(defaultText, splitValue);
|
||||
this.onChange(defaultText, splitValue)
|
||||
|
||||
const { worker, promiseWorker } = loadWorker("prettier.js");
|
||||
this.worker = worker;
|
||||
this.promiseWorker = promiseWorker;
|
||||
const { worker, promiseWorker } = loadWorker('prettier.js')
|
||||
this.worker = worker
|
||||
this.promiseWorker = promiseWorker
|
||||
|
||||
this.worker.onmessage = this.setPrettierAvailability;
|
||||
this.worker.onmessage = this.setPrettierAvailability
|
||||
}
|
||||
|
||||
setPrettierAvailability = ({ data }) => {
|
||||
if (!data.available || this.state.isPrettierAvailable === data.available)
|
||||
return;
|
||||
if (!data.available || this.state.isPrettierAvailable === data.available) {
|
||||
return
|
||||
}
|
||||
this.setState({
|
||||
isPrettierAvailable: data.available
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
passCodeToWorker = (code, mode, section) => {
|
||||
this.promiseWorker.postMessage({ code, mode, section }).then(response => {
|
||||
const { available, prettyCode, section } = response;
|
||||
const { available, prettyCode, section } = response
|
||||
this.setState({
|
||||
isPrettierAvailable: available,
|
||||
[section]: prettyCode
|
||||
});
|
||||
});
|
||||
};
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fetchJSON = async () => {
|
||||
const url = window.prompt("Enter URL to fetch JSON from a remote server.");
|
||||
if (!url) return;
|
||||
const url = window.prompt('Enter URL to fetch JSON from a remote server.')
|
||||
if (!url) return
|
||||
try {
|
||||
const res = await unfetch(url);
|
||||
const json = await res.json();
|
||||
this.onChange(JSON.stringify(json, null, 2));
|
||||
const res = await unfetch(url)
|
||||
const json = await res.json()
|
||||
this.onChange(JSON.stringify(json, null, 2))
|
||||
} catch (e) {
|
||||
this.setState({
|
||||
info: e.message,
|
||||
infoType: "error"
|
||||
});
|
||||
infoType: 'error'
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
onChange = async (newValue, leftSplitValue) => {
|
||||
const { prettifyRightPanel, rightMode } = this.props;
|
||||
const { prettifyRightPanel, rightMode } = this.props
|
||||
|
||||
const nValue = newValue || this.state.value;
|
||||
const nValue = newValue || this.state.value
|
||||
const splitValue =
|
||||
leftSplitValue && typeof leftSplitValue === "string"
|
||||
leftSplitValue && typeof leftSplitValue === 'string'
|
||||
? leftSplitValue
|
||||
: this.state.splitValue;
|
||||
: this.state.splitValue
|
||||
|
||||
try {
|
||||
let code = await this.props.getTransformedValue(nValue, splitValue);
|
||||
code = code.prettyCode || code;
|
||||
let code = await this.props.getTransformedValue(nValue, splitValue)
|
||||
code = code.prettyCode || code
|
||||
if (prettifyRightPanel) {
|
||||
this.passCodeToWorker(code, rightMode, "resultValue");
|
||||
this.passCodeToWorker(code, rightMode, 'resultValue')
|
||||
} else {
|
||||
this.setState({
|
||||
resultValue: code
|
||||
});
|
||||
})
|
||||
}
|
||||
this.setState({
|
||||
info: "",
|
||||
infoType: ""
|
||||
});
|
||||
info: '',
|
||||
infoType: ''
|
||||
})
|
||||
} catch (e) {
|
||||
this.setState({
|
||||
info: e.message,
|
||||
infoType: "error"
|
||||
});
|
||||
infoType: 'error'
|
||||
})
|
||||
}
|
||||
|
||||
this.setState({
|
||||
value: nValue,
|
||||
splitValue: splitValue
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
toggleCheckbox = e => {
|
||||
const checked = e.currentTarget.checked;
|
||||
const checked = e.currentTarget.checked
|
||||
if (this.props.onCheckboxChange) {
|
||||
this.props.onCheckboxChange(checked, () => {
|
||||
this.onChange();
|
||||
});
|
||||
this.onChange()
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
prettifyCode = () => {
|
||||
if (!this.state.isPrettierAvailable) return;
|
||||
const { leftMode } = this.props;
|
||||
const { value } = this.state;
|
||||
if (!this.state.isPrettierAvailable) return
|
||||
const { leftMode } = this.props
|
||||
const { value } = this.state
|
||||
|
||||
this.passCodeToWorker(value, leftMode, "value");
|
||||
};
|
||||
this.passCodeToWorker(value, leftMode, 'value')
|
||||
}
|
||||
|
||||
prettifySplitCode = () => {
|
||||
if (!this.state.isPrettierAvailable) return;
|
||||
const { splitMode } = this.props;
|
||||
const { splitValue } = this.state;
|
||||
if (!this.state.isPrettierAvailable) return
|
||||
const { splitMode } = this.props
|
||||
const { splitValue } = this.state
|
||||
|
||||
this.passCodeToWorker(splitValue, splitMode, "splitValue");
|
||||
};
|
||||
this.passCodeToWorker(splitValue, splitMode, 'splitValue')
|
||||
}
|
||||
|
||||
copyCode = () => {
|
||||
const { resultValue } = this.state;
|
||||
const { resultValue } = this.state
|
||||
|
||||
copy(resultValue);
|
||||
copy(resultValue)
|
||||
|
||||
this.setState({
|
||||
info: "Code copied to clipboard.",
|
||||
infoType: "success"
|
||||
});
|
||||
};
|
||||
info: 'Code copied to clipboard.',
|
||||
infoType: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
getPrettifyClass = () => {
|
||||
return cn("btn", {
|
||||
return cn('btn', {
|
||||
disabled: !this.state.isPrettierAvailable
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
const {
|
||||
leftMode,
|
||||
rightMode,
|
||||
@@ -237,35 +238,35 @@ export default class ConversionPanel extends PureComponent {
|
||||
splitMode,
|
||||
showFetchButton,
|
||||
fetchButtonText
|
||||
} = this.props;
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state;
|
||||
} = this.props
|
||||
const { infoType, resultValue, value, info, splitValue } = this.state
|
||||
|
||||
const leftClass = cn("section left", {
|
||||
const leftClass = cn('section left', {
|
||||
split: splitLeft
|
||||
});
|
||||
})
|
||||
|
||||
const codeMirrorOptions = {
|
||||
lineNumbers: true,
|
||||
theme: "chrome-devtools",
|
||||
theme: 'chrome-devtools',
|
||||
lineWrapping: true,
|
||||
scrollbarStyle: null
|
||||
};
|
||||
}
|
||||
|
||||
// hide success footer bannner after 2 seconds. Let other types be visible until fixed.
|
||||
clearTimeout(this.footerTimeout);
|
||||
if (infoType === "success") {
|
||||
clearTimeout(this.footerTimeout)
|
||||
if (infoType === 'success') {
|
||||
this.footerTimeout = setTimeout(
|
||||
() =>
|
||||
this.setState({
|
||||
info: "",
|
||||
infoType: ""
|
||||
info: '',
|
||||
infoType: ''
|
||||
}),
|
||||
2000
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="wrapper">
|
||||
<div className='wrapper'>
|
||||
<style jsx>{`
|
||||
.wrapper {
|
||||
display: flex;
|
||||
@@ -277,7 +278,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
.footer {
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
font-family: "Lato";
|
||||
font-family: 'Lato';
|
||||
background-color: white;
|
||||
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
z-index: 99;
|
||||
@@ -317,8 +318,8 @@ export default class ConversionPanel extends PureComponent {
|
||||
|
||||
.info {
|
||||
color: white;
|
||||
font: 14px/normal "Monaco", "Menlo", "Ubuntu Mono", "Consolas",
|
||||
"source-code-pro", monospace;
|
||||
font: 14px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas',
|
||||
'source-code-pro', monospace;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@@ -356,7 +357,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
padding: 0 10px;
|
||||
position: relative;
|
||||
justify-content: space-between;
|
||||
font-family: "Lato";
|
||||
font-family: 'Lato';
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -426,7 +427,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
|
||||
label {
|
||||
font-family: "Lato";
|
||||
font-family: 'Lato';
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -437,14 +438,14 @@ export default class ConversionPanel extends PureComponent {
|
||||
}
|
||||
`}</style>
|
||||
|
||||
<div className="content-wrapper">
|
||||
<div className='content-wrapper'>
|
||||
<div className={leftClass}>
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{leftTitle}</h4>
|
||||
{leftMode === "json" &&
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{leftTitle}</h4>
|
||||
{leftMode === 'json' &&
|
||||
showFetchButton && (
|
||||
<button className="btn" onClick={this.fetchJSON}>
|
||||
<button className='btn' onClick={this.fetchJSON}>
|
||||
{fetchButtonText}
|
||||
</button>
|
||||
)}
|
||||
@@ -470,9 +471,9 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
{splitLeft &&
|
||||
isBrowser && (
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{splitTitle}</h4>
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{splitTitle}</h4>
|
||||
{prettierParsers[splitMode] && (
|
||||
<button
|
||||
className={this.getPrettifyClass()}
|
||||
@@ -494,22 +495,22 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="section right">
|
||||
<div className="panel">
|
||||
<div className="header">
|
||||
<h4 className="title">{rightTitle}</h4>
|
||||
<div className='section right'>
|
||||
<div className='panel'>
|
||||
<div className='header'>
|
||||
<h4 className='title'>{rightTitle}</h4>
|
||||
{onCheckboxChange && (
|
||||
<label htmlFor="#text">
|
||||
<label htmlFor='#text'>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="#text"
|
||||
type='checkbox'
|
||||
id='#text'
|
||||
defaultChecked={initialCheckboxValue}
|
||||
onChange={this.toggleCheckbox}
|
||||
/>{" "}
|
||||
/>{' '}
|
||||
{checkboxText}
|
||||
</label>
|
||||
)}
|
||||
<button className="btn" onClick={this.copyCode}>
|
||||
<button className='btn' onClick={this.copyCode}>
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
@@ -527,12 +528,12 @@ export default class ConversionPanel extends PureComponent {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{infoType !== "" && (
|
||||
{infoType !== '' && (
|
||||
<div className={`footer has-${infoType}`}>
|
||||
<span className="info">{info}</span>
|
||||
<span className='info'>{info}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+104
-104
@@ -1,64 +1,64 @@
|
||||
import React, { PureComponent } 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";
|
||||
import FuzzyPicker, { FuzzyWrapper } from "react-fuzzy-picker";
|
||||
import Collapse, { Panel } from "rc-collapse";
|
||||
import findIndex from "lodash/findIndex";
|
||||
import { categorizedRoutes, routes, activeRouteData } from "../utils/routes";
|
||||
import React, { PureComponent } 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'
|
||||
import FuzzyPicker, { FuzzyWrapper } from 'react-fuzzy-picker'
|
||||
import Collapse, { Panel } from 'rc-collapse'
|
||||
import findIndex from 'lodash/findIndex'
|
||||
import { categorizedRoutes, routes, activeRouteData } from '../utils/routes'
|
||||
|
||||
NProgress.configure({ showSpinner: false });
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
Router.onRouteChangeStart = url => {
|
||||
if (url.indexOf("code=") === -1) {
|
||||
NProgress.start();
|
||||
if (url.indexOf('code=') === -1) {
|
||||
NProgress.start()
|
||||
}
|
||||
};
|
||||
Router.onRouteChangeComplete = () => NProgress.done();
|
||||
Router.onRouteChangeError = () => NProgress.done();
|
||||
}
|
||||
Router.onRouteChangeComplete = () => NProgress.done()
|
||||
Router.onRouteChangeError = () => NProgress.done()
|
||||
|
||||
function Logo() {
|
||||
function Logo () {
|
||||
return (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 100 125"
|
||||
fill="#ffffff"
|
||||
width="190"
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
viewBox='0 0 100 125'
|
||||
fill='#ffffff'
|
||||
width='190'
|
||||
>
|
||||
<path d="M68.6 34c-2.6 0-4.7 1.6-5.7 3.8l-25.4-6v-.4c0-3.4-2.8-6.2-6.2-6.2-3.4 0-6.2 2.8-6.2 6.2 0 3.1 2.2 5.6 5.2 6.1v25.1c-2.9.5-5.2 3-5.2 6.1 0 3.4 2.8 6.2 6.2 6.2 3.1 0 5.6-2.2 6.1-5.2h16.7c.5 2.9 3 5.2 6.1 5.2 3.4 0 6.2-2.8 6.2-6.2 0-2.4-1.4-4.4-3.3-5.5l4.8-16.9c.3 0 .6.1.9.1 3.4 0 6.2-2.8 6.2-6.2-.2-3.4-3-6.2-6.4-6.2zm0 10.3c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2zM31.4 27.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2zm4.1 41.4c0 2.3-1.9 4.2-4.2 4.2-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.4.1 4.2 1.9 4.2 4.2zm24.7 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2 4.2 1.9 4.2 4.2-1.9 4.2-4.2 4.2zm.9-10.3c-.3 0-.6-.1-.9-.1-3.1 0-5.6 2.2-6.1 5.2H37.5C37 65 35 63 32.4 62.5v-25c2.1-.3 3.9-1.8 4.7-3.7l25.4 6v.4c0 2.4 1.4 4.5 3.4 5.5l-4.8 16.8z" />
|
||||
<path d='M68.6 34c-2.6 0-4.7 1.6-5.7 3.8l-25.4-6v-.4c0-3.4-2.8-6.2-6.2-6.2-3.4 0-6.2 2.8-6.2 6.2 0 3.1 2.2 5.6 5.2 6.1v25.1c-2.9.5-5.2 3-5.2 6.1 0 3.4 2.8 6.2 6.2 6.2 3.1 0 5.6-2.2 6.1-5.2h16.7c.5 2.9 3 5.2 6.1 5.2 3.4 0 6.2-2.8 6.2-6.2 0-2.4-1.4-4.4-3.3-5.5l4.8-16.9c.3 0 .6.1.9.1 3.4 0 6.2-2.8 6.2-6.2-.2-3.4-3-6.2-6.4-6.2zm0 10.3c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2zM31.4 27.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2zm4.1 41.4c0 2.3-1.9 4.2-4.2 4.2-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.4.1 4.2 1.9 4.2 4.2zm24.7 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2 4.2 1.9 4.2 4.2-1.9 4.2-4.2 4.2zm.9-10.3c-.3 0-.6-.1-.9-.1-3.1 0-5.6 2.2-6.1 5.2H37.5C37 65 35 63 32.4 62.5v-25c2.1-.3 3.9-1.8 4.7-3.7l25.4 6v.4c0 2.4 1.4 4.5 3.4 5.5l-4.8 16.8z' />
|
||||
</svg>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function trackingScript() {
|
||||
(function(i, s, o, g, r, a, m) {
|
||||
i["GoogleAnalyticsObject"] = r;
|
||||
(i[r] =
|
||||
function trackingScript () {
|
||||
;(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r
|
||||
;(i[r] =
|
||||
i[r] ||
|
||||
function() {
|
||||
(i[r].q = i[r].q || []).push(arguments);
|
||||
function () {
|
||||
;(i[r].q = i[r].q || []).push(arguments)
|
||||
}),
|
||||
(i[r].l = 1 * new Date());
|
||||
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
|
||||
a.async = 1;
|
||||
a.src = g;
|
||||
m.parentNode.insertBefore(a, m);
|
||||
(i[r].l = 1 * new Date())
|
||||
;(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0])
|
||||
a.async = 1
|
||||
a.src = g
|
||||
m.parentNode.insertBefore(a, m)
|
||||
})(
|
||||
window,
|
||||
document,
|
||||
"script",
|
||||
"https://www.google-analytics.com/analytics.js",
|
||||
"ga"
|
||||
);
|
||||
'script',
|
||||
'https://www.google-analytics.com/analytics.js',
|
||||
'ga'
|
||||
)
|
||||
|
||||
ga("create", "UA-60624235-5", "auto");
|
||||
ga("send", "pageview");
|
||||
ga('create', 'UA-60624235-5', 'auto')
|
||||
ga('send', 'pageview')
|
||||
}
|
||||
|
||||
function renderFuzzyPicker(isOpen, onClose) {
|
||||
function renderFuzzyPicker (isOpen, onClose) {
|
||||
return (
|
||||
<FuzzyPicker
|
||||
isOpen={isOpen}
|
||||
@@ -68,32 +68,32 @@ function renderFuzzyPicker(isOpen, onClose) {
|
||||
itemValue={item => item.label}
|
||||
renderItem={item => <span>{item.label}</span>}
|
||||
/>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
// Here, we check what key must be pressed to open the fuzzy picker
|
||||
// We'll use the '/' key for this example.
|
||||
function isCorrectKeyPressed(event) {
|
||||
return event.metaKey && event.key === "p";
|
||||
function isCorrectKeyPressed (event) {
|
||||
return event.metaKey && event.key === 'p'
|
||||
}
|
||||
|
||||
export default class Layout extends PureComponent {
|
||||
state = {};
|
||||
state = {}
|
||||
|
||||
getClass(path) {
|
||||
return path === this.props.pathname ? "active" : "";
|
||||
getClass (path) {
|
||||
return path === this.props.pathname ? 'active' : ''
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.setKey(this.props.pathname);
|
||||
componentWillMount () {
|
||||
this.setKey(this.props.pathname)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
routes.forEach(({ path }) => Router.prefetch(path));
|
||||
componentDidMount () {
|
||||
routes.forEach(({ path }) => Router.prefetch(path))
|
||||
}
|
||||
|
||||
componentWillReceiveProps({ pathname }) {
|
||||
this.setKey(pathname);
|
||||
componentWillReceiveProps ({ pathname }) {
|
||||
this.setKey(pathname)
|
||||
}
|
||||
|
||||
setKey = pathname => {
|
||||
@@ -102,52 +102,52 @@ export default class Layout extends PureComponent {
|
||||
categorizedRoutes,
|
||||
o => o.content.filter(a => a.path === pathname).length
|
||||
) + 1}`
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
onChange = activeKey => {
|
||||
this.setState({
|
||||
activeKey
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
const { label, desc, title } = activeRouteData(this.props.pathname);
|
||||
render () {
|
||||
const { label, desc, title } = activeRouteData(this.props.pathname)
|
||||
|
||||
return (
|
||||
<div className="main-wrapper">
|
||||
<div className='main-wrapper'>
|
||||
<Head>
|
||||
<title>{title || label}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/png" href="/static/favicon.png" />
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
||||
<link rel='icon' type='image/png' href='/static/favicon.png' />
|
||||
<meta
|
||||
name="google-site-verification"
|
||||
content="bjJSOEahdert-7mwVScrwTTUVR3nSe0bEj5YjevUNn0"
|
||||
name='google-site-verification'
|
||||
content='bjJSOEahdert-7mwVScrwTTUVR3nSe0bEj5YjevUNn0'
|
||||
/>
|
||||
<meta name="description" content={desc} />
|
||||
<meta name='description' content={desc} />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-mfizz/2.4.1/font-mfizz.min.css"
|
||||
rel='stylesheet'
|
||||
type='text/css'
|
||||
href='https://cdnjs.cloudflare.com/ajax/libs/font-mfizz/2.4.1/font-mfizz.min.css'
|
||||
/>
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<link rel="manifest" href="/static/manifest.json" />
|
||||
<meta name="theme-color" content="#2196f3" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="application-name" content="Transform" />
|
||||
<meta name="apple-mobile-web-app-title" content="Transform" />
|
||||
<meta name="theme-color" content="#2196f3" />
|
||||
<meta name="msapplication-navbutton-color" content="#2196f3" />
|
||||
<link rel='stylesheet' href='/static/styles.css' />
|
||||
<link rel='manifest' href='/static/manifest.json' />
|
||||
<meta name='theme-color' content='#2196f3' />
|
||||
<meta name='mobile-web-app-capable' content='yes' />
|
||||
<meta name='apple-mobile-web-app-capable' content='yes' />
|
||||
<meta name='application-name' content='Transform' />
|
||||
<meta name='apple-mobile-web-app-title' content='Transform' />
|
||||
<meta name='theme-color' content='#2196f3' />
|
||||
<meta name='msapplication-navbutton-color' content='#2196f3' />
|
||||
<meta
|
||||
name="apple-mobile-web-app-status-bar-style"
|
||||
content="black-translucent"
|
||||
name='apple-mobile-web-app-status-bar-style'
|
||||
content='black-translucent'
|
||||
/>
|
||||
<meta name="msapplication-starturl" content="./" />
|
||||
<meta name="msapplication-TileColor" content="#2196f3" />
|
||||
<meta name='msapplication-starturl' content='./' />
|
||||
<meta name='msapplication-TileColor' content='#2196f3' />
|
||||
<meta
|
||||
name="msapplication-TileImage"
|
||||
content="/static/images/icons/icon-144x144.png"
|
||||
name='msapplication-TileImage'
|
||||
content='/static/images/icons/icon-144x144.png'
|
||||
/>
|
||||
</Head>
|
||||
<style jsx>{`
|
||||
@@ -189,7 +189,7 @@ export default class Layout extends PureComponent {
|
||||
padding: 10px 5px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-family: "Lato", sans-serif;
|
||||
font-family: 'Lato', sans-serif;
|
||||
}
|
||||
|
||||
.badge {
|
||||
@@ -219,7 +219,7 @@ export default class Layout extends PureComponent {
|
||||
}
|
||||
|
||||
.info {
|
||||
font-family: "Lato";
|
||||
font-family: 'Lato';
|
||||
color: white;
|
||||
border: 1px solid #7b7b7b;
|
||||
padding: 8px;
|
||||
@@ -233,7 +233,7 @@ export default class Layout extends PureComponent {
|
||||
<style jsx global>{`
|
||||
.Collapsible__trigger {
|
||||
color: whitesmoke;
|
||||
font-family: "Lato", sans-serif;
|
||||
font-family: 'Lato', sans-serif;
|
||||
line-height: 44px;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ export default class Layout extends PureComponent {
|
||||
.rc-collapse-content-box a {
|
||||
display: block;
|
||||
color: #fff;
|
||||
font-family: "Lato";
|
||||
font-family: 'Lato';
|
||||
line-height: 44px;
|
||||
padding-left: 20px;
|
||||
background-color: #3c3c3c;
|
||||
@@ -279,18 +279,18 @@ export default class Layout extends PureComponent {
|
||||
isKeyPressed={isCorrectKeyPressed}
|
||||
popup={renderFuzzyPicker}
|
||||
/>
|
||||
<div className="sidebar">
|
||||
<div className='sidebar'>
|
||||
<GithubCorner
|
||||
href="https://github.com/ritz078/transform-www"
|
||||
href='https://github.com/ritz078/transform-www'
|
||||
height={80}
|
||||
width={80}
|
||||
direction="left"
|
||||
direction='left'
|
||||
/>
|
||||
<div className="logo">
|
||||
<div className='logo'>
|
||||
<Logo />
|
||||
</div>
|
||||
<div className="info">Use Ctrl/Cmd + P for quick search</div>
|
||||
<div className="nav">
|
||||
<div className='info'>Use Ctrl/Cmd + P for quick search</div>
|
||||
<div className='nav'>
|
||||
<Collapse
|
||||
onChange={this.onChange}
|
||||
accordion
|
||||
@@ -301,14 +301,14 @@ export default class Layout extends PureComponent {
|
||||
return (
|
||||
<Panel
|
||||
key={i + 1}
|
||||
headerClass="Collapsible__trigger"
|
||||
headerClass='Collapsible__trigger'
|
||||
header={
|
||||
<span>
|
||||
{route.iconName ? (
|
||||
<i className={route.iconName} />
|
||||
) : (
|
||||
route.icon
|
||||
)}{" "}
|
||||
)}{' '}
|
||||
{route.category}
|
||||
</span>
|
||||
}
|
||||
@@ -319,25 +319,25 @@ export default class Layout extends PureComponent {
|
||||
</Link>
|
||||
))}
|
||||
</Panel>
|
||||
);
|
||||
)
|
||||
})}
|
||||
</Collapse>
|
||||
</div>
|
||||
|
||||
<div className="footer">
|
||||
Created by{" "}
|
||||
<div className='footer'>
|
||||
Created by{' '}
|
||||
<a
|
||||
target="_blank"
|
||||
className="twitter"
|
||||
href="https://twitter.com/ritz078"
|
||||
target='_blank'
|
||||
className='twitter'
|
||||
href='https://twitter.com/ritz078'
|
||||
>
|
||||
@ritz078
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="content">{this.props.children}</div>
|
||||
<div className='content'>{this.props.children}</div>
|
||||
<script>{isBrowser && trackingScript()}</script>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
const defaultText = `.main-wrapper {
|
||||
flex-direction: row;
|
||||
@@ -23,34 +23,34 @@ li {
|
||||
color: whitesmoke;
|
||||
line-height: 44px;
|
||||
}
|
||||
`;
|
||||
`
|
||||
|
||||
export default class extends PureComponent {
|
||||
state = {
|
||||
isRn: false
|
||||
};
|
||||
}
|
||||
|
||||
getTransformedValue = code => {
|
||||
this.promiseWorker = loadWorker("css-to-js.js", this).promiseWorker;
|
||||
return this.promiseWorker.postMessage({ code, isRn: this.state.isRn });
|
||||
};
|
||||
this.promiseWorker = loadWorker('css-to-js.js', this).promiseWorker
|
||||
return this.promiseWorker.postMessage({ code, isRn: this.state.isRn })
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="CSS"
|
||||
rightTitle="JavaScript"
|
||||
leftMode="css"
|
||||
rightMode="javascript"
|
||||
leftTitle='CSS'
|
||||
rightTitle='JavaScript'
|
||||
leftMode='css'
|
||||
rightMode='javascript'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"css_to_js"}
|
||||
name={'css_to_js'}
|
||||
defaultText={defaultText}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isRn: checked }, cb)}
|
||||
checkboxText="React Native"
|
||||
checkboxText='React Native'
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+18
-21
@@ -1,41 +1,38 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { dummySchema, dummyQuery } from "../utils/graphql-schema";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { dummySchema, dummyQuery } from '../utils/graphql-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = (newValue, splitValue) => {
|
||||
this.promiseWorker = loadWorker(
|
||||
"graphql-to-flow-ts.js",
|
||||
this
|
||||
).promiseWorker;
|
||||
this.promiseWorker = loadWorker('graphql-to-flow-ts.js', this).promiseWorker
|
||||
return this.promiseWorker.postMessage({
|
||||
schema: newValue,
|
||||
query: splitValue,
|
||||
convertTo: "flow"
|
||||
});
|
||||
};
|
||||
convertTo: 'flow'
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="Schema"
|
||||
rightTitle="Flow"
|
||||
leftTitle='Schema'
|
||||
rightTitle='Flow'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"graphql_to_typescript"}
|
||||
name={'graphql_to_typescript'}
|
||||
defaultText={dummySchema}
|
||||
leftMode="json"
|
||||
rightMode="flow"
|
||||
leftMode='json'
|
||||
rightMode='flow'
|
||||
url={this.props.url}
|
||||
splitLeft={true}
|
||||
splitMode={"graphql"}
|
||||
splitTitle={"Query"}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={'Query'}
|
||||
splitValue={dummyQuery}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,38 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { dummySchema, dummyQuery } from "../utils/graphql-schema";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { dummySchema, dummyQuery } from '../utils/graphql-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = (newValue, splitValue) => {
|
||||
this.promiseWorker = loadWorker(
|
||||
"graphql-to-flow-ts.js",
|
||||
this
|
||||
).promiseWorker;
|
||||
this.promiseWorker = loadWorker('graphql-to-flow-ts.js', this).promiseWorker
|
||||
return this.promiseWorker.postMessage({
|
||||
schema: newValue,
|
||||
query: splitValue,
|
||||
convertTo: "typescript"
|
||||
});
|
||||
};
|
||||
convertTo: 'typescript'
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="Schema"
|
||||
rightTitle="TypeScript Definition"
|
||||
leftTitle='Schema'
|
||||
rightTitle='TypeScript Definition'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"graphql_to_typescript"}
|
||||
name={'graphql_to_typescript'}
|
||||
defaultText={dummySchema}
|
||||
leftMode="json"
|
||||
rightMode="typescript"
|
||||
leftMode='json'
|
||||
rightMode='typescript'
|
||||
url={this.props.url}
|
||||
splitLeft={true}
|
||||
splitMode={"graphql"}
|
||||
splitTitle={"Query"}
|
||||
splitMode={'graphql'}
|
||||
splitTitle={'Query'}
|
||||
splitValue={dummyQuery}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+21
-21
@@ -1,55 +1,55 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import HTMLtoJSX from "@tsuyoshiwada/htmltojsx";
|
||||
import convertSvgString from "transform-svg-to-native";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import isSvg from "is-svg";
|
||||
import React, { PureComponent } from 'react'
|
||||
import HTMLtoJSX from '@tsuyoshiwada/htmltojsx'
|
||||
import convertSvgString from 'transform-svg-to-native'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import isSvg from 'is-svg'
|
||||
|
||||
const converter = new HTMLtoJSX({
|
||||
createClass: false
|
||||
});
|
||||
})
|
||||
|
||||
const defaultText = `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1">
|
||||
<rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/>
|
||||
</svg>`;
|
||||
</svg>`
|
||||
|
||||
export default class Css2Js extends PureComponent {
|
||||
state = {
|
||||
native: false
|
||||
};
|
||||
}
|
||||
|
||||
getTransformedValue = async (newValue: string) => {
|
||||
if (this.state.native && !isSvg(newValue)) {
|
||||
throw new Error(
|
||||
"You can only convert an SVG in this mode. Try turning off the react-native-svg checkbox."
|
||||
);
|
||||
'You can only convert an SVG in this mode. Try turning off the react-native-svg checkbox.'
|
||||
)
|
||||
}
|
||||
|
||||
return this.state.native
|
||||
? new Promise(resolve =>
|
||||
convertSvgString(newValue, code => resolve(code))
|
||||
)
|
||||
: converter.convert(newValue);
|
||||
};
|
||||
: converter.convert(newValue)
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
url={this.props.url}
|
||||
leftTitle="HTML"
|
||||
rightTitle="JSX"
|
||||
leftMode="html"
|
||||
rightMode="jsx"
|
||||
leftTitle='HTML'
|
||||
rightTitle='JSX'
|
||||
leftMode='html'
|
||||
rightMode='jsx'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"html_to_jsx"}
|
||||
name={'html_to_jsx'}
|
||||
defaultText={defaultText}
|
||||
checkboxText="react-native-svg"
|
||||
checkboxText='react-native-svg'
|
||||
initialCheckboxValue={this.state.native}
|
||||
onCheckboxChange={(checked: boolean, cb: Function) =>
|
||||
this.setState({ native: checked }, cb)}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+27
-27
@@ -1,57 +1,57 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import merge from "lodash/merge";
|
||||
import loadWorker from "../utils/loadWorker";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import merge from 'lodash/merge'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
|
||||
export default class Main extends PureComponent {
|
||||
state = {
|
||||
isImmutable: false
|
||||
};
|
||||
}
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
let code = JSON.parse(newValue);
|
||||
if (typeof code !== "object" || Array.isArray(code)) {
|
||||
code = merge({}, ...code);
|
||||
let code = JSON.parse(newValue)
|
||||
if (typeof code !== 'object' || Array.isArray(code)) {
|
||||
code = merge({}, ...code)
|
||||
}
|
||||
code = "const propTypes = " + JSON.stringify(code);
|
||||
this.promiseWorker = loadWorker("json-to-proptypes.js", this).promiseWorker;
|
||||
code = 'const propTypes = ' + JSON.stringify(code)
|
||||
this.promiseWorker = loadWorker('json-to-proptypes.js', this).promiseWorker
|
||||
return this.promiseWorker.postMessage({
|
||||
isImmutable: this.state.isImmutable,
|
||||
code
|
||||
});
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if ("serviceWorker" in navigator) {
|
||||
componentDidMount () {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register("/service-worker.js")
|
||||
.register('/service-worker.js')
|
||||
.then(registration => {
|
||||
console.log("service worker registration successful");
|
||||
console.log('service worker registration successful')
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn("service worker registration failed");
|
||||
});
|
||||
console.warn('service worker registration failed')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="PropTypes"
|
||||
leftMode="json"
|
||||
leftTitle='JSON'
|
||||
rightTitle='PropTypes'
|
||||
leftMode='json'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"prop_types"}
|
||||
name={'prop_types'}
|
||||
defaultText={defaultText}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isImmutable: checked }, cb)}
|
||||
checkboxText="Immutable Proptypes"
|
||||
checkboxText='Immutable Proptypes'
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -1,30 +1,30 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import stringify from "stringify-object";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import text from "../utils/dummy-object-json";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import stringify from 'stringify-object'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import text from '../utils/dummy-object-json'
|
||||
|
||||
const defaultText = stringify(eval(`(${text})`));
|
||||
const defaultText = stringify(eval(`(${text})`))
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
return JSON.stringify(eval("(" + newValue + ")"), null, 2);
|
||||
};
|
||||
return JSON.stringify(eval('(' + newValue + ')'), null, 2)
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JS Object"
|
||||
rightTitle="JSON"
|
||||
leftTitle='JS Object'
|
||||
rightTitle='JSON'
|
||||
url={this.props.url}
|
||||
leftMode="json"
|
||||
rightMode="json"
|
||||
leftMode='json'
|
||||
rightMode='json'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"js_to_json"}
|
||||
name={'js_to_json'}
|
||||
defaultText={defaultText}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import { compile } from "json-schema-to-typescript";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { compile } from 'json-schema-to-typescript'
|
||||
|
||||
const json = `{
|
||||
title: 'Example Schema',
|
||||
@@ -29,26 +29,26 @@ const json = `{
|
||||
}
|
||||
},
|
||||
required: ['firstName', 'lastName']
|
||||
}`;
|
||||
}`
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => compile(eval("(" + code + ")"));
|
||||
getTransformedValue = code => compile(eval('(' + code + ')'))
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON Schema"
|
||||
rightTitle="TypeScript Interface"
|
||||
leftTitle='JSON Schema'
|
||||
rightTitle='TypeScript Interface'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"ts_interface"}
|
||||
name={'ts_interface'}
|
||||
defaultText={json}
|
||||
leftMode="javascript"
|
||||
rightMode="typescript"
|
||||
leftMode='javascript'
|
||||
rightMode='typescript'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,30 +1,30 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import { bigquery } from "generate-schema";
|
||||
import stringify from "stringify-object";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-object-json";
|
||||
import React, { PureComponent } from 'react'
|
||||
import { bigquery } from 'generate-schema'
|
||||
import stringify from 'stringify-object'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-object-json'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue);
|
||||
return stringify(bigquery(value));
|
||||
};
|
||||
const value = JSON.parse(newValue)
|
||||
return stringify(bigquery(value))
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Big Query Schema"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Big Query Schema'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"big-query"}
|
||||
name={'big-query'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="javascript"
|
||||
leftMode='json'
|
||||
rightMode='javascript'
|
||||
url={this.props.url}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,28 +1,28 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
import React, { PureComponent } from 'react'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => transform(code);
|
||||
getTransformedValue = code => transform(code)
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Flow Types"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Flow Types'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"ts_interface"}
|
||||
name={'ts_interface'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="flow"
|
||||
leftMode='json'
|
||||
rightMode='flow'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import json2go from "../utils/json-to-go";
|
||||
import gofmt from "gofmt.js";
|
||||
import React, { PureComponent } from 'react'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import json2go from '../utils/json-to-go'
|
||||
import gofmt from 'gofmt.js'
|
||||
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = code => gofmt(json2go(code).go);
|
||||
getTransformedValue = code => gofmt(json2go(code).go)
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Go Struct"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Go Struct'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"ts_interface"}
|
||||
name={'ts_interface'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="go"
|
||||
leftMode='json'
|
||||
rightMode='go'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import plugin from "../utils/babel-plugin-js-to-mobx-state-tree";
|
||||
import Layout from "../components/Layout";
|
||||
import { transform } from "babel-standalone";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import React, { PureComponent } from 'react'
|
||||
import plugin from '../utils/babel-plugin-js-to-mobx-state-tree'
|
||||
import Layout from '../components/Layout'
|
||||
import { transform } from 'babel-standalone'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
|
||||
export default class Main extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
newValue = "const MyModel = " + newValue;
|
||||
newValue = 'const MyModel = ' + newValue
|
||||
const { code } = transform(newValue, {
|
||||
presets: ["es2015"],
|
||||
presets: ['es2015'],
|
||||
plugins: [plugin]
|
||||
});
|
||||
return code;
|
||||
};
|
||||
})
|
||||
return code
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="MobX-State-Tree Model"
|
||||
leftTitle='JSON'
|
||||
rightTitle='MobX-State-Tree Model'
|
||||
url={this.props.url}
|
||||
leftMode="json"
|
||||
leftMode='json'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"mobx_state_tree_model"}
|
||||
name={'mobx_state_tree_model'}
|
||||
defaultText={defaultText}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,31 +1,31 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import { mongoose } from "generate-schema";
|
||||
import stringify from "stringify-object";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-object-json";
|
||||
import React, { PureComponent } from 'react'
|
||||
import { mongoose } from 'generate-schema'
|
||||
import stringify from 'stringify-object'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-object-json'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue);
|
||||
return stringify(mongoose(value));
|
||||
};
|
||||
const value = JSON.parse(newValue)
|
||||
return stringify(mongoose(value))
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Mongoose Schema"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Mongoose Schema'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"mongoose"}
|
||||
name={'mongoose'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="javascript"
|
||||
leftMode='json'
|
||||
rightMode='javascript'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,31 +1,31 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import { mysql } from "generate-schema";
|
||||
import stringify from "stringify-object";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import React, { PureComponent } from 'react'
|
||||
import { mysql } from 'generate-schema'
|
||||
import stringify from 'stringify-object'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const value = JSON.parse(newValue);
|
||||
return mysql(value);
|
||||
};
|
||||
const value = JSON.parse(newValue)
|
||||
return mysql(value)
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="MySQL Table Schema"
|
||||
leftTitle='JSON'
|
||||
rightTitle='MySQL Table Schema'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"mysql"}
|
||||
name={'mysql'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="mysql"
|
||||
leftMode='json'
|
||||
rightMode='mysql'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: "rust-serde"
|
||||
});
|
||||
lang: 'rust-serde'
|
||||
})
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Rust Serde"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Rust Serde'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"ts_interface"}
|
||||
name={'ts_interface'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="rust"
|
||||
leftMode='json'
|
||||
rightMode='rust'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
export default class extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: "scala"
|
||||
});
|
||||
lang: 'scala'
|
||||
})
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="Scala Case Class"
|
||||
leftTitle='JSON'
|
||||
rightTitle='Scala Case Class'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"scala_case_class"}
|
||||
name={'scala_case_class'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="scala"
|
||||
leftMode='json'
|
||||
rightMode='scala'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import transform from "transform-json-types";
|
||||
import React, { PureComponent } from 'react'
|
||||
import dynamic from 'next/dynamic'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import defaultText from '../utils/dummy-json'
|
||||
import transform from 'transform-json-types'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code =>
|
||||
transform(code, {
|
||||
lang: "typescript"
|
||||
});
|
||||
lang: 'typescript'
|
||||
})
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="TypeScript Interface"
|
||||
leftTitle='JSON'
|
||||
rightTitle='TypeScript Interface'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"ts_interface"}
|
||||
name={'ts_interface'}
|
||||
defaultText={defaultText}
|
||||
leftMode="json"
|
||||
rightMode="typescript"
|
||||
leftMode='json'
|
||||
rightMode='typescript'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import { xml2json } from "xml-js";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import React, { PureComponent } from 'react'
|
||||
import { xml2json } from 'xml-js'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
|
||||
const text = `<note>
|
||||
<to>Tove</to>
|
||||
@@ -9,12 +9,12 @@ const text = `<note>
|
||||
<heading>Reminder</heading>
|
||||
<body>Don't forget me this weekend!</body>
|
||||
</note>
|
||||
`;
|
||||
`
|
||||
|
||||
export default class extends PureComponent {
|
||||
state = {
|
||||
isCompactMode: true
|
||||
};
|
||||
}
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
return JSON.stringify(
|
||||
@@ -23,27 +23,27 @@ export default class extends PureComponent {
|
||||
compact: this.state.isCompactMode
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="JSON"
|
||||
rightTitle="XML"
|
||||
leftTitle='JSON'
|
||||
rightTitle='XML'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"big-query"}
|
||||
name={'big-query'}
|
||||
defaultText={text}
|
||||
leftMode="html"
|
||||
rightMode="json"
|
||||
leftMode='html'
|
||||
rightMode='json'
|
||||
url={this.props.url}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ isCompactMode: checked }, cb)}
|
||||
checkboxText="Compact Mode"
|
||||
checkboxText='Compact Mode'
|
||||
initialCheckboxValue={this.state.isCompactMode}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import uniqBy from 'lodash/uniqBy'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to ImmutablePropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function({ types: t }) {
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
ArrayExpression (path) {
|
||||
if (t.isCallExpression(path.parent)) return
|
||||
let uniqueElements = uniqBy(path.node.elements, 'type')
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('mapContains')
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
];
|
||||
]
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -32,77 +32,78 @@ export default function({ types: t }) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("listOf")
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('listOf')
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
);
|
||||
)
|
||||
} else {
|
||||
path.replaceWith(t.identifier("ImmutablePropTypes.list"));
|
||||
path.replaceWith(t.identifier('ImmutablePropTypes.list'))
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.any"));
|
||||
NullLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.any'))
|
||||
},
|
||||
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`PropTypes.string`));
|
||||
StringLiteral (path) {
|
||||
if (path.parentKey === 'key') return
|
||||
path.replaceWith(t.identifier(`PropTypes.string`))
|
||||
},
|
||||
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.number"));
|
||||
NumericLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.number'))
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
ArrowFunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.func'))
|
||||
},
|
||||
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
FunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.func'))
|
||||
},
|
||||
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.bool"));
|
||||
BooleanLiteral (path) {
|
||||
path.replaceWith(t.identifier('PropTypes.bool'))
|
||||
},
|
||||
|
||||
VariableDeclaration(path) {
|
||||
VariableDeclaration (path) {
|
||||
path.insertBefore(
|
||||
t.identifier(
|
||||
`import ImmutablePropTypes from 'react-immutable-proptypes'`
|
||||
)
|
||||
);
|
||||
)
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
Program (path) {
|
||||
path.traverse({
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
enter (path) {
|
||||
t.removeComments(path.node)
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
ObjectExpression(path) {
|
||||
ObjectExpression (path) {
|
||||
if (
|
||||
t.isVariableDeclarator(path.parent) ||
|
||||
t.isCallExpression(path.parent)
|
||||
)
|
||||
return;
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const elements = [path.node];
|
||||
const elements = [path.node]
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
t.identifier('ImmutablePropTypes'),
|
||||
t.identifier('mapContains')
|
||||
),
|
||||
elements
|
||||
)
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
import uniqBy from 'lodash/uniqBy'
|
||||
import isEmpty from 'lodash/isEmpty'
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to PropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function({ types: t }) {
|
||||
export default function ({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression(path) {
|
||||
//if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
ArrayExpression (path) {
|
||||
// if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, 'type')
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
t.memberExpression(t.identifier('t'), t.identifier('model')),
|
||||
uniqueElements
|
||||
)
|
||||
];
|
||||
]
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -28,66 +28,66 @@ export default function({ types: t }) {
|
||||
) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("array")),
|
||||
t.memberExpression(t.identifier('t'), t.identifier('array')),
|
||||
uniqueElements
|
||||
)
|
||||
);
|
||||
)
|
||||
} else {
|
||||
path.replaceWith(t.identifier("t.array"));
|
||||
path.replaceWith(t.identifier('t.array'))
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.null"));
|
||||
NullLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.null'))
|
||||
},
|
||||
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`t.string`));
|
||||
StringLiteral (path) {
|
||||
if (path.parentKey === 'key') return
|
||||
path.replaceWith(t.identifier(`t.string`))
|
||||
},
|
||||
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.number"));
|
||||
NumericLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.number'))
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
ArrowFunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('t.frozen'))
|
||||
},
|
||||
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
FunctionExpression (path) {
|
||||
path.replaceWith(t.identifier('t.frozen'))
|
||||
},
|
||||
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.boolean"));
|
||||
BooleanLiteral (path) {
|
||||
path.replaceWith(t.identifier('t.boolean'))
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
Program (path) {
|
||||
path.traverse({
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
enter (path) {
|
||||
t.removeComments(path.node)
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
ObjectProperty(path) {
|
||||
ObjectProperty (path) {
|
||||
if (t.isStringLiteral(path.node.key)) {
|
||||
path.node.key = t.identifier(path.node.key.value);
|
||||
path.node.key = t.identifier(path.node.key.value)
|
||||
}
|
||||
},
|
||||
|
||||
ObjectExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
ObjectExpression (path) {
|
||||
if (t.isCallExpression(path.parent)) return
|
||||
|
||||
const elements = [path.node];
|
||||
const elements = [path.node]
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
t.memberExpression(t.identifier('t'), t.identifier('model')),
|
||||
elements
|
||||
)
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -41,6 +41,6 @@ const x = `{
|
||||
}
|
||||
]
|
||||
}
|
||||
`;
|
||||
`
|
||||
|
||||
export default x;
|
||||
export default x
|
||||
@@ -16,6 +16,6 @@ const y = `{
|
||||
"index": true,
|
||||
"required": true
|
||||
}
|
||||
}`;
|
||||
}`
|
||||
|
||||
export default y;
|
||||
export default y
|
||||
+649
-649
File diff suppressed because it is too large.
Load diff
+145
-145
@@ -7,227 +7,227 @@
|
||||
A simple utility to translate JSON into a Go type definition.
|
||||
*/
|
||||
|
||||
function jsonToGo(json, typename) {
|
||||
let data;
|
||||
let scope;
|
||||
let go = "";
|
||||
let tabs = 0;
|
||||
function jsonToGo (json, typename) {
|
||||
let data
|
||||
let scope
|
||||
let go = ''
|
||||
let tabs = 0
|
||||
|
||||
try {
|
||||
data = JSON.parse(json.replace(/\.0/g, ".1")); // hack that forces floats to stay as floats
|
||||
scope = data;
|
||||
data = JSON.parse(json.replace(/\.0/g, '.1')) // hack that forces floats to stay as floats
|
||||
scope = data
|
||||
} catch (e) {
|
||||
return {
|
||||
go: "",
|
||||
go: '',
|
||||
error: e.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
typename = format(typename || "AutoGenerated");
|
||||
append("type " + typename + " ");
|
||||
typename = format(typename || 'AutoGenerated')
|
||||
append('type ' + typename + ' ')
|
||||
|
||||
parseScope(scope);
|
||||
parseScope(scope)
|
||||
|
||||
return { go: go };
|
||||
return { go: go }
|
||||
|
||||
function parseScope(scope) {
|
||||
let keyname;
|
||||
if (typeof scope === "object" && scope !== null) {
|
||||
function parseScope (scope) {
|
||||
let keyname
|
||||
if (typeof scope === 'object' && scope !== null) {
|
||||
if (Array.isArray(scope)) {
|
||||
let i;
|
||||
let i
|
||||
let sliceType,
|
||||
scopeLength = scope.length;
|
||||
scopeLength = scope.length
|
||||
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
const thisType = goType(scope[i]);
|
||||
if (!sliceType) sliceType = thisType;
|
||||
const thisType = goType(scope[i])
|
||||
if (!sliceType) sliceType = thisType
|
||||
else if (sliceType !== thisType) {
|
||||
sliceType = mostSpecificPossibleGoType(thisType, sliceType);
|
||||
if (sliceType === "interface{}") break;
|
||||
sliceType = mostSpecificPossibleGoType(thisType, sliceType)
|
||||
if (sliceType === 'interface{}') break
|
||||
}
|
||||
}
|
||||
|
||||
append("[]");
|
||||
if (sliceType === "struct") {
|
||||
let k;
|
||||
let keys;
|
||||
const allFields = {};
|
||||
append('[]')
|
||||
if (sliceType === 'struct') {
|
||||
let k
|
||||
let keys
|
||||
const allFields = {}
|
||||
|
||||
// for each field counts how many times appears
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
keys = Object.keys(scope[i]);
|
||||
keys = Object.keys(scope[i])
|
||||
for (k in keys) {
|
||||
keyname = keys[k];
|
||||
keyname = keys[k]
|
||||
if (!(keyname in allFields)) {
|
||||
allFields[keyname] = {
|
||||
value: scope[i][keyname],
|
||||
count: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
allFields[keyname].count++;
|
||||
allFields[keyname].count++
|
||||
}
|
||||
}
|
||||
|
||||
// create a common struct with all fields found in the current array
|
||||
// omitempty dict indicates if a field is optional
|
||||
keys = Object.keys(allFields);
|
||||
keys = Object.keys(allFields)
|
||||
let struct = {},
|
||||
omitempty = {};
|
||||
omitempty = {}
|
||||
for (k in keys) {
|
||||
keyname = keys[k];
|
||||
let elem = allFields[keyname];
|
||||
keyname = keys[k]
|
||||
let elem = allFields[keyname]
|
||||
|
||||
struct[keyname] = elem.value;
|
||||
omitempty[keyname] = elem.count !== scopeLength;
|
||||
struct[keyname] = elem.value
|
||||
omitempty[keyname] = elem.count !== scopeLength
|
||||
}
|
||||
|
||||
parseStruct(struct, omitempty); // finally parse the struct !!
|
||||
} else if (sliceType === "slice") {
|
||||
parseScope(scope[0]);
|
||||
} else append(sliceType || "interface{}");
|
||||
parseStruct(struct, omitempty) // finally parse the struct !!
|
||||
} else if (sliceType === 'slice') {
|
||||
parseScope(scope[0])
|
||||
} else append(sliceType || 'interface{}')
|
||||
} else {
|
||||
parseStruct(scope);
|
||||
parseStruct(scope)
|
||||
}
|
||||
} else append(goType(scope));
|
||||
} else append(goType(scope))
|
||||
}
|
||||
|
||||
function parseStruct(scope, omitempty) {
|
||||
append("struct {\n");
|
||||
++tabs;
|
||||
const keys = Object.keys(scope);
|
||||
function parseStruct (scope, omitempty) {
|
||||
append('struct {\n')
|
||||
++tabs
|
||||
const keys = Object.keys(scope)
|
||||
for (const i in keys) {
|
||||
const keyname = keys[i];
|
||||
indent(tabs);
|
||||
append(format(keyname) + " ");
|
||||
parseScope(scope[keyname]);
|
||||
const keyname = keys[i]
|
||||
indent(tabs)
|
||||
append(format(keyname) + ' ')
|
||||
parseScope(scope[keyname])
|
||||
|
||||
append(' `json:"' + keyname);
|
||||
append(' `json:"' + keyname)
|
||||
if (omitempty && omitempty[keyname] === true) {
|
||||
append(",omitempty");
|
||||
append(',omitempty')
|
||||
}
|
||||
append('"`\n');
|
||||
append('"`\n')
|
||||
}
|
||||
indent(--tabs);
|
||||
append("}");
|
||||
indent(--tabs)
|
||||
append('}')
|
||||
}
|
||||
|
||||
function indent(tabs) {
|
||||
for (let i = 0; i < tabs; i++) go += "\t";
|
||||
function indent (tabs) {
|
||||
for (let i = 0; i < tabs; i++) go += '\t'
|
||||
}
|
||||
|
||||
function append(str) {
|
||||
go += str;
|
||||
function append (str) {
|
||||
go += str
|
||||
}
|
||||
|
||||
// Sanitizes and formats a string to make an appropriate identifier in Go
|
||||
function format(str) {
|
||||
if (!str) return "";
|
||||
else if (str.match(/^\d+$/)) str = "Num" + str;
|
||||
function format (str) {
|
||||
if (!str) return ''
|
||||
else if (str.match(/^\d+$/)) str = 'Num' + str
|
||||
else if (str.charAt(0).match(/\d/)) {
|
||||
const numbers = {
|
||||
"0": "Zero_",
|
||||
"1": "One_",
|
||||
"2": "Two_",
|
||||
"3": "Three_",
|
||||
"4": "Four_",
|
||||
"5": "Five_",
|
||||
"6": "Six_",
|
||||
"7": "Seven_",
|
||||
"8": "Eight_",
|
||||
"9": "Nine_"
|
||||
};
|
||||
str = numbers[str.charAt(0)] + str.substr(1);
|
||||
'0': 'Zero_',
|
||||
'1': 'One_',
|
||||
'2': 'Two_',
|
||||
'3': 'Three_',
|
||||
'4': 'Four_',
|
||||
'5': 'Five_',
|
||||
'6': 'Six_',
|
||||
'7': 'Seven_',
|
||||
'8': 'Eight_',
|
||||
'9': 'Nine_'
|
||||
}
|
||||
str = numbers[str.charAt(0)] + str.substr(1)
|
||||
}
|
||||
return toProperCase(str).replace(/[^a-z0-9]/gi, "") || "NAMING_FAILED";
|
||||
return toProperCase(str).replace(/[^a-z0-9]/gi, '') || 'NAMING_FAILED'
|
||||
}
|
||||
|
||||
// Determines the most appropriate Go type
|
||||
function goType(val) {
|
||||
if (val === null) return "interface{}";
|
||||
function goType (val) {
|
||||
if (val === null) return 'interface{}'
|
||||
|
||||
switch (typeof val) {
|
||||
case "string":
|
||||
if (/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(\+\d\d:\d\d|Z)/.test(val))
|
||||
return "time.Time";
|
||||
else return "string";
|
||||
case "number":
|
||||
case 'string':
|
||||
if (/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(\+\d\d:\d\d|Z)/.test(val)) {
|
||||
return 'time.Time'
|
||||
} else return 'string'
|
||||
case 'number':
|
||||
if (val % 1 === 0) {
|
||||
if (val > -2147483648 && val < 2147483647) return "int";
|
||||
else return "int64";
|
||||
} else return "float64";
|
||||
case "boolean":
|
||||
return "bool";
|
||||
case "object":
|
||||
if (Array.isArray(val)) return "slice";
|
||||
return "struct";
|
||||
if (val > -2147483648 && val < 2147483647) return 'int'
|
||||
else return 'int64'
|
||||
} else return 'float64'
|
||||
case 'boolean':
|
||||
return 'bool'
|
||||
case 'object':
|
||||
if (Array.isArray(val)) return 'slice'
|
||||
return 'struct'
|
||||
default:
|
||||
return "interface{}";
|
||||
return 'interface{}'
|
||||
}
|
||||
}
|
||||
|
||||
// Given two types, returns the more specific of the two
|
||||
function mostSpecificPossibleGoType(typ1, typ2) {
|
||||
if (typ1.substr(0, 5) === "float" && typ2.substr(0, 3) === "int")
|
||||
return typ1;
|
||||
else if (typ1.substr(0, 3) === "int" && typ2.substr(0, 5) === "float")
|
||||
return typ1;
|
||||
else return "interface{}";
|
||||
function mostSpecificPossibleGoType (typ1, typ2) {
|
||||
if (typ1.substr(0, 5) === 'float' && typ2.substr(0, 3) === 'int') {
|
||||
return typ1
|
||||
} else if (typ1.substr(0, 3) === 'int' && typ2.substr(0, 5) === 'float') {
|
||||
return typ1
|
||||
} else return 'interface{}'
|
||||
}
|
||||
|
||||
// Proper cases a string according to Go conventions
|
||||
function toProperCase(str) {
|
||||
function toProperCase (str) {
|
||||
// https://github.com/golang/lint/blob/39d15d55e9777df34cdffde4f406ab27fd2e60c0/lint.go#L695-L731
|
||||
const commonInitialisms = [
|
||||
"API",
|
||||
"ASCII",
|
||||
"CPU",
|
||||
"CSS",
|
||||
"DNS",
|
||||
"EOF",
|
||||
"GUID",
|
||||
"HTML",
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"ID",
|
||||
"IP",
|
||||
"JSON",
|
||||
"LHS",
|
||||
"QPS",
|
||||
"RAM",
|
||||
"RHS",
|
||||
"RPC",
|
||||
"SLA",
|
||||
"SMTP",
|
||||
"SSH",
|
||||
"TCP",
|
||||
"TLS",
|
||||
"TTL",
|
||||
"UDP",
|
||||
"UI",
|
||||
"UID",
|
||||
"UUID",
|
||||
"URI",
|
||||
"URL",
|
||||
"UTF8",
|
||||
"VM",
|
||||
"XML",
|
||||
"XSRF",
|
||||
"XSS"
|
||||
];
|
||||
'API',
|
||||
'ASCII',
|
||||
'CPU',
|
||||
'CSS',
|
||||
'DNS',
|
||||
'EOF',
|
||||
'GUID',
|
||||
'HTML',
|
||||
'HTTP',
|
||||
'HTTPS',
|
||||
'ID',
|
||||
'IP',
|
||||
'JSON',
|
||||
'LHS',
|
||||
'QPS',
|
||||
'RAM',
|
||||
'RHS',
|
||||
'RPC',
|
||||
'SLA',
|
||||
'SMTP',
|
||||
'SSH',
|
||||
'TCP',
|
||||
'TLS',
|
||||
'TTL',
|
||||
'UDP',
|
||||
'UI',
|
||||
'UID',
|
||||
'UUID',
|
||||
'URI',
|
||||
'URL',
|
||||
'UTF8',
|
||||
'VM',
|
||||
'XML',
|
||||
'XSRF',
|
||||
'XSS'
|
||||
]
|
||||
|
||||
return str
|
||||
.replace(/(^|[^a-zA-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(frag.toUpperCase()) >= 0)
|
||||
return sep + frag.toUpperCase();
|
||||
else return sep + frag[0].toUpperCase() + frag.substr(1).toLowerCase();
|
||||
.replace(/(^|[^a-zA-Z])([a-z]+)/g, function (unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(frag.toUpperCase()) >= 0) {
|
||||
return sep + frag.toUpperCase()
|
||||
} else return sep + frag[0].toUpperCase() + frag.substr(1).toLowerCase()
|
||||
})
|
||||
.replace(/([A-Z])([a-z]+)/g, function (unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(sep + frag.toUpperCase()) >= 0) {
|
||||
return (sep + frag).toUpperCase()
|
||||
} else return sep + frag
|
||||
})
|
||||
.replace(/([A-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(sep + frag.toUpperCase()) >= 0)
|
||||
return (sep + frag).toUpperCase();
|
||||
else return sep + frag;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = jsonToGo;
|
||||
module.exports = jsonToGo
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
export default function(fileName, self) {
|
||||
if (self && self.promiseWorker) return { promiseWorker: self.promiseWorker };
|
||||
const PromiseWorker = require("promise-worker");
|
||||
const MyWorker = require(`worker-loader?inline!../workers/${fileName}`);
|
||||
const worker = new MyWorker();
|
||||
const promiseWorker = new PromiseWorker(worker);
|
||||
export default function (fileName, self) {
|
||||
if (self && self.promiseWorker) return { promiseWorker: self.promiseWorker }
|
||||
const PromiseWorker = require('promise-worker')
|
||||
const MyWorker = require(`worker-loader?inline!../workers/${fileName}`)
|
||||
const worker = new MyWorker()
|
||||
const promiseWorker = new PromiseWorker(worker)
|
||||
|
||||
return { worker, promiseWorker };
|
||||
return { worker, promiseWorker }
|
||||
}
|
||||
+89
-89
@@ -1,185 +1,185 @@
|
||||
import flatten from "lodash/flatten";
|
||||
import find from "lodash/find";
|
||||
import flatten from 'lodash/flatten'
|
||||
import find from 'lodash/find'
|
||||
|
||||
function GraphQLIcon() {
|
||||
function GraphQLIcon () {
|
||||
return (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
|
||||
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z"
|
||||
fill='#ffffff'
|
||||
d='M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z'
|
||||
/>
|
||||
<path fill="#ffffff" d="M39.8 272.2h320.3v16.6H39.8z" />
|
||||
<path fill='#ffffff' d='M39.8 272.2h320.3v16.6H39.8z' />
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z"
|
||||
fill='#ffffff'
|
||||
d='M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z'
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z"
|
||||
fill='#ffffff'
|
||||
d='M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z'
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z"
|
||||
fill='#ffffff'
|
||||
d='M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z'
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z"
|
||||
fill='#ffffff'
|
||||
d='M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z'
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9"
|
||||
fill='#ffffff'
|
||||
d='M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
export const categorizedRoutes = [
|
||||
{
|
||||
category: "React",
|
||||
iconName: "icon-reactjs",
|
||||
category: 'React',
|
||||
iconName: 'icon-reactjs',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to React PropTypes",
|
||||
path: "/",
|
||||
title: "Transform | All important transforms at one place.",
|
||||
label: 'JSON to React PropTypes',
|
||||
path: '/',
|
||||
title: 'Transform | All important transforms at one place.',
|
||||
desc:
|
||||
"An online utility to convert a JSON object to prop-types, Typescript Interface, Rust serde or flow types. It also converts your CSS into JS and HTML into JSX."
|
||||
'An online utility to convert a JSON object to prop-types, Typescript Interface, Rust serde or flow types. It also converts your CSS into JS and HTML into JSX.'
|
||||
},
|
||||
{
|
||||
label: "HTML to JSX",
|
||||
path: "/html-to-jsx",
|
||||
label: 'HTML to JSX',
|
||||
path: '/html-to-jsx',
|
||||
desc:
|
||||
"An online REPL for converting HTML to JSX with proper support for SVG."
|
||||
'An online REPL for converting HTML to JSX with proper support for SVG.'
|
||||
},
|
||||
{
|
||||
label: "CSS to JS Objects",
|
||||
path: "/css-to-js",
|
||||
label: 'CSS to JS Objects',
|
||||
path: '/css-to-js',
|
||||
desc:
|
||||
"An online REPL for converting CSS to JS object. It also gives style optimized for React Native."
|
||||
'An online REPL for converting CSS to JS object. It also gives style optimized for React Native.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "JavaScript",
|
||||
iconName: "icon-javascript",
|
||||
category: 'JavaScript',
|
||||
iconName: 'icon-javascript',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Flow Types",
|
||||
path: "/json-to-flow-types",
|
||||
desc: "An online REPL for converting JSON to generate Flow Types."
|
||||
label: 'JSON to Flow Types',
|
||||
path: '/json-to-flow-types',
|
||||
desc: 'An online REPL for converting JSON to generate Flow Types.'
|
||||
},
|
||||
{
|
||||
label: "JSON to Typescript Interface",
|
||||
path: "/json-to-ts-interface",
|
||||
label: 'JSON to Typescript Interface',
|
||||
path: '/json-to-ts-interface',
|
||||
desc:
|
||||
"An online REPL for converting JSON to generate TypeScript Interface."
|
||||
'An online REPL for converting JSON to generate TypeScript Interface.'
|
||||
},
|
||||
{
|
||||
label: "JSON to MobX-State-Tree Model",
|
||||
path: "/json-to-mobx-state-tree",
|
||||
desc: "An online REPL for converting JSON to generate Mobx State Tree."
|
||||
label: 'JSON to MobX-State-Tree Model',
|
||||
path: '/json-to-mobx-state-tree',
|
||||
desc: 'An online REPL for converting JSON to generate Mobx State Tree.'
|
||||
},
|
||||
{
|
||||
label: "JS Object to JSON",
|
||||
path: "/js-object-to-json",
|
||||
desc: "An online REPL for converting JS Object to JSON."
|
||||
label: 'JS Object to JSON',
|
||||
path: '/js-object-to-json',
|
||||
desc: 'An online REPL for converting JS Object to JSON.'
|
||||
},
|
||||
{
|
||||
label: "JSON Schema to TypeScript",
|
||||
path: "/json-schema-to-ts",
|
||||
label: 'JSON Schema to TypeScript',
|
||||
path: '/json-schema-to-ts',
|
||||
desc:
|
||||
"An online REPL for converting JSON Schema to TypeScript Interface."
|
||||
'An online REPL for converting JSON Schema to TypeScript Interface.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Rust",
|
||||
iconName: "icon-rust",
|
||||
category: 'Rust',
|
||||
iconName: 'icon-rust',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Rust Serde",
|
||||
path: "/json-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON to Rust Serde Structs."
|
||||
label: 'JSON to Rust Serde',
|
||||
path: '/json-to-rust-serde',
|
||||
desc: 'An online REPL for converting JSON to Rust Serde Structs.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Databases",
|
||||
iconName: "icon-database",
|
||||
category: 'Databases',
|
||||
iconName: 'icon-database',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Mongoose Schema",
|
||||
path: "/json-to-mongoose",
|
||||
desc: "An online REPL to generate Mongoose Schema from JSON."
|
||||
label: 'JSON to Mongoose Schema',
|
||||
path: '/json-to-mongoose',
|
||||
desc: 'An online REPL to generate Mongoose Schema from JSON.'
|
||||
},
|
||||
{
|
||||
label: "JSON to Big Query Schema",
|
||||
path: "/json-to-big-query",
|
||||
desc: "An online REPL to generate Big Query Schema from JSON."
|
||||
label: 'JSON to Big Query Schema',
|
||||
path: '/json-to-big-query',
|
||||
desc: 'An online REPL to generate Big Query Schema from JSON.'
|
||||
},
|
||||
{
|
||||
label: "JSON to MySQL",
|
||||
path: "/json-to-mysql",
|
||||
label: 'JSON to MySQL',
|
||||
path: '/json-to-mysql',
|
||||
desc:
|
||||
"An online REPL to generate MySQL table generation code from JSON."
|
||||
'An online REPL to generate MySQL table generation code from JSON.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Scala",
|
||||
iconName: "icon-scala",
|
||||
category: 'Scala',
|
||||
iconName: 'icon-scala',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Scala Case Class",
|
||||
path: "/json-to-scala-case-class",
|
||||
desc: "An online REPL to generate Scala Case Class from JSON."
|
||||
label: 'JSON to Scala Case Class',
|
||||
path: '/json-to-scala-case-class',
|
||||
desc: 'An online REPL to generate Scala Case Class from JSON.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "GraphQL",
|
||||
category: 'GraphQL',
|
||||
icon: <GraphQLIcon />,
|
||||
content: [
|
||||
{
|
||||
label: "GraphQL to TypeScript",
|
||||
path: "/graphql-to-typescript",
|
||||
label: 'GraphQL to TypeScript',
|
||||
path: '/graphql-to-typescript',
|
||||
desc:
|
||||
"An online REPL to generate TypeScript type annotations based on a GraphQL schema and query documents."
|
||||
'An online REPL to generate TypeScript type annotations based on a GraphQL schema and query documents.'
|
||||
},
|
||||
{
|
||||
label: "GraphQL to Flow",
|
||||
path: "/graphql-to-flow",
|
||||
label: 'GraphQL to Flow',
|
||||
path: '/graphql-to-flow',
|
||||
desc:
|
||||
"An online REPL to generate Flow type annotations based on a GraphQL schema and query documents."
|
||||
'An online REPL to generate Flow type annotations based on a GraphQL schema and query documents.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Go",
|
||||
iconName: "icon-go",
|
||||
category: 'Go',
|
||||
iconName: 'icon-go',
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Go Struct",
|
||||
path: "/json-to-go",
|
||||
desc: "An online REPL to generate Go Struct from JSON."
|
||||
label: 'JSON to Go Struct',
|
||||
path: '/json-to-go',
|
||||
desc: 'An online REPL to generate Go Struct from JSON.'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "XML",
|
||||
iconName: "icon-html",
|
||||
category: 'XML',
|
||||
iconName: 'icon-html',
|
||||
content: [
|
||||
{
|
||||
label: "XML to JSON",
|
||||
path: "/xml-to-json",
|
||||
desc: "An online REPL to generate basic JSON from a XML."
|
||||
label: 'XML to JSON',
|
||||
path: '/xml-to-json',
|
||||
desc: 'An online REPL to generate basic JSON from a XML.'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
]
|
||||
|
||||
export const routes = flatten(categorizedRoutes.map(a => a.content));
|
||||
export const routes = flatten(categorizedRoutes.map(a => a.content))
|
||||
|
||||
export function activeRouteData(pathname) {
|
||||
return find(routes, o => o.path === pathname);
|
||||
export function activeRouteData (pathname) {
|
||||
return find(routes, o => o.path === pathname)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import cssToJS from "transform-css-to-js";
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
import cssToJS from 'transform-css-to-js'
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { isRn, code } = message;
|
||||
resolve(`const styles = ${cssToJS(code, isRn)}`);
|
||||
const { isRn, code } = message
|
||||
resolve(`const styles = ${cssToJS(code, isRn)}`)
|
||||
})
|
||||
);
|
||||
)
|
||||
@@ -1,10 +1,10 @@
|
||||
import transform from "transform-graphql-type-annotations";
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import transform from 'transform-graphql-type-annotations'
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { query, schema, convertTo } = message;
|
||||
resolve(transform(schema, query, convertTo));
|
||||
const { query, schema, convertTo } = message
|
||||
resolve(transform(schema, query, convertTo))
|
||||
})
|
||||
);
|
||||
)
|
||||
@@ -1,19 +1,19 @@
|
||||
import { transform } from "babel-standalone";
|
||||
import jsonToProptypes from "babel-plugin-json-to-proptypes";
|
||||
import immutablePropsPlugin from "../utils/babel-plugin-js-to-immutable-prop-types";
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import { transform } from 'babel-standalone'
|
||||
import jsonToProptypes from 'babel-plugin-json-to-proptypes'
|
||||
import immutablePropsPlugin from '../utils/babel-plugin-js-to-immutable-prop-types'
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
const { isImmutable, code } = message;
|
||||
const plugin = isImmutable ? immutablePropsPlugin : jsonToProptypes;
|
||||
const { isImmutable, code } = message
|
||||
const plugin = isImmutable ? immutablePropsPlugin : jsonToProptypes
|
||||
const newCode = transform(code, {
|
||||
plugins: [plugin]
|
||||
}).code;
|
||||
}).code
|
||||
|
||||
resolve(`import PropTypes from "prop-types";
|
||||
|
||||
${newCode}`);
|
||||
${newCode}`)
|
||||
})
|
||||
);
|
||||
)
|
||||
+26
-26
@@ -1,46 +1,46 @@
|
||||
import registerPromiseWorker from "promise-worker/register";
|
||||
import registerPromiseWorker from 'promise-worker/register'
|
||||
|
||||
try {
|
||||
importScripts("https://bundle.run/prettier@1.6.1");
|
||||
importScripts('https://bundle.run/prettier@1.6.1')
|
||||
} catch (e) {
|
||||
self.postMessage({ available: false });
|
||||
self.postMessage({ available: false })
|
||||
}
|
||||
|
||||
const prettierParsers = {
|
||||
css: "postcss",
|
||||
javascript: "babylon",
|
||||
jsx: "babylon",
|
||||
graphql: "graphql",
|
||||
json: "json",
|
||||
typescript: "typescript",
|
||||
flow: "flow"
|
||||
};
|
||||
|
||||
if (self.prettier) {
|
||||
postMessage({ available: true });
|
||||
css: 'postcss',
|
||||
javascript: 'babylon',
|
||||
jsx: 'babylon',
|
||||
graphql: 'graphql',
|
||||
json: 'json',
|
||||
typescript: 'typescript',
|
||||
flow: 'flow'
|
||||
}
|
||||
|
||||
function getPrettyCode(data) {
|
||||
const { code, mode, section } = data;
|
||||
if (self.prettier) {
|
||||
postMessage({ available: true })
|
||||
}
|
||||
|
||||
function getPrettyCode (data) {
|
||||
const { code, mode, section } = data
|
||||
|
||||
const prettyCode =
|
||||
self.prettier && prettierParsers[mode] && code
|
||||
? self.prettier.format(code, {
|
||||
parser: prettierParsers[mode],
|
||||
printWidth: 70
|
||||
})
|
||||
: code;
|
||||
parser: prettierParsers[mode],
|
||||
printWidth: 70
|
||||
})
|
||||
: code
|
||||
|
||||
return { available: !!self.prettier, prettyCode, section };
|
||||
return { available: !!self.prettier, prettyCode, section }
|
||||
}
|
||||
|
||||
registerPromiseWorker(
|
||||
message =>
|
||||
new Promise(resolve => {
|
||||
resolve(getPrettyCode(message));
|
||||
resolve(getPrettyCode(message))
|
||||
})
|
||||
);
|
||||
)
|
||||
|
||||
onmessage = function({ data }) {
|
||||
postMessage(getPrettyCode(data));
|
||||
};
|
||||
onmessage = function ({ data }) {
|
||||
postMessage(getPrettyCode(data))
|
||||
}
|
||||
Reference in new issue
Block a user