Skip to content

Commit

Permalink
Allow partial imports (#125)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Haraldson authored and sindresorhus committed Mar 14, 2018
1 parent d1a714e commit 42417c8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ function keysSorter(input) {
return input;
}

exports.extract = function (str) {
function extract(str) {
var queryStart = str.indexOf('?');
if (queryStart === -1) {
return '';
}
return str.slice(queryStart + 1);
};
}

exports.parse = function (str, opts) {
function parse(str, opts) {
opts = objectAssign({arrayFormat: 'none'}, opts);

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

return result;
}, Object.create(null));
};
}

exports.extract = extract;
exports.parse = parse;

exports.stringify = function (obj, opts) {
var defaults = {
Expand Down Expand Up @@ -216,6 +219,6 @@ exports.stringify = function (obj, opts) {
exports.parseUrl = function (str, opts) {
return {
url: str.split('?')[0] || '',
query: this.parse(this.extract(str), opts)
query: parse(extract(str), opts)
};
};

0 comments on commit 42417c8

Please sign in to comment.