This commit is contained in:
Ritesh Kumar committed 2017-09-02 19:53:49 +05:30
1 parent 60ad63eb9e
commit 050a2eeb87
5 files changed
+16 -15

No files matched your search

+8 -2
View File
@@ -4,6 +4,8 @@ import immutablePropsPlugin from "../utils/babel-plugin-js-to-immutable-prop-typ
import Layout from "../components/Layout";
import { transform } from "babel-standalone";
import defaultText from "../utils/dummy-json";
import { toValidJSON } from "../utils/json-to-ts-flow";
import merge from "lodash/merge"
import ConversionPanel from "../components/ConversionPanel";
@@ -13,9 +15,13 @@ export default class Main extends PureComponent {
};
getTransformedValue = newValue => {
newValue = "const propTypes = " + newValue;
let x = JSON.parse(toValidJSON(newValue))
if (typeof x !== "object" || Array.isArray(x)) {
x = merge({}, ...x)
}
x = "const propTypes = " + JSON.stringify(x);
const plugin = this.state.isImmutable ? immutablePropsPlugin : propsPlugin;
const { code } = transform(newValue, {
const { code } = transform(x, {
presets: ["es2015"],
plugins: [plugin]
});
+2 -3
View File
@@ -4,15 +4,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-ts-flow";
import Layout from "../components/Layout";
import ConversionPanel from "../components/ConversionPanel";
import defaultText from "../utils/dummy-json";
import merge from "lodash/merge";
export default class Json2Ts extends PureComponent {
getTransformedValue = newValue => {
const converter = new Json2dts();
let text2Obj = JSON.parse(toValidJSON(newValue));
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
throw new Error(
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
);
text2Obj = merge({}, ...text2Obj)
}
converter.parse(text2Obj, "props");
return converter.getCode(true);
+2 -4
View File
@@ -3,15 +3,13 @@ import { Json2dts, toValidJSON } from "../utils/json-to-rust-serde";
import Layout from "../components/Layout";
import ConversionPanel from "../components/ConversionPanel";
import defaultText from "../utils/dummy-json";
import merge from "lodash/merge"
export default class Json2Ts extends PureComponent {
getTransformedValue = newValue => {
const converter = new Json2dts();
let text2Obj = JSON.parse(toValidJSON(newValue));
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
throw new Error(
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
);
text2Obj = merge({}, ...text2Obj)
}
converter.parse(text2Obj, "RootJson");
+2 -3
View File
@@ -3,15 +3,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-scala-case-class";
import Layout from "../components/Layout";
import ConversionPanel from "../components/ConversionPanel";
import defaultText from "../utils/dummy-json";
import merge from "lodash/merge"
export default class Json2Ts extends PureComponent {
getTransformedValue = newValue => {
const converter = new Json2dts();
let text2Obj = JSON.parse(toValidJSON(newValue));
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
throw new Error(
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
);
text2Obj = merge({}, ...text2Obj)
}
converter.parse(text2Obj, "RootJson");
+2 -3
View File
@@ -4,15 +4,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-ts-flow";
import Layout from "../components/Layout";
import ConversionPanel from "../components/ConversionPanel";
import defaultText from "../utils/dummy-json";
import merge from "lodash/merge"
export default class Json2Ts extends PureComponent {
getTransformedValue = newValue => {
const converter = new Json2dts();
let text2Obj = JSON.parse(toValidJSON(newValue));
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
throw new Error(
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
);
text2Obj = merge({}, ...text2Obj)
}
converter.parse(text2Obj, "RootJson");
return converter.getCode();