added json => xml

This commit is contained in:
Ritesh Kumar committed 2017-08-30 20:33:29 +05:30
1 parent 5fe112e346
commit 12bd61a7ee
9 files changed
+148 -94

No files matched your search

+23 -24
View File
@@ -43,7 +43,7 @@ type Props = {
onCheckboxChange: Function,
checkboxText: ?string,
pathname: string,
initialCheckboxValue: boolean,
initialCheckboxValue: ?boolean,
leftTitle: string,
rightTitle: string,
prettifyRightPanel: ?boolean
@@ -183,7 +183,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;
@@ -221,8 +221,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 {
@@ -252,7 +252,7 @@ export default class ConversionPanel extends PureComponent {
padding: 0 10px;
position: relative;
justify-content: space-between;
font-family: 'Lato';
font-family: "Lato";
}
.title {
@@ -295,7 +295,7 @@ export default class ConversionPanel extends PureComponent {
}
label {
font-family: 'Lato';
font-family: "Lato";
padding: 0 12px;
cursor: pointer;
}
@@ -309,14 +309,12 @@ export default class ConversionPanel extends PureComponent {
<div className="content-wrapper">
<div className="section left">
<div className="header">
<div className="title">
{leftTitle}
</div>
<div className="title">{leftTitle}</div>
<button className="btn" onClick={this.prettifyCode}>
Prettify
</button>
</div>
{isBrowser &&
{isBrowser && (
<AceEditor
mode={leftMode}
theme={theme}
@@ -329,14 +327,13 @@ export default class ConversionPanel extends PureComponent {
focus
fontSize={14}
wrapEnabled
/>}
/>
)}
</div>
<div className="section right">
<div className="header">
<div className="title">
{rightTitle}
</div>
{onCheckboxChange &&
<div className="title">{rightTitle}</div>
{onCheckboxChange && (
<label htmlFor="#text">
<input
type="checkbox"
@@ -345,21 +342,24 @@ export default class ConversionPanel extends PureComponent {
onChange={this.toggleCheckbox}
/>{" "}
{checkboxText}
</label>}
</label>
)}
<button className="btn" onClick={this.copyCode}>
Copy
</button>
</div>
{isBrowser &&
{isBrowser && (
<AceEditor
mode={rightMode === "jsx" ? "javascript" : rightMode}
theme={theme}
name="code"
readOnly
value={
prettifyRightPanel
? window.js_beautify(resultValue, { e4x: true })
: resultValue
prettifyRightPanel ? (
window.js_beautify(resultValue, { e4x: true })
) : (
resultValue
)
}
editorProps={{ $blockScrolling: true }}
scrollMargin={[20]}
@@ -367,13 +367,12 @@ export default class ConversionPanel extends PureComponent {
showGutter={false}
highlightActiveLine={false}
wrapEnabled
/>}
/>
)}
</div>
</div>
<div className={`footer${infoType ? " has-" + infoType : ""}`}>
<span className="info">
{info}
</span>
<span className="info">{info}</span>
</div>
</div>
);
+27 -23
View File
@@ -132,6 +132,16 @@ const x = [
path: "/graphql-to-typescript"
}
]
},
{
category: "XML",
iconName: "icon-html",
content: [
{
label: "XML to JSON",
path: "/xml-to-json"
}
]
}
];
@@ -157,7 +167,8 @@ function trackingScript() {
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}), (i[r].l = 1 * new Date());
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
@@ -182,10 +193,7 @@ function renderFuzzyPicker(isOpen, onClose) {
onChange={choice => Router.push(choice.path)}
items={routes}
itemValue={item => item.label}
renderItem={item =>
<span>
{item.label}
</span>}
renderItem={item => <span>{item.label}</span>}
/>
);
}
@@ -287,7 +295,7 @@ export default class Layout extends PureComponent {
height: 70px;
text-align: center;
color: #fff;
font-family: 'Lato', sans-serif;
font-family: "Lato", sans-serif;
}
.footer svg {
@@ -323,7 +331,7 @@ export default class Layout extends PureComponent {
}
.info {
font-family: 'Lato';
font-family: "Lato";
color: white;
border: 1px solid #7b7b7b;
padding: 8px;
@@ -337,7 +345,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;
}
@@ -370,7 +378,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;
@@ -407,20 +415,20 @@ export default class Layout extends PureComponent {
headerClass="Collapsible__trigger"
header={
<span>
{route.iconName
? <i className={route.iconName} />
: route.icon}{" "}
{route.iconName ? (
<i className={route.iconName} />
) : (
route.icon
)}{" "}
&nbsp; {route.category}
</span>
}
>
{route.content.map(a =>
{route.content.map(a => (
<Link prefetch href={a.path}>
<a className={this.getClass(a.path)}>
{a.label}
</a>
<a className={this.getClass(a.path)}>{a.label}</a>
</Link>
)}
))}
</Panel>
);
})}
@@ -438,12 +446,8 @@ export default class Layout extends PureComponent {
</a>
</div>
</div>
<div className="content">
{this.props.children}
</div>
<script>
{isBrowser && trackingScript()}
</script>
<div className="content">{this.props.children}</div>
<script>{isBrowser && trackingScript()}</script>
</div>
);
}
+8 -7
View File
@@ -18,31 +18,32 @@
"@gql2ts/from-schema": "^1.2.1",
"@gql2ts/language-flow": "^1.2.1",
"@tsuyoshiwada/htmltojsx": "^0.0.4",
"babel-standalone": "^6.25.0",
"babel-standalone": "^6.26.0",
"babili-webpack-plugin": "^0.1.2",
"copy-text-to-clipboard": "^1.0.2",
"copy-text-to-clipboard": "^1.0.3",
"css-to-react-native": "^2.0.4",
"generate-schema": "^2.5.1",
"is-in-browser": "^1.1.3",
"json2dts": "^0.0.2",
"lodash": "^4.17.4",
"next": "3.0.3",
"next": "^3.1.0",
"nprogress": "^0.2.0",
"pretty": "^2.0.0",
"prop-types": "^15.5.10",
"rc-collapse": "^1.7.6",
"react": "^15.6.1",
"react-ace": "^5.1.2",
"react-ace": "^5.2.0",
"react-collapse": "^4.0.3",
"react-collapsible": "^2.0.0",
"react-dom": "^15.6.1",
"react-fuzzy-picker": "^0.5.1",
"react-github-corner": "^0.3.0",
"react-github-corner": "^1.0.0",
"react-responsive-accordion": "^1.0.0",
"stringify-object": "^3.2.0",
"webpack-bundle-analyzer": "^2.9.0"
"webpack-bundle-analyzer": "^2.9.0",
"xml-js": "^1.4.1"
},
"devDependencies": {
"prettier": "^1.5.3"
"prettier": "^1.6.1"
}
}
-1
View File
@@ -10,7 +10,6 @@ export default class Json2Ts extends PureComponent {
};
getTransformedValue = newValue => {
console.log(newValue);
return schemaToInterfaces(JSON.parse(newValue), {
legacy: this.state.legacyTS
});
+45
View File
@@ -0,0 +1,45 @@
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>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
`;
export default class Json2Ts extends PureComponent {
state = {
isCompactMode: true
};
getTransformedValue = newValue => {
return xml2json(newValue, {
compact: this.state.isCompactMode
});
};
render() {
return (
<Layout pathname={this.props.url.pathname}>
<ConversionPanel
leftTitle="JSON"
rightTitle="XML"
getTransformedValue={this.getTransformedValue}
name={"big-query"}
defaultText={text}
leftMode="html"
rightMode="json"
url={this.props.url}
onCheckboxChange={(checked, cb) =>
this.setState({ isCompactMode: checked }, cb)}
checkboxText="Compact Mode"
initialCheckboxValue={this.state.isCompactMode}
/>
</Layout>
);
}
}
+5 -3
View File
@@ -344,9 +344,11 @@ var Json2dts = (function() {
classes[clsName] = output;
});
output = "";
Object.keys(classes).sort().forEach(function(key) {
output += classes[key];
});
Object.keys(classes)
.sort()
.forEach(function(key) {
output += classes[key];
});
return output;
};
+5 -3
View File
@@ -340,9 +340,11 @@ var Json2dts = (function() {
classes[clsName] = output;
});
output = "";
Object.keys(classes).sort().forEach(function(key) {
output += classes[key];
});
Object.keys(classes)
.sort()
.forEach(function(key) {
output += classes[key];
});
return output;
};
+5 -3
View File
@@ -337,9 +337,11 @@ var Json2dts = (function() {
classes[clsName] = output;
});
output = outputModule ? "module " + this.moduleName + "\n{\n" : "";
Object.keys(classes).sort().forEach(function(key) {
output += classes[key];
});
Object.keys(classes)
.sort()
.forEach(function(key) {
output += classes[key];
});
return output + (outputModule ? "\n}" : "");
};
Json2dts.prototype.analyse_object = function(obj, objectName) {
+30 -30
View File
@@ -108,10 +108,6 @@ ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
@@ -956,9 +952,9 @@ babel-runtime@6.x:
core-js "^2.4.0"
regenerator-runtime "^0.11.0"
babel-standalone@^6.25.0:
version "6.25.0"
resolved "https://registry.yarnpkg.com/babel-standalone/-/babel-standalone-6.25.0.tgz#759ef04574402b6d1a1b5efa62d18c9a47e4abeb"
babel-standalone@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-standalone/-/babel-standalone-6.26.0.tgz#15fb3d35f2c456695815ebf1ed96fe7f015b6886"
babel-template@6.25.0, babel-template@^6.24.1, babel-template@^6.25.0, babel-template@^6.7.0:
version "6.25.0"
@@ -1365,9 +1361,9 @@ cookie@0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
copy-text-to-clipboard@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/copy-text-to-clipboard/-/copy-text-to-clipboard-1.0.2.tgz#4809283665f24b4286acbfd4a67d8b209eae1680"
copy-text-to-clipboard@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/copy-text-to-clipboard/-/copy-text-to-clipboard-1.0.3.tgz#69662cd305493c925c02a384cbcae76d642d77f3"
core-js@^1.0.0:
version "1.2.7"
@@ -2888,9 +2884,9 @@ negotiator@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
next@3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/next/-/next-3.0.3.tgz#35128ba8359064ffe8d1d5e5543410319c6d66d3"
next@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/next/-/next-3.1.0.tgz#8dfff9b89cfb95ba29cf43107dd0b7ff3a4f5d01"
dependencies:
ansi-html "0.0.7"
babel-core "6.25.0"
@@ -2934,7 +2930,7 @@ next@3.0.3:
recursive-copy "^2.0.6"
send "^0.15.3"
source-map-support "0.4.15"
strip-ansi "4.0.0"
strip-ansi "3.0.1"
styled-jsx "^1.0.8"
touch "3.1.0"
unfetch "3.0.0"
@@ -3297,9 +3293,9 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@^1.5.3:
version "1.5.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.5.3.tgz#59dadc683345ec6b88f88b94ed4ae7e1da394bfe"
prettier@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.6.1.tgz#850f411a3116226193e32ea5acfc21c0f9a76d7d"
pretty@^2.0.0:
version "2.0.0"
@@ -3437,9 +3433,9 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
react-ace@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-5.1.2.tgz#cbaa0b20ce6dcb5f9b9151633ddce313c38d7905"
react-ace@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/react-ace/-/react-ace-5.2.0.tgz#94b6fbf71d5af68ca0a18228858cdb156a1c7dd5"
dependencies:
brace "^0.10.0"
lodash.get "^4.4.2"
@@ -3489,9 +3485,9 @@ react-fuzzy-picker@^0.5.1:
classnames "^2.2.5"
fuzzysearch "^1.0.3"
react-github-corner@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/react-github-corner/-/react-github-corner-0.3.0.tgz#b34c613e6f9cceb49fbe51378b78a9061af4da98"
react-github-corner@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-github-corner/-/react-github-corner-1.0.0.tgz#4cd59a09fa4a359d8578b7eb4466449690137b7f"
react-hot-loader@3.0.0-beta.7:
version "3.0.0-beta.7"
@@ -3746,6 +3742,10 @@ safe-buffer@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"
sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
"semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
@@ -3975,13 +3975,7 @@ stringstream@~0.0.4:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"
strip-ansi@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
dependencies:
ansi-regex "^3.0.0"
strip-ansi@^3.0.0, strip-ansi@^3.0.1:
strip-ansi@3.0.1, strip-ansi@^3.0.0, strip-ansi@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
dependencies:
@@ -4371,6 +4365,12 @@ ws@^2.3.1:
safe-buffer "~5.0.1"
ultron "~1.1.0"
xml-js@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.4.1.tgz#b34fface0c6d89804aaf0a182821ac1ed08a01e9"
dependencies:
sax "^1.2.1"
xml-name-validator@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-1.0.0.tgz#dcf82ee092322951ef8cc1ba596c9cbfd14a83f1"