From 47ab6022052115dd09a1a690218b05222a35f88b Mon Sep 17 00:00:00 2001 From: Vinay Date: Tue, 10 Jul 2018 23:52:21 +0800 Subject: [PATCH] use prettier --- package.json | 2 ++ src/actions.js | 4 ++-- src/context.js | 2 +- src/index.js | 7 +------ src/provider.js | 33 ++++++++++++++++++++------------- src/reducer.js | 4 ++-- src/utils.js | 8 ++++---- src/withTranslate.js | 14 ++++++++------ 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 75b637b..89479c6 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A simple multilingual translate component and HOC for react and redux", "main": "lib/index.js", "scripts": { + "prettier": "prettier --single-quote --no-semi 'src/*.js' --write", "watch": "BABEL_ENV=production babel --watch src --out-dir lib" }, "repository": { @@ -23,6 +24,7 @@ "homepage": "https://github.com/rmdort/react-redux-multilingual#readme", "dependencies": { "hoist-non-react-statics": "^1.2.0", + "prettier-standard": "^8.0.1", "prop-types": "^15.5.8" }, "peerDependencies": { diff --git a/src/actions.js b/src/actions.js index 122b2ca..848ca74 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,6 +1,6 @@ -export function setLocale (locale) { +export function setLocale(locale) { return { type: 'SET_LOCALE', locale } -} \ No newline at end of file +} diff --git a/src/context.js b/src/context.js index 88b7749..f5ec412 100644 --- a/src/context.js +++ b/src/context.js @@ -7,4 +7,4 @@ const { } = TranslateContext export { TranslateProvider, TranslateConsumer } -export default TranslateContext \ No newline at end of file +export default TranslateContext diff --git a/src/index.js b/src/index.js index c5e4aa2..5ac1663 100644 --- a/src/index.js +++ b/src/index.js @@ -3,9 +3,4 @@ import withTranslate from './withTranslate' import IntlProvider from './provider' import * as IntlActions from './actions' -export { - IntlReducer, - withTranslate, - IntlProvider, - IntlActions -} \ No newline at end of file +export { IntlReducer, withTranslate, IntlProvider, IntlActions } diff --git a/src/provider.js b/src/provider.js index 360c299..0dd10a0 100644 --- a/src/provider.js +++ b/src/provider.js @@ -5,21 +5,28 @@ import { supplant, translateKey, createHTMLMarkup } from './utils' import { TranslateProvider } from './context' class IntlProvider extends React.Component { - constructor (props) { + constructor(props) { super(props) if (!props.translations || !props.locale) { - let namePart = this.constructor.displayName ? ' of ' + this.constructor.displayName : '' - throw new Error('Could not find translations or locale on this.props ' + namePart) + let namePart = this.constructor.displayName + ? ' of ' + this.constructor.displayName + : '' + throw new Error( + 'Could not find translations or locale on this.props ' + namePart + ) } } static propTypes = { translations: PropTypes.object - }; + } static defaultProps = { translations: {} - }; + } translate = (key, placeholders, isHTML, options = {}) => { - const result = translateKey(key, this.props.translations[this.props.locale]['messages']) + const result = translateKey( + key, + this.props.translations[this.props.locale]['messages'] + ) const tagName = options.tagName || 'div' if (typeof placeholders === 'undefined') { return result @@ -27,13 +34,13 @@ class IntlProvider extends React.Component { const finalResult = supplant(result, placeholders) return isHTML ? React.createElement( - tagName, - { dangerouslySetInnerHTML: createHTMLMarkup(finalResult) }, - null - ) + tagName, + { dangerouslySetInnerHTML: createHTMLMarkup(finalResult) }, + null + ) : finalResult - }; - render () { + } + render() { return ( {this.props.children} @@ -42,7 +49,7 @@ class IntlProvider extends React.Component { } } -function mapPropsToState (state) { +function mapPropsToState(state) { const { Intl } = state return { ...Intl, diff --git a/src/reducer.js b/src/reducer.js index fdb6e22..0fd8ef3 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -2,7 +2,7 @@ var initialState = { locale: 'en' } -export default function (state = initialState, action) { +export default function(state = initialState, action) { switch (action.type) { case 'SET_LOCALE': return { @@ -12,4 +12,4 @@ export default function (state = initialState, action) { default: return state } -} \ No newline at end of file +} diff --git a/src/utils.js b/src/utils.js index 02b0553..84ce3a4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,16 +1,16 @@ -export function supplant (s, d) { +export function supplant(s, d) { for (var p in d) { s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]) } return s } -export function translateKey (path, obj, safe) { +export function translateKey(path, obj, safe) { return path.split('.').reduce((prev, curr) => { - return !safe ? prev[curr] : (prev ? prev[curr] : undefined) + return !safe ? prev[curr] : prev ? prev[curr] : undefined }, obj) } -export function createHTMLMarkup (html) { +export function createHTMLMarkup(html) { return { __html: html } } diff --git a/src/withTranslate.js b/src/withTranslate.js index 7239743..724e703 100644 --- a/src/withTranslate.js +++ b/src/withTranslate.js @@ -6,12 +6,14 @@ import { TranslateConsumer } from './context' * @param {Object} WrappedComponent * @return {Object} */ -function withTranslate (WrappedComponent) { - return React.forwardRef((props, ref) => ( - - {(translate) => } +function withTranslate(WrappedComponent) { + return React.forwardRef((props, ref) => ( + + {translate => ( + + )} - )) + )) } -export default withTranslate \ No newline at end of file +export default withTranslate