Skip to content

Commit

Permalink
eslint --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelin2025 committed Apr 6, 2018
1 parent 1258f2b commit e10263c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fetch =
(typeof window === "object" && window.fetch) || require("node-fetch")
const pathToRegexp = require("path-to-regexp")
(typeof window === 'object' && window.fetch) || require('node-fetch')
const pathToRegexp = require('path-to-regexp')

const parseUrl = url => {
let origin = ""
let pathname = ""
if (url.indexOf("://") > -1) {
const res = url.match("(^(?:(?:.*?)?//)?[^/?#;]*)(.*)")
let origin = ''
let pathname = ''
if (url.indexOf('://') > -1) {
const res = url.match('(^(?:(?:.*?)?//)?[^/?#;]*)(.*)')
origin = res[1]
pathname = res[2]
} else {
Expand All @@ -21,31 +21,31 @@ const uriReducer = (res = [], [key, val]) =>
res.concat(
Array.isArray(val)
? val.reduce((res, val, i) => uriReducer(res, [`${key}[]`, val]), [])
: typeof val === "object"
: typeof val === 'object'
? Object.entries(val).reduce(
(res, [i, val]) => uriReducer(res, [`${key}[${i}]`, val]),
[]
)
(res, [i, val]) => uriReducer(res, [`${key}[${i}]`, val]),
[]
)
: `${encodeURIComponent(key)}=${encodeURIComponent(val)}`
)

const withQuestion = res => (res.length && `?${res}`) || ""
const withQuestion = res => (res.length && `?${res}`) || ''

const buildQueryString = payload =>
withQuestion(
typeof payload === "string"
typeof payload === 'string'
? payload
: Object.entries(payload)
.reduce(uriReducer, [])
.join("&")
.reduce(uriReducer, [])
.join('&')
)

const defaultStatusValidator = status => status >= 200 && status < 300

const prepareBody = body =>
body instanceof FormData
? body
: typeof body === "object" ? JSON.stringify(body) : body
: typeof body === 'object' ? JSON.stringify(body) : body

const createResponse = res => body => ({
status: res.status,
Expand Down Expand Up @@ -73,8 +73,8 @@ export default {

const stream = res.clone()

const parser = payload.parser[isValid ? "done" : "fail"]
const callback = isValid ? "resolve" : "reject"
const parser = payload.parser[isValid ? 'done' : 'fail']
const callback = isValid ? 'resolve' : 'reject'

return stream[parser]()
.then(body => cbs[callback](responseWith(body)))
Expand All @@ -88,7 +88,7 @@ export default {
return fetch(payload.url, payload.options)
.then(done)
.catch(function(err) {
if (err.name === "AbortError") return
if (err.name === 'AbortError') return
fail(err)
})
},
Expand All @@ -104,15 +104,15 @@ export default {
const res = {
url: origin + compilePath(pathname, payload.params || {}),
parser: (payload.parser &&
(typeof payload.parser === "string"
(typeof payload.parser === 'string'
? { done: payload.parser, fail: payload.parser }
: payload.parser)) || { done: "json", fail: "json" },
: payload.parser)) || { done: 'json', fail: 'json' },
controller: controller,
validateStatus: payload.validateStatus || defaultStatusValidator,
options: {
method: payload.method || "GET",
method: payload.method || 'GET',
headers: payload.headers || {},
credentials: payload.createntials || "omit"
credentials: payload.createntials || 'omit'
}
}
if (payload.query) {
Expand All @@ -122,10 +122,10 @@ export default {
res.options.body = (payload.prepareBody || prepareBody)(payload.body)
}
if (
typeof payload.body === "object" &&
typeof payload.body === 'object' &&
!(payload.body instanceof FormData)
) {
res.options.headers["Content-Type"] = "application/json"
res.options.headers['Content-Type'] = 'application/json'
}
if (controller) {
res.options.signal = controller.signal
Expand All @@ -136,7 +136,7 @@ export default {
merge(from, to) {
const res = Object.assign({}, from, to)
if (to.url !== undefined && from.url !== undefined) {
res.url = to.url[0] === "/" ? to.url : [from.url, to.url].join("/")
res.url = to.url[0] === '/' ? to.url : [from.url, to.url].join('/')
}
return res
}
Expand Down

0 comments on commit e10263c

Please sign in to comment.