Skip to content

Commit 42417c8

Browse files
Haraldsonsindresorhus
authored andcommitted
Allow partial imports (#125)
`this.parse(this.extract(str), opts)` assumes `query-string` will always be imported fully. Importing `stringify` by itself works, but not `parseUrl`. This change makes the `parseUrl` export independent, allowing `import { parseUrl } from 'query-string'` and a more consistent behavior.
1 parent d1a714e commit 42417c8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ function keysSorter(input) {
113113
return input;
114114
}
115115

116-
exports.extract = function (str) {
116+
function extract(str) {
117117
var queryStart = str.indexOf('?');
118118
if (queryStart === -1) {
119119
return '';
120120
}
121121
return str.slice(queryStart + 1);
122-
};
122+
}
123123

124-
exports.parse = function (str, opts) {
124+
function parse(str, opts) {
125125
opts = objectAssign({arrayFormat: 'none'}, opts);
126126

127127
var formatter = parserForArrayFormat(opts);
@@ -165,7 +165,10 @@ exports.parse = function (str, opts) {
165165

166166
return result;
167167
}, Object.create(null));
168-
};
168+
}
169+
170+
exports.extract = extract;
171+
exports.parse = parse;
169172

170173
exports.stringify = function (obj, opts) {
171174
var defaults = {
@@ -216,6 +219,6 @@ exports.stringify = function (obj, opts) {
216219
exports.parseUrl = function (str, opts) {
217220
return {
218221
url: str.split('?')[0] || '',
219-
query: this.parse(this.extract(str), opts)
222+
query: parse(extract(str), opts)
220223
};
221224
};

0 commit comments

Comments
 (0)