[chore] added prettier
This commit is contained in:
@@ -7,7 +7,7 @@ import constants from '../constants';
|
||||
const isIterable = object =>
|
||||
object != null && typeof object[Symbol.iterator] === 'function';
|
||||
|
||||
const cacheResponse = (data) => {
|
||||
const cacheResponse = data => {
|
||||
if (isIterable(data)) {
|
||||
stores.cache.cacheList(data);
|
||||
} else {
|
||||
@@ -51,59 +51,58 @@ class ApiClient {
|
||||
// Handle request promises and return a new promise
|
||||
return new Promise((resolve, reject) => {
|
||||
request
|
||||
.then((response) => {
|
||||
// Handle successful responses
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response;
|
||||
}
|
||||
.then(response => {
|
||||
// Handle successful responses
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response;
|
||||
}
|
||||
|
||||
// Handle 404
|
||||
if (response.status === 404) {
|
||||
return browserHistory.push('/404');
|
||||
}
|
||||
// Handle 404
|
||||
if (response.status === 404) {
|
||||
return browserHistory.push('/404');
|
||||
}
|
||||
|
||||
// Handle 401, log out user
|
||||
if (response.status === 401) {
|
||||
return stores.user.logout();
|
||||
}
|
||||
// Handle 401, log out user
|
||||
if (response.status === 401) {
|
||||
return stores.user.logout();
|
||||
}
|
||||
|
||||
// Handle failed responses
|
||||
const error = {};
|
||||
error.statusCode = response.status;
|
||||
error.response = response;
|
||||
throw error;
|
||||
})
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((json) => {
|
||||
// Cache responses
|
||||
if (options.cache) {
|
||||
cacheResponse(json.data);
|
||||
}
|
||||
resolve(json);
|
||||
})
|
||||
.catch(error => {
|
||||
error.response.json()
|
||||
// Handle failed responses
|
||||
const error = {};
|
||||
error.statusCode = response.status;
|
||||
error.response = response;
|
||||
throw error;
|
||||
})
|
||||
.then(response => {
|
||||
return response.json();
|
||||
})
|
||||
.then(json => {
|
||||
error.data = json;
|
||||
reject(error);
|
||||
// Cache responses
|
||||
if (options.cache) {
|
||||
cacheResponse(json.data);
|
||||
}
|
||||
resolve(json);
|
||||
})
|
||||
.catch(error => {
|
||||
error.response.json().then(json => {
|
||||
error.data = json;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
get = (path, data, options) => {
|
||||
return this.fetch(path, 'GET', data, options);
|
||||
}
|
||||
};
|
||||
|
||||
post = (path, data, options) => {
|
||||
return this.fetch(path, 'POST', data, options);
|
||||
}
|
||||
};
|
||||
|
||||
// Helpers
|
||||
|
||||
constructQueryString = (data) => {
|
||||
constructQueryString = data => {
|
||||
return _.map(data, (v, k) => {
|
||||
return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
|
||||
}).join('&');
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export default (type, ...argNames) => {
|
||||
return function(...args) {
|
||||
let action = { type }
|
||||
let action = { type };
|
||||
argNames.forEach((arg, index) => {
|
||||
action[argNames[index]] = args[index]
|
||||
})
|
||||
return action
|
||||
}
|
||||
}
|
||||
action[argNames[index]] = args[index];
|
||||
});
|
||||
return action;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import emojiMapping from './emoji-mapping.json';
|
||||
|
||||
const EMOJI_REGEX = /:([A-Za-z0-9_\-\+]+?):/gm;
|
||||
|
||||
const emojify = (text='') => {
|
||||
const emojify = (text = '') => {
|
||||
const emojis = text.match(EMOJI_REGEX) || [];
|
||||
let emojifiedText = text;
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ const Renderer = sanitizedRenderer(marked.Renderer);
|
||||
const renderer = new Renderer();
|
||||
renderer.code = (code, language) => {
|
||||
const validLang = !!(language && highlight.getLanguage(language));
|
||||
const highlighted = validLang ? highlight.highlight(language, code).value : _.escape(code);
|
||||
const highlighted = validLang
|
||||
? highlight.highlight(language, code).value
|
||||
: _.escape(code);
|
||||
return `<pre><code class="hljs ${_.escape(language)}">${highlighted}</code></pre>`;
|
||||
};
|
||||
renderer.heading = (text, level) => {
|
||||
@@ -25,10 +27,10 @@ renderer.heading = (text, level) => {
|
||||
`;
|
||||
};
|
||||
|
||||
const convertToMarkdown = (text) => {
|
||||
const convertToMarkdown = text => {
|
||||
// Add TOC
|
||||
text = toc.insert(text || '', {
|
||||
slugify: (heading) => {
|
||||
slugify: heading => {
|
||||
// FIXME: E.g. `&` gets messed up
|
||||
const headingSlug = _.escape(slug(heading));
|
||||
return headingSlug;
|
||||
@@ -46,6 +48,4 @@ const convertToMarkdown = (text) => {
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
convertToMarkdown,
|
||||
};
|
||||
export { convertToMarkdown };
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
const randomInteger = (min, max) => {
|
||||
return Math.floor(Math.random()*(max-min+1)+min);
|
||||
}
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
};
|
||||
|
||||
export {
|
||||
randomInteger
|
||||
};
|
||||
export { randomInteger };
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import renderer from 'react-test-renderer';
|
||||
|
||||
const snap = (children) => {
|
||||
const snap = children => {
|
||||
const component = renderer.create(children);
|
||||
expect(component).toMatchSnapshot();
|
||||
};
|
||||
|
||||
export {
|
||||
snap,
|
||||
};
|
||||
export { snap };
|
||||
|
||||
Reference in New Issue
Block a user