chore: add code formatting and linting (#952)

This commit is contained in:
Caleb
2018-08-07 14:46:54 -06:00
committed by Shawn Erquhart
parent 32e0a9b2b5
commit f801b19221
265 changed files with 5988 additions and 4481 deletions

View File

@ -3,26 +3,40 @@ import curry from 'lodash/curry';
import flow from 'lodash/flow';
import isString from 'lodash/isString';
const decodeParams = paramsString => List(paramsString.split("&"))
.map(s => List(s.split("=")).map(decodeURIComponent))
.update(Map);
const decodeParams = paramsString =>
List(paramsString.split('&'))
.map(s => List(s.split('=')).map(decodeURIComponent))
.update(Map);
const fromURL = wholeURL => {
const [url, allParamsString] = wholeURL.split("?");
const [url, allParamsString] = wholeURL.split('?');
return Map({ url, ...(allParamsString ? { params: decodeParams(allParamsString) } : {}) });
};
const encodeParams = params => params.entrySeq()
.map(([k, v]) => `${ encodeURIComponent(k) }=${ encodeURIComponent(v) }`)
.join("&");
const encodeParams = params =>
params
.entrySeq()
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
.join('&');
const toURL = req => `${ req.get("url") }${ req.get("params") ? `?${ encodeParams(req.get("params")) }` : "" }`;
const toURL = req =>
`${req.get('url')}${req.get('params') ? `?${encodeParams(req.get('params'))}` : ''}`;
const toFetchArguments = req => [toURL(req), req.delete("url").delete("params").toJS()];
const toFetchArguments = req => [
toURL(req),
req
.delete('url')
.delete('params')
.toJS(),
];
const maybeRequestArg = req => {
if (isString(req)) { return fromURL(req); }
if (req) { return fromJS(req); }
if (isString(req)) {
return fromURL(req);
}
if (req) {
return fromJS(req);
}
return Map();
};
const ensureRequestArg = func => req => func(maybeRequestArg(req));
@ -41,23 +55,27 @@ const getPropSetFunctions = path => [
getCurriedRequestProcessor((val, req) => (req.getIn(path) ? req : req.setIn(path, val))),
];
const getPropMergeFunctions = path => [
getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p=Map()) => p.merge(obj))),
getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p=Map()) => Map(obj).merge(p))),
getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p = Map()) => p.merge(obj))),
getCurriedRequestProcessor((obj, req) => req.updateIn(path, (p = Map()) => Map(obj).merge(p))),
];
const [withMethod, withDefaultMethod] = getPropSetFunctions(["method"]);
const [withBody, withDefaultBody] = getPropSetFunctions(["body"]);
const [withParams, withDefaultParams] = getPropMergeFunctions(["params"]);
const [withHeaders, withDefaultHeaders] = getPropMergeFunctions(["headers"]);
const [withMethod, withDefaultMethod] = getPropSetFunctions(['method']);
const [withBody, withDefaultBody] = getPropSetFunctions(['body']);
const [withParams, withDefaultParams] = getPropMergeFunctions(['params']);
const [withHeaders, withDefaultHeaders] = getPropMergeFunctions(['headers']);
// withRoot sets a root URL, unless the URL is already absolute
const absolutePath = new RegExp('^(?:[a-z]+:)?//', 'i');
const withRoot = getCurriedRequestProcessor((root, req) => req.update("url", p => {
if (absolutePath.test(p)) { return p; }
return (root && p && p[0] !== "/" && root[root.length - 1] !== "/")
? `${ root }/${ p }`
: `${ root }${ p }`;
}));
const withRoot = getCurriedRequestProcessor((root, req) =>
req.update('url', p => {
if (absolutePath.test(p)) {
return p;
}
return root && p && p[0] !== '/' && root[root.length - 1] !== '/'
? `${root}/${p}`
: `${root}${p}`;
}),
);
// withTimestamp needs no argument and has to run as late as possible,
// so it calls `withParams` only when it's actually called with a