diff --git a/.all-contributorsrc b/.all-contributorsrc index 41cf41d..13f196e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -100,6 +100,15 @@ "contributions": [ "code" ] + }, + { + "login": "bcherny", + "name": "Boris Cherny", + "avatar_url": "https://avatars2.githubusercontent.com/u/1761758?v=4", + "profile": "https://performancejs.com", + "contributions": [ + "code" + ] } ] } diff --git a/package.json b/package.json index f5e2486..bdc65e5 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "is-in-browser": "^1.1.3", "is-svg": "^2.1.0", "js-beautify": "^1.6.14", + "json-schema-to-typescript": "^4.6.0", "lodash": "^4.17.4", "next": "^3.2.1", "nprogress": "^0.2.0", diff --git a/pages/json-schema-to-ts.js b/pages/json-schema-to-ts.js new file mode 100644 index 0000000..34cd567 --- /dev/null +++ b/pages/json-schema-to-ts.js @@ -0,0 +1,54 @@ +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', + type: 'object', + properties: { + firstName: { + type: 'string' + }, + lastName: { + type: 'string' + }, + age: { + description: 'Age in years', + type: 'integer', + minimum: 0 + }, + height: { + type: 'number' + }, + favoriteFoods: { + type: 'array' + }, + likesDogs: { + type: 'boolean' + } + }, + required: ['firstName', 'lastName'] +}` + +export default class Json2Ts extends PureComponent { + getTransformedValue = code => compile(eval('(' + code + ')')) + + render() { + return ( + + + + ); + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index c80fc99..5092de5 100644 --- a/readme.md +++ b/readme.md @@ -48,7 +48,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") | +| [
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") | 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 a533a82..d19a05f 100644 --- a/utils/routes.js +++ b/utils/routes.js @@ -83,6 +83,11 @@ export const categorizedRoutes = [ 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", + desc: "An online REPL for converting JSON Schema to TypeScript Interface." } ] }, diff --git a/yarn.lock b/yarn.lock index 61c8a55..cf49539 100644 --- a/yarn.lock +++ b/yarn.lock @@ -96,7 +96,7 @@ ansi-html@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e" -ansi-regex@^2.0.0: +ansi-regex@^2.0.0, ansi-regex@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" @@ -1243,6 +1243,10 @@ builtin-status-codes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" +call-me-maybe@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b" + camel-case@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-3.0.0.tgz#ca3c3688a4e9cf3a4cda777dc4dcbc713249cf73" @@ -1390,6 +1394,17 @@ cli-boxes@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143" +cli-color@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/cli-color/-/cli-color-1.2.0.tgz#3a5ae74fd76b6267af666e69e2afbbd01def34d1" + dependencies: + ansi-regex "^2.1.1" + d "1" + es5-ext "^0.10.12" + es6-iterator "2" + memoizee "^0.4.3" + timers-ext "0.1" + cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -1487,16 +1502,16 @@ combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" +commander@^2.7.1, commander@~2.11.0: + version "2.11.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563" + commander@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" dependencies: graceful-readlink ">= 1.0.0" -commander@~2.11.0: - version "2.11.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563" - commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" @@ -1823,6 +1838,12 @@ debug@^2.1.1: dependencies: ms "2.0.0" +debug@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.0.1.tgz#0564c612b521dc92d9f2988f0549e34f9c98db64" + dependencies: + ms "2.0.0" + decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -2065,6 +2086,13 @@ error-stack-parser@^2.0.0: dependencies: stackframe "^1.0.3" +es5-ext@^0.10.12, es5-ext@^0.10.30, es5-ext@~0.10.2: + version "0.10.30" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.30.tgz#7141a16836697dbabfaaaeee41495ce29f52c939" + dependencies: + es6-iterator "2" + es6-symbol "~3.1" + es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: version "0.10.26" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.26.tgz#51b2128a531b70c4f6764093a73cbebb82186372" @@ -2091,7 +2119,7 @@ es6-map@^0.1.3: es6-symbol "~3.1.1" event-emitter "~0.3.5" -es6-promise@^4.0.5: +es6-promise@^4.0.5, es6-promise@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.1.1.tgz#8811e90915d9a0dba36274f0b242dbda78f9c92a" @@ -2112,7 +2140,7 @@ es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbo d "1" es5-ext "~0.10.14" -es6-weak-map@^2.0.1: +es6-weak-map@^2.0.1, es6-weak-map@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.2.tgz#5e3ab32251ffd1538a1f8e5ffa1357772f92d96f" dependencies: @@ -2142,6 +2170,10 @@ esprima@^2.6.0: version "2.7.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" +esprima@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804" + esrecurse@^4.1.0: version "4.2.0" resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.0.tgz#fa9568d98d3823f9a41d91e902dcab9ea6e5b163" @@ -2161,7 +2193,7 @@ etag@1.8.0, etag@~1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.0.tgz#6f631aef336d6c46362b51764044ce216be3c051" -event-emitter@~0.3.5: +event-emitter@^0.3.5, event-emitter@~0.3.5: version "0.3.5" resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" dependencies: @@ -2383,6 +2415,10 @@ form-data@~2.1.1: combined-stream "^1.0.5" mime-types "^2.1.12" +format-util@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.3.tgz#032dca4a116262a12c43f4c3ec8566416c5b2d95" + forwarded@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.0.tgz#19ef9874c4ae1c297bcf078fde63a09b66a84363" @@ -3009,7 +3045,7 @@ is-primitive@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" -is-promise@^2.1.0: +is-promise@^2.1, is-promise@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa" @@ -3103,6 +3139,13 @@ js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" +js-yaml@^3.9.1: + version "3.9.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.9.1.tgz#08775cebdfdd359209f0d2acd383c8f86a6904a0" + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + js-yaml@~3.7.0: version "3.7.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" @@ -3144,6 +3187,29 @@ json-loader@0.5.4, json-loader@^0.5.4: version "0.5.4" resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.4.tgz#8baa1365a632f58a3c46d20175fc6002c96e37de" +json-schema-ref-parser@^3.1.2: + version "3.3.1" + resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-3.3.1.tgz#86e751b8099357bf601a7cfe42d10123ee906a32" + dependencies: + call-me-maybe "^1.0.1" + debug "^3.0.0" + es6-promise "^4.1.1" + js-yaml "^3.9.1" + ono "^4.0.2" + z-schema "^3.18.2" + +json-schema-to-typescript@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/json-schema-to-typescript/-/json-schema-to-typescript-4.6.0.tgz#a2455325253e0d17bb4a31d10a51fcb188e48f79" + dependencies: + cli-color "^1.2.0" + json-schema-ref-parser "^3.1.2" + json-stringify-safe "^5.0.1" + lodash "^4.17.4" + minimist "^1.2.0" + mz "^2.6.0" + stdin "0.0.1" + json-schema-traverse@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" @@ -3158,7 +3224,7 @@ json-stable-stringify@^1.0.1: dependencies: jsonify "~0.0.0" -json-stringify-safe@~5.0.1: +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" @@ -3275,6 +3341,14 @@ lodash.defaults@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c" +lodash.get@^4.0.0: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + +lodash.isequal@^4.0.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" + lodash.isplainobject@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" @@ -3352,6 +3426,12 @@ lru-cache@^4.0.1: pseudomap "^1.0.2" yallist "^2.1.2" +lru-queue@0.1: + version "0.1.0" + resolved "https://registry.yarnpkg.com/lru-queue/-/lru-queue-0.1.0.tgz#2738bd9f0d3cf4f84490c5736c48699ac632cda3" + dependencies: + es5-ext "~0.10.2" + macaddress@^0.2.8: version "0.2.8" resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12" @@ -3393,6 +3473,19 @@ mem@^1.1.0: dependencies: mimic-fn "^1.0.0" +memoizee@^0.4.3: + version "0.4.9" + resolved "https://registry.yarnpkg.com/memoizee/-/memoizee-0.4.9.tgz#ea1c005f5c4c31d89a4a10e24db83fbf61cdd4f3" + dependencies: + d "1" + es5-ext "^0.10.30" + es6-weak-map "^2.0.2" + event-emitter "^0.3.5" + is-promise "^2.1" + lru-queue "0.1" + next-tick "1" + timers-ext "^0.1.2" + memory-fs@^0.4.0, memory-fs@~0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552" @@ -3527,7 +3620,7 @@ mv@2.1.1: ncp "~2.0.0" rimraf "~2.4.0" -mz@2.6.0: +mz@2.6.0, mz@^2.6.0: version "2.6.0" resolved "https://registry.yarnpkg.com/mz/-/mz-2.6.0.tgz#c8b8521d958df0a4f2768025db69c719ee4ef1ce" dependencies: @@ -3547,6 +3640,10 @@ negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" +next-tick@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" + next@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/next/-/next-3.2.1.tgz#6d694823ac6e74e9be4553117144a6402220490f" @@ -3796,6 +3893,12 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" +ono@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/ono/-/ono-4.0.2.tgz#2e18ff7c21b9eac0cab794f7a3082507000d6d36" + dependencies: + format-util "^1.0.3" + opener@^1.4.3: version "1.4.3" resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8" @@ -4998,6 +5101,10 @@ stackframe@^1.0.3: version "1.3.1" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" +stdin@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/stdin/-/stdin-0.0.1.tgz#d3041981aaec3dfdbc77a1b38d6372e38f5fb71e" + stream-browserify@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db" @@ -5252,6 +5359,13 @@ timers-browserify@^2.0.2: global "^4.3.2" setimmediate "^1.0.4" +timers-ext@0.1, timers-ext@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/timers-ext/-/timers-ext-0.1.2.tgz#61cc47a76c1abd3195f14527f978d58ae94c5204" + dependencies: + es5-ext "~0.10.14" + next-tick "1" + title-case@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/title-case/-/title-case-2.1.1.tgz#3e127216da58d2bc5becf137ab91dae3a7cd8faa" @@ -5497,6 +5611,10 @@ validate-npm-package-license@^3.0.1: spdx-correct "~1.0.0" spdx-expression-parse "~1.0.0" +validator@^8.0.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-8.1.0.tgz#89cf6b512ff71eba886afd8d10d47f8dc800eac0" + vary@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37" @@ -5802,3 +5920,13 @@ yargs@~3.10.0: cliui "^2.1.0" decamelize "^1.0.0" window-size "0.1.0" + +z-schema@^3.18.2: + version "3.18.3" + resolved "https://registry.yarnpkg.com/z-schema/-/z-schema-3.18.3.tgz#45592990891d0342fe20a36823fc44d89ab4d8a2" + dependencies: + lodash.get "^4.0.0" + lodash.isequal "^4.0.0" + validator "^8.0.0" + optionalDependencies: + commander "^2.7.1"