Permalink
Browse files

More lint + add lodash

  • Loading branch information...
JeremDsgn committed Apr 1, 2017
1 parent 7bd6f08 commit f20f661c080dfc068f373e159c37e752a44ec3a7
View
@@ -13,25 +13,26 @@
"*.{js,jsx}": "./node_modules/.bin/eslint"
},
"dependencies": {
- "moment": "^2.18.1",
+ "moment": "2.18.1",
"react": "15.4.2",
- "react-native": "^0.42.3",
- "react-native-router-flux": "^3.38.0",
- "react-native-vector-icons": "^4.0.0"
+ "react-native": "0.42.3",
+ "react-native-router-flux": "3.38.0",
+ "react-native-vector-icons": "4.0.0"
},
"devDependencies": {
- "babel-eslint": "^7.2.1",
+ "babel-eslint": "7.2.1",
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
- "eslint": "^3.18.0",
+ "eslint": "3.18.0",
"eslint-config-airbnb": "14.1.0",
"eslint-import-resolver-webpack": "0.8.1",
- "eslint-plugin-flowtype": "^2.30.4",
+ "eslint-plugin-flowtype": "2.30.4",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "4.0.0",
- "eslint-plugin-react": "^6.10.3",
+ "eslint-plugin-react": "6.10.3",
"jest": "19.0.2",
"lint-staged": "3.4.0",
+ "lodash": "4.17.4",
"pre-commit": "1.2.2",
"react-test-renderer": "15.4.2"
},
@@ -78,6 +78,6 @@ export default ApiUtils = {
return {
state: 'success',
data: objNetwork,
- }
+ };
},
};
View
@@ -1,25 +1,19 @@
/**
* Function to check is the username is stored before submiting with api request
-*/
+*
function isUsernameStore(input, store, network) {
- const valuedStored = (store !== '') ? ((store[network] !== '') ? store[network].data.user.Username : undefined) : undefined;
- return (input !== undefined && input !== valuedStored);
-}
+ const isExist = store[network] !== '' ? store[network].data.user.Username : undefined;
+ const valuedStored = store !== '' ? isExist : undefined;
-/**
-* Function to check if the data contained in a declared variable exists
-*/
-export function dataIsEmpty(data) {
- let arrayIntoArray = (data instanceof Array) ? data.filter(array => !dataIsEmpty(array)).length === 0 : false;
- return (data === undefined || data === null || data.length === 0 || arrayIntoArray);
+ return input !== undefined && input !== valuedStored;
}
/**
* Return the ratio of a division of two number
*/
export function ratio(a, b) {
- let x = Number(a);
- let y = Number(b);
+ const x = Number(a);
+ const y = Number(b);
if (x > y) {
return `${Math.ceil(x / y)}:1`;
@@ -29,7 +23,8 @@ export function ratio(a, b) {
}
/**
-* Some API return html tag in their response (e.g. dribbble about key return <a href="#"></a> for link add)
+* Some API return html tag in their response
+* (e.g. dribbble about key return <a href="#"></a> for link add)
*/
export function removeTag(s) {
return s.replace(/(<(?:.|\n)*?>)/g, '');
@@ -60,24 +55,24 @@ export function capitalize(s) {
* Formatting big numbers
*/
export function format(nbr) {
- return (nbr + '').replace(/.(?=(?:.{3})+$)/g, '$& ');
+ return String(nbr).replace(/.(?=(?:.{3})+$)/g, '$& ');
}
/**
* Converts a single hex number to a character
* Note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc
*/
export function hex2char(hex) {
- var result = '';
- var n = parseInt(hex, 16);
+ let result = '';
+ let n = parseInt(hex, 16);
if (n <= 0xFFFF) {
result += String.fromCharCode(n);
} else if (n <= 0x10FFFF) {
- n -= 0x10000
- result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF));
+ n -= 0x10000;
+ result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF)); // eslint-disable-line
} else {
- result += 'hex2Char error: Code point out of range: ' + dec2hex(n);
+ result += `hex2Char error: Code point out of range: dec2hex(${n})`;
}
return result;
@@ -87,28 +82,26 @@ export function hex2char(hex) {
* Converts a string containing JavaScript escapes to a string of characters - unicode UTF-8 ready
*/
export function decode(str, shortEscapes) {
+ let strToDecode = str;
+
// convert \U and 6 digit escapes to characters
- str = str.replace(/\\U([A-Fa-f0-9]{8})/g, (matchstr, parens) => {
- return hex2char(parens);
- });
+ strToDecode = strToDecode.replace(/\\U([A-Fa-f0-9]{8})/g, (matchstr, parens) => hex2char(parens));
// convert \u and 6 digit escapes to characters
- str = str.replace(/\\u([A-Fa-f0-9]{4})/g, (matchstr, parens) => {
- return hex2char(parens);
- });
+ strToDecode = strToDecode.replace(/\\u([A-Fa-f0-9]{4})/g, (matchstr, parens) => hex2char(parens));
// convert \b etc to characters, if flag set
if (shortEscapes) {
- str = str.replace(/\\b/g, '\b');
- str = str.replace(/\\t/g, '\t');
- str = str.replace(/\\n/g, '\n');
- str = str.replace(/\\v/g, '\v');
- str = str.replace(/\\f/g, '\f');
- str = str.replace(/\\r/g, '\r');
- str = str.replace(/\\\'/g, '\'');
- str = str.replace(/\\\"/g, '\"');
- str = str.replace(/\\\\/g, '\\');
+ strToDecode = strToDecode.replace(/\\b/g, '\b');
+ strToDecode = strToDecode.replace(/\\t/g, '\t');
+ strToDecode = strToDecode.replace(/\\n/g, '\n');
+ strToDecode = strToDecode.replace(/\\v/g, '\v');
+ strToDecode = strToDecode.replace(/\\f/g, '\f');
+ strToDecode = strToDecode.replace(/\\r/g, '\r');
+ strToDecode = strToDecode.replace(/\\\'/g, '\''); // eslint-disable-line
+ strToDecode = strToDecode.replace(/\\\"/g, '\"'); // eslint-disable-line
+ strToDecode = strToDecode.replace(/\\\\/g, '\\');
}
- return str;
+ return strToDecode;
}
@@ -0,0 +1,24 @@
+import React, { Component, PropTypes } from 'react';
+import { ActivityIndicator } from 'react-native';
+
+import _variables from '../_styles/variables';
+import style from './style';
+
+export default class Loading extends Component {
+
+ static propTypes = {
+ loaded: PropTypes.bool,
+ };
+
+ render() {
+ return (
+ <ActivityIndicator
+ style={[style.itemFeedback, style.itemLoading]}
+ animating={this.props.loaded}
+ color={_variables.white}
+ hidesWhenStopped
+ size="small"
+ />
+ );
+ }
+}
@@ -0,0 +1,37 @@
+import React, { Component, PropTypes } from 'react';
+import { TouchableOpacity } from 'react-native';
+import { createIconSetFromFontello } from 'react-native-vector-icons';
+
+import style from './style';
+
+import { colors } from '../_utils/networksColors';
+import fontelloConfig from '../config.json';
+
+const Icon = createIconSetFromFontello(fontelloConfig);
+
+export default class Remove extends Component {
+
+ static propTypes = {
+ network: PropTypes.string,
+ onPress: PropTypes.func,
+ };
+
+ render() {
+ const { onPress, network } = this.props;
+
+ return (
+ <TouchableOpacity
+ activeOpacity={0.85}
+ style={[style.itemFeedback, style.itemRemove]}
+ onPress={onPress}
+ >
+ <Icon
+ style={[style.itemIcon, style.itemRemoveIcon]}
+ name="cross"
+ color={colors(network)}
+ size={8}
+ />
+ </TouchableOpacity>
+ );
+ }
+}
@@ -0,0 +1,33 @@
+import React, { Component, PropTypes } from 'react';
+import { TouchableOpacity } from 'react-native';
+import { createIconSetFromFontello } from 'react-native-vector-icons';
+
+import style from './style';
+
+import { colors } from '../_utils/networksColors';
+import fontelloConfig from '../config.json';
+
+const Icon = createIconSetFromFontello(fontelloConfig);
+
+export default class Success extends Component {
+
+ static propTypes = {
+ network: PropTypes.string,
+ };
+
+ render() {
+ return (
+ <TouchableOpacity
+ activeOpacity={0.85}
+ style={[style.itemFeedback, style.itemSuccess]}
+ >
+ <Icon
+ style={[style.itemIcon, style.itemSuccessIcon]}
+ name="check"
+ color={colors(this.props.network)}
+ size={10}
+ />
+ </TouchableOpacity>
+ );
+ }
+}
@@ -1,78 +0,0 @@
-import React, { Component, PropTypes } from 'react';
-import { ActivityIndicator, TouchableOpacity } from 'react-native';
-import { createIconSetFromFontello } from 'react-native-vector-icons';
-
-import _variables from '../_styles/variables';
-import style from './style';
-
-import { colors } from '../_utils/networksColors';
-import fontelloConfig from '../config.json';
-
-const Icon = createIconSetFromFontello(fontelloConfig);
-
-export class Loading extends Component {
-
- static propTypes = {
- loaded: PropTypes.bool,
- };
-
- render() {
- return (
- <ActivityIndicator
- style={[style.itemFeedback, style.itemLoading]}
- animating={this.props.loaded}
- color={_variables.white}
- hidesWhenStopped
- size="small"
- />
- );
- }
-}
-
-export class Success extends Component {
-
- static propTypes = {
- network: PropTypes.string,
- };
-
- render() {
- return (
- <TouchableOpacity
- activeOpacity={0.85}
- style={[style.itemFeedback, style.itemSuccess]}
- >
- <Icon
- style={[style.itemIcon, style.itemSuccessIcon]}
- name="check"
- color={colors(this.props.network)}
- size={10}
- />
- </TouchableOpacity>
- );
- }
-}
-
-export class Remove extends Component {
-
- static propTypes = {
- network: PropTypes.string,
- onPress: PropTypes.func,
- };
-
- render() {
- return (
- <TouchableOpacity
- activeOpacity={0.85}
- style={[style.itemFeedback, style.itemRemove]}
- onPress={this.props.onPress}
- >
- <Icon
- style={[style.itemIcon, style.itemRemoveIcon]}
- name="cross"
- color={colors(this.props.network)}
- size={8}
- />
- </TouchableOpacity>
- );
- }
-}
@@ -1,17 +1,19 @@
import React, { Component, PropTypes } from 'react';
import { TextInput, View } from 'react-native';
import { createIconSetFromFontello } from 'react-native-vector-icons';
+import isEmpty from 'lodash/isEmpty';
import _variables from '../_styles/variables';
import global from '../_styles/global';
import style from './style';
import api from '../api';
-import { dataIsEmpty } from '../_utils/utils';
import { omit } from '../_utils/object';
import Storage from '../_utils/storage';
import { colors } from '../_utils/networksColors';
-import { Loading, Success, Remove } from '../addIndicators';
+import Loading from '../addIndicators/Loading';
+import Success from '../addIndicators/Success';
+import Remove from '../addIndicators/Remove';
import fontelloConfig from '../config.json';
const Icon = createIconSetFromFontello(fontelloConfig);
@@ -60,7 +62,7 @@ export default class AddInput extends Component {
const { network } = this.props;
const { value, networkData, isSuccess, isLoading, showRemoveIcon } = this.state;
- const condition = showRemoveIcon || !dataIsEmpty(networkData.Username);
+ const condition = showRemoveIcon || !isEmpty(networkData.Username);
const marginForRemoveIcon = condition ? { marginRight: 46 } : { marginRight: 20 };
const inputValue = (value === '') ? networkData.Username : value;
Oops, something went wrong.

0 comments on commit f20f661

Please sign in to comment.