Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
fix: Typos
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidmt committed Oct 27, 2020
1 parent bc0a411 commit 6c8416b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/fn.set-props.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { trim, is, isObject } = require("@mutant-ws/m")
const { trim, is, isObject } = require("@asd14/m")

const setProps = props => ({ baseURL, headers, queryStringifyFn }) => {
if (is(queryStringifyFn)) {
if (typeof queryStringifyFn === "function") {
props.queryStringifyFn = queryStringifyFn
} else {
throw new TypeError(
`@mutant-ws/fetch-node: "queryStringifyFn" should be a function, received ${JSON.stringify(
`@asd14/fetch-node: "queryStringifyFn" should be a function, received ${JSON.stringify(
queryStringifyFn
)}`
)
Expand All @@ -21,7 +21,7 @@ const setProps = props => ({ baseURL, headers, queryStringifyFn }) => {
}
} else {
throw new TypeError(
`@mutant-ws/fetch-node: "headers" should be an object, received ${JSON.stringify(
`@asd14/fetch-node: "headers" should be an object, received ${JSON.stringify(
headers
)}`
)
Expand All @@ -30,10 +30,10 @@ const setProps = props => ({ baseURL, headers, queryStringifyFn }) => {

if (is(baseURL)) {
if (typeof baseURL === "string") {
props.baseURL = trim("/")(baseURL)
props.baseURL = trim("/", baseURL)
} else {
throw new TypeError(
`@mutant-ws/fetch-node: "baseURL" should be a string, received ${JSON.stringify(
`@asd14/fetch-node: "baseURL" should be a string, received ${JSON.stringify(
baseURL
)}`
)
Expand Down
15 changes: 6 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable import/exports-last */

const fetch = require("node-fetch")
const FormData = require("form-data")
const RFC3986 = require("rfc-3986")
const {
get,
read,
pipe,
reduce,
startsWith,
Expand All @@ -13,7 +11,7 @@ const {
same,
toLower,
isEmpty,
} = require("@mutant-ws/m")
} = require("@asd14/m")

const { setProps } = require("./fn.set-props")
const { HTTPError } = require("./fn.http-error")
Expand Down Expand Up @@ -46,15 +44,15 @@ const request = (
) => {
if (!isEmpty(query) && isEmpty(props.queryStringifyFn)) {
throw new TypeError(
`@mutant-ws/fetch-node: ${method}:${path} - Cannot send query params without providing "queryStringifyFn"`
`@asd14/fetch-node: ${method}:${path} - Cannot send query params without providing "queryStringifyFn"`
)
}

const isPathURI = new RegExp(RFC3986.uri).test(path)

if (isEmpty(props.baseURL) && !isPathURI) {
throw new TypeError(
`@mutant-ws/fetch-node: ${method}:${path} - Cannot make request with non-absolute path and no "baseURL"`
`@asd14/fetch-node: ${method}:${path} - Cannot make request with non-absolute path and no "baseURL"`
)
}

Expand All @@ -68,8 +66,7 @@ const request = (
...acc,
[toLower(key)]: value,
},
{}
)(
{},
Object.entries({
accept: "application/json",
"content-type": "application/json",
Expand All @@ -79,7 +76,7 @@ const request = (
)

const isReqJSON = pipe(
get("content-type"),
read("content-type"),
startsWith("application/json")
)(HEADERS)

Expand Down

0 comments on commit 6c8416b

Please sign in to comment.