From c93caa676582fb2c788b851febdcbc22cfe4450d Mon Sep 17 00:00:00 2001 From: ritz078 Date: Fri, 19 Jan 2018 21:35:08 +0530 Subject: [PATCH 01/20] allow JS object instead of JSON --- components/ConversionPanel.js | 9 +++++++-- package.json | 6 +++--- yarn.lock | 18 +++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js index 1128f45..0f318bb 100644 --- a/components/ConversionPanel.js +++ b/components/ConversionPanel.js @@ -185,7 +185,7 @@ export default class ConversionPanel extends PureComponent { }; onChange = async (newValue, leftSplitValue) => { - const { prettifyRightPanel, rightMode } = this.props; + const { prettifyRightPanel, rightMode, leftMode } = this.props; const nValue = newValue || this.state.value; const splitValue = @@ -194,7 +194,12 @@ export default class ConversionPanel extends PureComponent { : this.state.splitValue; try { - let code = await this.props.getTransformedValue(nValue, splitValue); + // Convert JS to JSON + const json = + leftMode === "json" + ? JSON.stringify(eval("(" + nValue + ")", null, 2)) + : nValue; + let code = await this.props.getTransformedValue(json, splitValue); code = code.prettyCode || code; if (prettifyRightPanel) { this.passCodeToWorker(code, rightMode, "resultValue"); diff --git a/package.json b/package.json index e04c5d6..9e81a60 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "json-schema-faker": "^0.5.0-rc11", "json-schema-to-typescript": "^4.6.5", "lodash": "^4.17.4", - "next": "4.2.1", + "next": "4.2.3", "nprogress": "^0.2.0", "promise-worker": "^1.1.1", "prop-types": "^15.6.0", @@ -58,14 +58,14 @@ "react-codemirror2": "^3.0.7", "react-dom": "16.2.0", "react-fuzzy-picker": "0.6.0", - "react-github-corner": "^2.0.0", + "react-github-corner": "^2.1.0", "stringify-object": "^3.2.1", "transform-css-to-js": "^0.1.1", "transform-graphql-type-annotations": "^0.1.1", "transform-json-types": "^0.3.0", "transform-svg-to-native": "^0.1.3", "unfetch": "^3.0.0", - "xml-js": "^1.6.1" + "xml-js": "^1.6.2" }, "devDependencies": { "all-contributors-cli": "^4.10.1", diff --git a/yarn.lock b/yarn.lock index ac7b842..344dfea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4598,9 +4598,9 @@ next-tick@1: version "1.0.0" resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" -next@4.2.1: - version "4.2.1" - resolved "https://registry.yarnpkg.com/next/-/next-4.2.1.tgz#37b5637050235b92a487ca484e20088ace7e37fe" +next@4.2.3: + version "4.2.3" + resolved "https://registry.yarnpkg.com/next/-/next-4.2.3.tgz#6f85f9bd6df2c420b4f6425f9f158e82515b7bc8" dependencies: ansi-html "0.0.7" babel-core "6.26.0" @@ -5714,9 +5714,9 @@ react-fuzzy-picker@0.6.0: fuzzysearch "^1.0.3" prop-types "^15.6.0" -react-github-corner@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/react-github-corner/-/react-github-corner-2.0.0.tgz#e248f9110afdc03a5e1168f95714795459b1b380" +react-github-corner@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/react-github-corner/-/react-github-corner-2.1.0.tgz#559363f5407e932db47e942f639d165e81827be4" react-hot-loader@3.1.1: version "3.1.1" @@ -7275,9 +7275,9 @@ xdg-basedir@^2.0.0: dependencies: os-homedir "^1.0.0" -xml-js@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.1.tgz#e94121bf73acf54126241fe7d913508f4cf49e90" +xml-js@^1.6.2: + version "1.6.2" + resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.2.tgz#4c4cb8413998f73701a202a1b8b2f17c985a72c5" dependencies: sax "^1.2.4" From b746e2837b7d4616276669ccd2f24c029e988929 Mon Sep 17 00:00:00 2001 From: ritz078 Date: Fri, 19 Jan 2018 21:50:19 +0530 Subject: [PATCH 02/20] closes #64, #65, #66 --- .all-contributorsrc | 9 +++++++++ package.json | 1 + pages/json-to-flow-types.js | 6 ++++-- pages/json-to-ts-interface.js | 9 ++++----- readme.md | 1 + utils/routes.js | 8 ++++++-- yarn.lock | 31 +++++++++++++++++++++++++++++++ 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5157058..687bc06 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -136,6 +136,15 @@ "contributions": [ "code" ] + }, + { + "login": "shakyShane", + "name": "Shane Osbourne", + "avatar_url": "https://avatars3.githubusercontent.com/u/1643522?v=4", + "profile": "https://medium.com/@shakyShane", + "contributions": [ + "code" + ] } ] } diff --git a/package.json b/package.json index 9e81a60..2ebbc54 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "is-svg": "^2.1.0", "json-schema-faker": "^0.5.0-rc11", "json-schema-to-typescript": "^4.6.5", + "json-ts": "^1.6.4", "lodash": "^4.17.4", "next": "4.2.3", "nprogress": "^0.2.0", diff --git a/pages/json-to-flow-types.js b/pages/json-to-flow-types.js index 311b530..da4c5ee 100644 --- a/pages/json-to-flow-types.js +++ b/pages/json-to-flow-types.js @@ -3,10 +3,11 @@ 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 { json2ts } from "json-ts"; +import PoweredBy from "../components/PoweredBy"; export default class Json2Ts extends PureComponent { - getTransformedValue = code => transform(code); + getTransformedValue = code => json2ts(code, { flow: true }); render() { return ( @@ -22,6 +23,7 @@ export default class Json2Ts extends PureComponent { url={this.props.url} prettifyRightPanel={false} /> + ); } diff --git a/pages/json-to-ts-interface.js b/pages/json-to-ts-interface.js index f14a220..6b50147 100644 --- a/pages/json-to-ts-interface.js +++ b/pages/json-to-ts-interface.js @@ -3,13 +3,11 @@ 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 { json2ts } from "json-ts"; +import PoweredBy from "../components/PoweredBy"; export default class Json2Ts extends PureComponent { - getTransformedValue = code => - transform(code, { - lang: "typescript" - }); + getTransformedValue = code => json2ts(code); render() { return ( @@ -25,6 +23,7 @@ export default class Json2Ts extends PureComponent { url={this.props.url} prettifyRightPanel={false} /> + ); } diff --git a/readme.md b/readme.md index db642bf..e5e9b33 100644 --- a/readme.md +++ b/readme.md @@ -50,6 +50,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds | [
Ritesh Kumar](http://riteshkr.com)
[📖](https://github.com/ritz078/transform-www/commits?author=ritz078 "Documentation") [💻](https://github.com/ritz078/transform-www/commits?author=ritz078 "Code") [🤔](#ideas-ritz078 "Ideas, Planning, & Feedback") [👀](#review-ritz078 "Reviewed Pull Requests") | [
Florian Gilcher](http://asquera.de)
[💻](https://github.com/ritz078/transform-www/commits?author=skade "Code") | [
Pascal Hertleif](http://pascalhertleif.de/)
[💻](https://github.com/ritz078/transform-www/commits?author=killercup "Code") | [
Lado Lomidze](http://landish.github.io)
[💻](https://github.com/ritz078/transform-www/commits?author=Landish "Code") | [
Mattia Manzati](https://github.com/mattiamanzati)
[💻](https://github.com/ritz078/transform-www/commits?author=mattiamanzati "Code") | [
Mohammad Rajabifard](https://tarino.ir)
[🤔](#ideas-morajabi "Ideas, Planning, & Feedback") [💻](https://github.com/ritz078/transform-www/commits?author=morajabi "Code") | [
Raathigeshan Kugarajan](http://raathigesh.com/)
[💻](https://github.com/ritz078/transform-www/commits?author=Raathigesh "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Gyandeep Singh](https://gyandeeps.com)
[💻](https://github.com/ritz078/transform-www/commits?author=gyandeeps "Code") | [
Matt Holt](https://matt.life)
[💻](https://github.com/ritz078/transform-www/commits?author=mholt "Code") | [
sreenivas alapati](https://medium.com/@sreenivas)
[💻](https://github.com/ritz078/transform-www/commits?author=cg-cnu "Code") | [
Boris Cherny](https://performancejs.com)
[💻](https://github.com/ritz078/transform-www/commits?author=bcherny "Code") | [
Mark Lussier](http://www.twitter.com/intabulas)
[💻](https://github.com/ritz078/transform-www/commits?author=intabulas "Code") | [
Brice BERNARD](https://github.com/brikou)
[💻](https://github.com/ritz078/transform-www/commits?author=brikou "Code") | [
Satyajit Sahoo](https://twitter.com/@satya164)
[💻](https://github.com/ritz078/transform-www/commits?author=satya164 "Code") | +| [
Shane Osbourne](https://medium.com/@shakyShane)
[💻](https://github.com/ritz078/transform-www/commits?author=shakyShane "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! diff --git a/utils/routes.js b/utils/routes.js index c2cad11..bc10893 100644 --- a/utils/routes.js +++ b/utils/routes.js @@ -90,13 +90,17 @@ export const categorizedRoutes = [ { label: "JSON to Flow Types", path: "/json-to-flow-types", - desc: "An online REPL for converting JSON to generate Flow Types." + desc: "An online REPL for converting JSON to generate Flow Types.", + packageName: "json-ts", + packageUrl: "https://github.com/shakyShane/json-ts" }, { 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.", + packageName: "json-ts", + packageUrl: "https://github.com/shakyShane/json-ts" }, { label: "JSON to MobX-State-Tree Model", diff --git a/yarn.lock b/yarn.lock index 344dfea..4ace141 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3010,6 +3010,10 @@ get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" +get-stdin@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -3493,6 +3497,10 @@ immediate@~3.0.5: version "3.0.6" resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" +immutable@^3.8.1: + version "3.8.2" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3" + import-from@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-from/-/import-from-2.1.0.tgz#335db7f2a7affd53aaa471d4b8021dee36b7f3b1" @@ -3976,6 +3984,17 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" +json-ts@^1.6.4: + version "1.6.4" + resolved "https://registry.yarnpkg.com/json-ts/-/json-ts-1.6.4.tgz#e4423b8ccdb3069306f4727d6a579790675abbd0" + dependencies: + get-stdin "^5.0.1" + immutable "^3.8.1" + minimist "^1.2.0" + needsquotes "^1.0.0" + transducers-js "^0.4.174" + typescript "^2.3.2" + json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" @@ -4582,6 +4601,10 @@ ncp@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3" +needsquotes@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/needsquotes/-/needsquotes-1.0.0.tgz#f54f90ff2ad3f5c1fc90236804639f849b924fad" + negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" @@ -6796,6 +6819,10 @@ tough-cookie@~2.3.0, tough-cookie@~2.3.3: dependencies: punycode "^1.4.1" +transducers-js@^0.4.174: + version "0.4.174" + resolved "https://registry.yarnpkg.com/transducers-js/-/transducers-js-0.4.174.tgz#d5862c10eff4be3d3322abf6bb742e30f1bb6fc4" + transform-css-to-js@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/transform-css-to-js/-/transform-css-to-js-0.1.1.tgz#20fd40b137849555c063aa55f168680ad00724bb" @@ -6906,6 +6933,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" +typescript@^2.3.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4" + ua-parser-js@^0.7.9: version "0.7.17" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac" From 043f9bdf690777512ef292781f12b8c8b03f6a38 Mon Sep 17 00:00:00 2001 From: ritz078 Date: Sun, 21 Jan 2018 23:00:39 +0530 Subject: [PATCH 03/20] closes #65, closes #66 --- components/ConversionPanel.js | 4 ++++ pages/json-to-flow-types.js | 4 +--- pages/json-to-ts-interface.js | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js index 0f318bb..1825690 100644 --- a/components/ConversionPanel.js +++ b/components/ConversionPanel.js @@ -320,6 +320,10 @@ export default class ConversionPanel extends PureComponent { return (
+