@apicase/adapter-xhr
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -7,10 +7,25 @@ 'use strict'; | ||
const encodeURIParts = (res, [key, val]) => | ||
res + encodeURIComponent(key) + '=' + encodeURIComponent(val); | ||
const uriReducer = (res = [], [key, val]) => | ||
res.concat( | ||
Array.isArray(val) | ||
? val.reduce((res, val, i) => uriReducer(res, [`${key}[]`, val]), []) | ||
: typeof val === 'object' | ||
? Object.entries(val).reduce( | ||
(res, [i, val]) => uriReducer(res, [`${key}[${i}]`, val]), | ||
[] | ||
) | ||
: `${encodeURIComponent(key)}=${encodeURIComponent(val)}` | ||
); | ||
const buildQueryString = query => { | ||
const queryString = Object.entries(query).reduce(encodeURIParts, ''); | ||
return queryString.length ? '?' + queryString : '' | ||
}; | ||
const withQuestion = res => (res.length && `?${res}`) || ''; | ||
const buildQueryString = payload => | ||
withQuestion( | ||
typeof payload === 'string' | ||
? payload | ||
: Object.entries(payload) | ||
.reduce(uriReducer, []) | ||
.join('&') | ||
); | ||
const defaultStatusValidator = status => status >= 200 && status < 300; | ||
@@ -17,0 +32,0 @@ |
27
index.js
@@ -5,10 +5,25 @@ const pathToRegexp = require('path-to-regexp') | ||
const encodeURIParts = (res, [key, val]) => | ||
res + encodeURIComponent(key) + '=' + encodeURIComponent(val) | ||
const uriReducer = (res = [], [key, val]) => | ||
res.concat( | ||
Array.isArray(val) | ||
? val.reduce((res, val, i) => uriReducer(res, [`${key}[]`, val]), []) | ||
: typeof val === 'object' | ||
? Object.entries(val).reduce( | ||
(res, [i, val]) => uriReducer(res, [`${key}[${i}]`, val]), | ||
[] | ||
) | ||
: `${encodeURIComponent(key)}=${encodeURIComponent(val)}` | ||
) | ||
const buildQueryString = query => { | ||
const queryString = Object.entries(query).reduce(encodeURIParts, '') | ||
return queryString.length ? '?' + queryString : '' | ||
} | ||
const withQuestion = res => (res.length && `?${res}`) || '' | ||
const buildQueryString = payload => | ||
withQuestion( | ||
typeof payload === 'string' | ||
? payload | ||
: Object.entries(payload) | ||
.reduce(uriReducer, []) | ||
.join('&') | ||
) | ||
const defaultStatusValidator = status => status >= 200 && status < 300 | ||
@@ -15,0 +30,0 @@ |
{ | ||
"name": "@apicase/adapter-xhr", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "XHR adapter for apicase-core", | ||
@@ -5,0 +5,0 @@ "main": "index.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9320
172