Skip to content

Commit

Permalink
More lint + add lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Apr 1, 2017
1 parent 7bd6f08 commit f20f661
Show file tree
Hide file tree
Showing 25 changed files with 549 additions and 468 deletions.
17 changes: 9 additions & 8 deletions package.json
Expand Up @@ -13,25 +13,26 @@
"*.{js,jsx}": "./node_modules/.bin/eslint" "*.{js,jsx}": "./node_modules/.bin/eslint"
}, },
"dependencies": { "dependencies": {
"moment": "^2.18.1", "moment": "2.18.1",
"react": "15.4.2", "react": "15.4.2",
"react-native": "^0.42.3", "react-native": "0.42.3",
"react-native-router-flux": "^3.38.0", "react-native-router-flux": "3.38.0",
"react-native-vector-icons": "^4.0.0" "react-native-vector-icons": "4.0.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^7.2.1", "babel-eslint": "7.2.1",
"babel-jest": "19.0.0", "babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1", "babel-preset-react-native": "1.9.1",
"eslint": "^3.18.0", "eslint": "3.18.0",
"eslint-config-airbnb": "14.1.0", "eslint-config-airbnb": "14.1.0",
"eslint-import-resolver-webpack": "0.8.1", "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-import": "2.2.0",
"eslint-plugin-jsx-a11y": "4.0.0", "eslint-plugin-jsx-a11y": "4.0.0",
"eslint-plugin-react": "^6.10.3", "eslint-plugin-react": "6.10.3",
"jest": "19.0.2", "jest": "19.0.2",
"lint-staged": "3.4.0", "lint-staged": "3.4.0",
"lodash": "4.17.4",
"pre-commit": "1.2.2", "pre-commit": "1.2.2",
"react-test-renderer": "15.4.2" "react-test-renderer": "15.4.2"
}, },
Expand Down
2 changes: 1 addition & 1 deletion sources/_utils/apiUtils.js
Expand Up @@ -78,6 +78,6 @@ export default ApiUtils = {
return { return {
state: 'success', state: 'success',
data: objNetwork, data: objNetwork,
} };
}, },
}; };
63 changes: 28 additions & 35 deletions sources/_utils/utils.js
@@ -1,25 +1,19 @@
/** /**
* Function to check is the username is stored before submiting with api request * Function to check is the username is stored before submiting with api request
*/ *
function isUsernameStore(input, store, network) { function isUsernameStore(input, store, network) {
const valuedStored = (store !== '') ? ((store[network] !== '') ? store[network].data.user.Username : undefined) : undefined; const isExist = store[network] !== '' ? store[network].data.user.Username : undefined;
return (input !== undefined && input !== valuedStored); const valuedStored = store !== '' ? isExist : undefined;
}
/** return input !== undefined && input !== valuedStored;
* 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 the ratio of a division of two number * Return the ratio of a division of two number
*/ */
export function ratio(a, b) { export function ratio(a, b) {
let x = Number(a); const x = Number(a);
let y = Number(b); const y = Number(b);


if (x > y) { if (x > y) {
return `${Math.ceil(x / y)}:1`; return `${Math.ceil(x / y)}:1`;
Expand All @@ -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) { export function removeTag(s) {
return s.replace(/(<(?:.|\n)*?>)/g, ''); return s.replace(/(<(?:.|\n)*?>)/g, '');
Expand Down Expand Up @@ -60,24 +55,24 @@ export function capitalize(s) {
* Formatting big numbers * Formatting big numbers
*/ */
export function format(nbr) { export function format(nbr) {
return (nbr + '').replace(/.(?=(?:.{3})+$)/g, '$& '); return String(nbr).replace(/.(?=(?:.{3})+$)/g, '$& ');
} }


/** /**
* Converts a single hex number to a character * 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 * Note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc
*/ */
export function hex2char(hex) { export function hex2char(hex) {
var result = ''; let result = '';
var n = parseInt(hex, 16); let n = parseInt(hex, 16);


if (n <= 0xFFFF) { if (n <= 0xFFFF) {
result += String.fromCharCode(n); result += String.fromCharCode(n);
} else if (n <= 0x10FFFF) { } else if (n <= 0x10FFFF) {
n -= 0x10000 n -= 0x10000;
result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF)); result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF)); // eslint-disable-line
} else { } else {
result += 'hex2Char error: Code point out of range: ' + dec2hex(n); result += `hex2Char error: Code point out of range: dec2hex(${n})`;
} }


return result; return result;
Expand All @@ -87,28 +82,26 @@ export function hex2char(hex) {
* Converts a string containing JavaScript escapes to a string of characters - unicode UTF-8 ready * Converts a string containing JavaScript escapes to a string of characters - unicode UTF-8 ready
*/ */
export function decode(str, shortEscapes) { export function decode(str, shortEscapes) {
let strToDecode = str;

// convert \U and 6 digit escapes to characters // convert \U and 6 digit escapes to characters
str = str.replace(/\\U([A-Fa-f0-9]{8})/g, (matchstr, parens) => { strToDecode = strToDecode.replace(/\\U([A-Fa-f0-9]{8})/g, (matchstr, parens) => hex2char(parens));
return hex2char(parens);
});


// convert \u and 6 digit escapes to characters // convert \u and 6 digit escapes to characters
str = str.replace(/\\u([A-Fa-f0-9]{4})/g, (matchstr, parens) => { strToDecode = strToDecode.replace(/\\u([A-Fa-f0-9]{4})/g, (matchstr, parens) => hex2char(parens));
return hex2char(parens);
});


// convert \b etc to characters, if flag set // convert \b etc to characters, if flag set
if (shortEscapes) { if (shortEscapes) {
str = str.replace(/\\b/g, '\b'); strToDecode = strToDecode.replace(/\\b/g, '\b');
str = str.replace(/\\t/g, '\t'); strToDecode = strToDecode.replace(/\\t/g, '\t');
str = str.replace(/\\n/g, '\n'); strToDecode = strToDecode.replace(/\\n/g, '\n');
str = str.replace(/\\v/g, '\v'); strToDecode = strToDecode.replace(/\\v/g, '\v');
str = str.replace(/\\f/g, '\f'); strToDecode = strToDecode.replace(/\\f/g, '\f');
str = str.replace(/\\r/g, '\r'); strToDecode = strToDecode.replace(/\\r/g, '\r');
str = str.replace(/\\\'/g, '\''); strToDecode = strToDecode.replace(/\\\'/g, '\''); // eslint-disable-line
str = str.replace(/\\\"/g, '\"'); strToDecode = strToDecode.replace(/\\\"/g, '\"'); // eslint-disable-line
str = str.replace(/\\\\/g, '\\'); strToDecode = strToDecode.replace(/\\\\/g, '\\');
} }


return str; return strToDecode;
} }
24 changes: 24 additions & 0 deletions sources/addIndicators/Loading.js
@@ -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"
/>
);
}
}
37 changes: 37 additions & 0 deletions sources/addIndicators/Remove.js
@@ -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>
);
}
}
33 changes: 33 additions & 0 deletions sources/addIndicators/Success.js
@@ -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>
);
}
}
78 changes: 0 additions & 78 deletions sources/addIndicators/index.js

