diff --git a/.gitignore b/.gitignore
index d34af98..48a2108 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
node_modules
-.idea
\ No newline at end of file
+.idea
+
+yarn-error.log
\ No newline at end of file
diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js
new file mode 100644
index 0000000..9daea76
--- /dev/null
+++ b/components/ConversionPanel.js
@@ -0,0 +1,227 @@
+import React, { PureComponent } from 'react'
+import PropTypes from 'prop-types'
+import isBrowser from 'is-in-browser'
+import { transform } from 'babel-standalone'
+import store from 'store2'
+import {js_beautify} from 'js-beautify'
+import copy from 'copy-text-to-clipboard'
+import Head from 'next/head'
+import Layout from '../components/Layout'
+
+let brace
+let AceEditor
+if (isBrowser) {
+ brace = require('brace').default
+ AceEditor = require('react-ace').default
+ require('brace/mode/javascript')
+ require('brace/theme/tomorrow')
+}
+
+
+
+export default class ConversionPanel extends PureComponent {
+ static propTypes = {
+ plugin: PropTypes.func.isRequired,
+ name: PropTypes.string.isRequired,
+ leftMode: PropTypes.string,
+ rightMode: PropTypes.string
+ }
+
+ static defaultProps = {
+ leftMode: 'javascript',
+ rightMode: 'javascript'
+ }
+
+ constructor (props) {
+ super(props)
+
+ this.state = {
+ resultValue: '',
+ value: '',
+ info: ''
+ }
+ }
+
+ componentDidMount() {
+ this.setState({
+ value: store(`${name}_code`) || this.props.defaultText,
+ resultValue: store(`${name}_result`) || this.props.getTransformedValue(this.props.defaultText)
+ })
+ }
+
+ onChange = (newValue) => {
+ const {name} = this.props;
+
+ try {
+ const code = this.props.getTransformedValue(newValue)
+
+ this.setState({
+ resultValue: code,
+ info: ''
+ })
+
+ store(`${name}_code`, newValue)
+ store(`${name}_result`, code)
+ } catch (e) {
+ this.setState({
+ info: e.message
+ })
+ }
+
+ this.setState({
+ value: newValue
+ })
+ }
+
+ prettifyCode = () => {
+ this.setState({
+ value: js_beautify(this.state.value)
+ })
+ }
+
+ copyCode = () => {
+ copy(this.state.resultValue)
+ this.setState({
+ info: 'Code copied to clipboard.'
+ })
+ }
+
+ render () {
+ return (
+
+
+
+
Transform | Convert an object to propTypes
+
+
+
+
+
+
+
+
+ {isBrowser &&
+
+ }
+
+
+
+
+ {isBrowser &&
+
+ }
+
+
+
+
+ {this.state.info}
+
+
+
+ )
+ }
+}
diff --git a/components/Layout.js b/components/Layout.js
new file mode 100644
index 0000000..6557d3a
--- /dev/null
+++ b/components/Layout.js
@@ -0,0 +1,95 @@
+import React from 'react'
+import isBrowser from 'is-in-browser'
+import Link from 'next/link'
+
+function isActiveRoute (routeName) {
+ if (isBrowser) {
+ return window.location.pathname === routeName
+ }
+}
+
+function Logo () {
+ return (
+
+ )
+}
+
+export default function ({children}) {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/next.config.js b/next.config.js
index ab1335b..3b72583 100644
--- a/next.config.js
+++ b/next.config.js
@@ -2,6 +2,10 @@ module.exports = {
webpack: (config, { dev }) => {
config.plugins = config.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin');
+ config.node = {
+ fs: 'empty'
+ }
+
return config;
}
};
\ No newline at end of file
diff --git a/package.json b/package.json
index 953fa16..ed201d1 100644
--- a/package.json
+++ b/package.json
@@ -19,9 +19,12 @@
"js-beautify": "^1.6.14",
"lodash": "^4.17.4",
"next": "^2.4.3",
+ "prop-types": "^15.5.10",
"react": "^15.6.0",
"react-ace": "^5.0.1",
+ "react-alert": "^2.1.2",
"react-dom": "^15.6.0",
+ "react-toastify": "^1.7.0",
"store2": "^2.5.1"
}
}
diff --git a/pages/index.js b/pages/index.js
index 99a3612..03801a8 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -1,23 +1,13 @@
-import React, { PureComponent } from 'react'
-import isBrowser from 'is-in-browser'
+import React, {PureComponent} from 'react'
import { transform } from 'babel-standalone'
-import store from 'store2'
-import {js_beautify} from 'js-beautify'
-import copy from 'copy-text-to-clipboard'
import plugin from '../utils/plugin'
+import ConversionPanel from '../components/ConversionPanel'
-let brace
-let AceEditor
-if (isBrowser) {
- brace = require('brace').default
- AceEditor = require('react-ace').default
- require('brace/mode/javascript')
- require('brace/theme/tomorrow')
-}
-
-const defaultText = `
-// Enter the object you want to convert in the following form
+const defaultText = `// Enter the object you want to convert in the
+// following form
+//
// const x = your_object
+//
// You need to assign your object to a variable (for now.)
const x = {
@@ -27,193 +17,21 @@ const x = {
`
export default class Main extends PureComponent {
- constructor (props) {
- super(props)
-
- this.state = {
- resultValue: '',
- value: '',
- error: ''
- }
- }
-
- componentDidMount() {
- this.setState({
- value: store('code') || defaultText,
- resultValue: store('result') || this.getTransformedValue(defaultText).code
- })
- }
-
getTransformedValue = (newValue) => {
- return transform(newValue, {
+ const { code } = transform(newValue, {
presets: ['es2015'],
plugins: [plugin]
})
+ return code
}
- onChange = (newValue) => {
- try {
- const {code, ast} = this.getTransformedValue(newValue)
-
- this.setState({
- resultValue: code,
- error: ''
- })
-
- store('code', newValue)
- store('result', code)
- } catch (e) {
- this.setState({
- error: e.message
- })
- }
-
- this.setState({
- value: newValue
- })
- }
-
- prettifyCode = () => {
- this.setState({
- value: js_beautify(this.state.value)
- })
- }
-
- copyCode = () => {
- copy(this.state.resultValue)
- }
-
- render () {
+ render() {
return (
-
-
- Object to PropTypes
-
-
-
-
-
-
-
- {isBrowser &&
-
- }
-
-
-
-
- {isBrowser &&
-
- }
-
-
-
-
- {this.state.error ?
{this.state.error} :
Created by Ritesh Kumar}
-
-
+
)
}
}
diff --git a/utils/plugin.js b/utils/plugin.js
index 8881e9d..a7ecc0d 100644
--- a/utils/plugin.js
+++ b/utils/plugin.js
@@ -1,5 +1,10 @@
import {uniqBy, isEmpty} from 'lodash'
+/**
+ * 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}) {
return {
visitor: {
@@ -46,7 +51,7 @@ export default function ({types: t}) {
path.replaceWith(t.identifier('PropTypes.bool'))
},
- Program(path, state) {
+ Program(path) {
path.traverse({
enter(path) {
t.removeComments(path.node);
diff --git a/yarn.lock b/yarn.lock
index 9603d93..dece694 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -881,6 +881,10 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"
+brcast@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/brcast/-/brcast-2.0.0.tgz#9e627ab82209895664c1d6c1f45cd8c43422e3f6"
+
brorand@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
@@ -990,6 +994,10 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"
+chain-function@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"
+
chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -1269,6 +1277,10 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0"
randombytes "^2.0.0"
+dom-helpers@^3.2.0:
+ version "3.2.1"
+ resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.2.1.tgz#3203e07fed217bd1f424b019735582fc37b2825a"
+
dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
@@ -1419,7 +1431,11 @@ extsprintf@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550"
-fbjs@^0.8.9:
+fast-memoize@^2.2.7:
+ version "2.2.7"
+ resolved "https://registry.yarnpkg.com/fast-memoize/-/fast-memoize-2.2.7.tgz#f145c5c22039cedf0a1d4ff6ca592ad0268470ca"
+
+fbjs@^0.8.8, fbjs@^0.8.9:
version "0.8.12"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"
dependencies:
@@ -1568,6 +1584,25 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
+glamor@^2.20.24:
+ version "2.20.25"
+ resolved "https://registry.yarnpkg.com/glamor/-/glamor-2.20.25.tgz#71b84b82b67a9327771ac59de53ee915d148a4a3"
+ dependencies:
+ babel-runtime "^6.18.0"
+ fbjs "^0.8.8"
+ object-assign "^4.1.0"
+ prop-types "^15.5.8"
+
+glamorous@^3.13.1:
+ version "3.23.3"
+ resolved "https://registry.yarnpkg.com/glamorous/-/glamorous-3.23.3.tgz#4f64b8e3fab01bf9e51d50564955a0b8fdecb0fe"
+ dependencies:
+ brcast "^2.0.0"
+ fast-memoize "^2.2.7"
+ html-tag-names "^1.1.1"
+ react-html-attributes "^1.3.0"
+ svg-tag-names "^1.1.0"
+
glob-base@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"
@@ -1705,10 +1740,18 @@ hosted-git-info@^2.1.4:
version "2.4.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"
+html-element-attributes@^1.0.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/html-element-attributes/-/html-element-attributes-1.2.0.tgz#8b1c7aaf94353fd9b455c27ec7ebaf1583e29fd0"
+
html-entities@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
+html-tag-names@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/html-tag-names/-/html-tag-names-1.1.1.tgz#f8a076113f16e393518937f6b3b5d22296755d4a"
+
htmlescape@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/htmlescape/-/htmlescape-1.1.1.tgz#3a03edc2214bca3b66424a3e7959349509cb0351"
@@ -2639,7 +2682,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"
-prop-types@15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@~15.5.7:
+prop-types@15.5.10, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@~15.5.7:
version "15.5.10"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
dependencies:
@@ -2724,6 +2767,15 @@ react-ace@^5.0.1:
opencollective "^1.0.3"
prop-types "^15.5.8"
+react-alert@^2.1.2:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/react-alert/-/react-alert-2.1.2.tgz#fc8a5d03a13561e02b92979a104338d999bf11de"
+ dependencies:
+ glamor "^2.20.24"
+ glamorous "^3.13.1"
+ react-transition-group "^1.1.2"
+ shortid "^2.2.8"
+
react-deep-force-update@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.0.1.tgz#4f7f6c12c3e7de42f345992a3c518236fa1ecad3"
@@ -2748,12 +2800,35 @@ react-hot-loader@3.0.0-beta.7:
redbox-react "^1.3.6"
source-map "^0.4.4"
+react-html-attributes@^1.3.0:
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/react-html-attributes/-/react-html-attributes-1.3.0.tgz#c97896e9cac47ad9c4e6618b835029a826f5d28c"
+ dependencies:
+ html-element-attributes "^1.0.0"
+
react-proxy@^3.0.0-alpha.0:
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-3.0.0-alpha.1.tgz#4400426bcfa80caa6724c7755695315209fa4b07"
dependencies:
lodash "^4.6.1"
+react-toastify@^1.7.0:
+ version "1.7.0"
+ resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-1.7.0.tgz#8731c37e5000ddb33eed40fd10951e0451c5f9d0"
+ dependencies:
+ prop-types "^15.5.8"
+ react-transition-group "^1.1.2"
+
+react-transition-group@^1.1.2:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.0.tgz#b51fc921b0c3835a7ef7c571c79fc82c73e9204f"
+ dependencies:
+ chain-function "^1.0.0"
+ dom-helpers "^3.2.0"
+ loose-envify "^1.3.1"
+ prop-types "^15.5.6"
+ warning "^3.0.0"
+
react@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.0.tgz#c23299b48e30ed302508ce89e1a02c919f826bce"
@@ -3013,6 +3088,10 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
+shortid@^2.2.8:
+ version "2.2.8"
+ resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.8.tgz#033b117d6a2e975804f6f0969dbe7d3d0b355131"
+
sigmund@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
@@ -3202,6 +3281,10 @@ supports-color@^3.1.0:
dependencies:
has-flag "^1.0.0"
+svg-tag-names@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/svg-tag-names/-/svg-tag-names-1.1.0.tgz#24c04db37f2ee2ee28bc619f4e8a25ee21fc0203"
+
tapable@^0.2.5, tapable@~0.2.5:
version "0.2.6"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
@@ -3362,6 +3445,12 @@ w3c-blob@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/w3c-blob/-/w3c-blob-0.0.1.tgz#b0cd352a1a50f515563420ffd5861f950f1d85b8"
+warning@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
+ dependencies:
+ loose-envify "^1.0.0"
+
watchpack@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.3.1.tgz#7d8693907b28ce6013e7f3610aa2a1acf07dad87"