Repository: sindresorhus/query-string (js)

Issue:
queryString.exclude an hash url is not expected
```
queryString.exclude('https://xxx.com?a=b#/home', ['a'])
```

expect:

```
https://xxx.com#/home
```

result
```
https://xxx.com?a=b#%2Fhome
```



Pull request:
Don't encode the fragment identifier in `.pick` and `.exclude`
Fixes #318

Patch:
diff --git a/index.js b/index.js
index 7ab5d92..cc57637 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,8 @@ const filterObject = require('filter-obj');
 
 const isNullOrUndefined = value => value === null || value === undefined;
 
+const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
+
 function encoderForArrayFormat(options) {
 	switch (options.arrayFormat) {
 		case 'index':
@@ -402,7 +404,8 @@ exports.parseUrl = (url, options) => {
 exports.stringifyUrl = (object, options) => {
 	options = Object.assign({
 		encode: true,
-		strict: true
+		strict: true,
+		[encodeFragmentIdentifier]: true
 	}, options);
 
 	const url = removeHash(object.url).split('?')[0] || '';
@@ -417,7 +420,7 @@ exports.stringifyUrl = (object, options) => {
 
 	let hash = getHash(object.url);
 	if (object.fragmentIdentifier) {
-		hash = `#${encode(object.fragmentIdentifier, options)}`;
+		hash = `#${options[encodeFragmentIdentifier] ? encode(object.fragmentIdentifier, options) : object.fragmentIdentifier}`;
 	}
 
 	return `${url}${queryString}${hash}`;
@@ -425,7 +428,8 @@ exports.stringifyUrl = (object, options) => {
 
 exports.pick = (input, filter, options) => {
 	options = Object.assign({
-		parseFragmentIdentifier: true
+		parseFragmentIdentifier: true,
+		[encodeFragmentIdentifier]: false
 	}, options);
 
 	const {url, query, fragmentIdentifier} = exports.parseUrl(input, options);


Test patch:
diff --git a/test/exclude.js b/test/exclude.js
index 91e0d4f..646db88 100644
--- a/test/exclude.js
+++ b/test/exclude.js
@@ -15,3 +15,7 @@ test('excludes elements in a URL with a filter predicate', t => {
 		parseNumbers: true
 	}), 'http://example.com/?b=2&c=3#a');
 });
+
+test('excludes elements in a URL without encoding fragment identifiers', t => {
+	t.is(queryString.exclude('https://example.com?a=b#/home', ['a']), 'https://example.com#/home');
+});
diff --git a/test/pick.js b/test/pick.js
index e5e4381..0bfaf72 100644
--- a/test/pick.js
+++ b/test/pick.js
@@ -15,3 +15,7 @@ test('picks elements in a URL with a filter predicate', t => {
 		parseNumbers: true
 	}), 'http://example.com/?a=1#a');
 });
+
+test('picks elements in a URL without encoding fragment identifiers', t => {
+	t.is(queryString.pick('https://example.com?a=b#/home', []), 'https://example.com#/home');
+});