This file was deleted.

8 changes: 5 additions & 3 deletions sources/addInput/index.js
@@ -1,17 +1,19 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { TextInput, View } from 'react-native'; import { TextInput, View } from 'react-native';
import { createIconSetFromFontello } from 'react-native-vector-icons'; import { createIconSetFromFontello } from 'react-native-vector-icons';
import isEmpty from 'lodash/isEmpty';


import _variables from '../_styles/variables'; import _variables from '../_styles/variables';
import global from '../_styles/global'; import global from '../_styles/global';
import style from './style'; import style from './style';


import api from '../api'; import api from '../api';
import { dataIsEmpty } from '../_utils/utils';
import { omit } from '../_utils/object'; import { omit } from '../_utils/object';
import Storage from '../_utils/storage'; import Storage from '../_utils/storage';
import { colors } from '../_utils/networksColors'; 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'; import fontelloConfig from '../config.json';


const Icon = createIconSetFromFontello(fontelloConfig); const Icon = createIconSetFromFontello(fontelloConfig);
Expand Down Expand Up @@ -60,7 +62,7 @@ export default class AddInput extends Component {
const { network } = this.props; const { network } = this.props;
const { value, networkData, isSuccess, isLoading, showRemoveIcon } = this.state; 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 marginForRemoveIcon = condition ? { marginRight: 46 } : { marginRight: 20 };
const inputValue = (value === '') ? networkData.Username : value; const inputValue = (value === '') ? networkData.Username : value;


Expand Down

0 comments on commit f20f661

Please sign in to comment.