Skip to content

Commit f262a3f

Browse files
committed
Use native alternatives to querystringify
1 parent 7b37f27 commit f262a3f

File tree

3 files changed

+4
-16
lines changed

3 files changed

+4
-16
lines changed

package-lock.json

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"phpdate": "1.0.0",
8181
"preact": "10.3.3",
8282
"prsh": "1.0.0",
83-
"querystringify": "2.1.1",
8483
"redux": "4.0.5",
8584
"redux-multi": "0.1.12",
8685
"refx": "3.1.1",

src/state/requests/middleware.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* External dependencies
33
*/
4-
import { stringify } from 'querystringify';
54
import { assign, isPlainObject, fromPairs } from 'lodash';
65

76
/**
@@ -98,12 +97,8 @@ export default ( { dispatch, getState } ) => {
9897

9998
// Append form contents
10099
if ( isPlainObject( params.body ) ) {
101-
params.headers.append(
102-
'Content-Type',
103-
'application/x-www-form-urlencoded'
104-
);
105-
106-
params.body = stringify( params.body );
100+
params.body = JSON.stringify( params.body );
101+
params.headers.append( 'Content-Type', 'application/json' );
107102
}
108103

109104
// Trigger and await network request
@@ -157,9 +152,8 @@ export default ( { dispatch, getState } ) => {
157152
const { type, query } = action;
158153
if ( REQUEST === type ) {
159154
// Append query string
160-
const querystring = stringify( query );
161-
if ( querystring ) {
162-
action.path += '?' + querystring;
155+
if ( query && Object.keys( query ).length > 0 ) {
156+
action.path += '?' + new URLSearchParams( query ).toString();
163157
}
164158

165159
// Assign flag for considering request completion as intended for

0 commit comments

Comments
 (0)