Socket
Socket
Sign inDemoInstall

query-string

Package Overview
Dependencies
3
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.12.1 to 6.13.0

40

index.d.ts

@@ -124,2 +124,17 @@ export interface ParseOptions {

readonly parseBooleans?: boolean;
/**
Parse the fragment identifier from the URL and add it to result object.
@default false
@example
```
import queryString = require('query-string');
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
```
*/
readonly parseFragmentIdentifier?: boolean;
}

@@ -146,2 +161,9 @@

readonly query: ParsedQuery;
/**
The fragment identifier of the URL.
Present when the `parseFragmentIdentifier` option is `true`.
*/
readonly fragmentIdentifier?: string;
}

@@ -152,2 +174,4 @@

If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
@param url - The URL to parse.

@@ -161,2 +185,5 @@

//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
```

@@ -305,3 +332,3 @@ */

```
@example

@@ -340,2 +367,4 @@ ```

The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
@example

@@ -348,2 +377,11 @@ ```

//=> 'https://foo.bar?foo=bar'
queryString.stringifyUrl({
url: 'https://foo.bar',
query: {
top: 'foo'
},
fragmentIdentifier: 'bar'
});
//=> 'https://foo.bar?top=foo#bar'
```

@@ -350,0 +388,0 @@ */

@@ -341,13 +341,27 @@ 'use strict';

exports.parseUrl = (input, options) => {
return {
url: removeHash(input).split('?')[0] || '',
query: parse(extract(input), options)
};
options = Object.assign({
decode: true
}, options);
const [url, hash] = splitOnFirst(input, '#');
return Object.assign(
{
url: url.split('?')[0] || '',
query: parse(extract(input), options)
},
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
);
};
exports.stringifyUrl = (input, options) => {
options = Object.assign({
encode: true,
strict: true
}, options);
const url = removeHash(input.url).split('?')[0] || '';
const queryFromUrl = exports.extract(input.url);
const parsedQueryFromUrl = exports.parse(queryFromUrl);
const hash = getHash(input.url);
const query = Object.assign(parsedQueryFromUrl, input.query);

@@ -359,3 +373,8 @@ let queryString = exports.stringify(query, options);

let hash = getHash(input.url);
if (input.fragmentIdentifier) {
hash = `#${encode(input.fragmentIdentifier, options)}`;
}
return `${url}${queryString}${hash}`;
};

8

package.json
{
"name": "query-string",
"version": "6.12.1",
"version": "6.13.0",
"description": "Parse and stringify URL query strings",

@@ -11,3 +11,3 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},

@@ -18,2 +18,3 @@ "engines": {

"scripts": {
"benchmark": "node benchmark.js",
"test": "xo && ava && tsd"

@@ -41,4 +42,4 @@ },

"dependencies": {
"decode-uri-component": "^0.2.0",
"split-on-first": "^1.0.0",
"decode-uri-component": "^0.2.0",
"strict-uri-encode": "^2.0.0"

@@ -48,2 +49,3 @@ },

"ava": "^1.4.1",
"benchmark": "^2.1.4",
"deep-equal": "^1.0.1",

@@ -50,0 +52,0 @@ "fast-check": "^1.5.0",

@@ -1,2 +0,2 @@

# query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string)
# query-string [![Build Status](https://travis-ci.com/sindresorhus/query-string.svg?branch=master)](https://travis-ci.com/github/sindresorhus/query-string) [![](https://badgen.net/bundlephobia/minzip/query-string)](https://bundlephobia.com/result?p=query-string)

@@ -19,10 +19,5 @@ > Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)

<br>
<a href="https://github.com/botpress/botpress">
<img src="https://sindresorhus.com/assets/thanks/botpress-logo.svg" width="260" alt="Botpress">
<a href="https://standardresume.co">
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="200"/>
</a>
<br>
<sub><b>Botpress is an open-source conversational assistant creation platform.</b></sub>
<br>
<sub>They <a href="https://github.com/botpress/botpress/blob/master/.github/CONTRIBUTING.md">welcome contributions</a> from anyone, whether you're into machine learning,<br>want to get started in open-source, or just have an improvement idea.</sub>
<br>
</p>

@@ -343,6 +338,6 @@ </div>

The `options` are the same as for `.parse()`.
Returns an object with a `url` and `query` property.
If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
```js

@@ -353,4 +348,29 @@ const queryString = require('query-string');

//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
```
#### options
Type: `object`
The options are the same as for `.parse()`.
Extra options are as below.
##### parseFragmentIdentifier
Parse the fragment identifier from the URL.
Type: `boolean`\
Default: `false`
```js
const queryString = require('query-string');
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
```
### .stringifyUrl(object, options?)

@@ -366,2 +386,4 @@

The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
```js

@@ -373,2 +395,11 @@ queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});

//=> 'https://foo.bar?foo=bar'
queryString.stringifyUrl({
url: 'https://foo.bar',
query: {
top: 'foo'
},
fragmentIdentifier: 'bar'
});
//=> 'https://foo.bar?top=foo#bar'
```

@@ -375,0 +406,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc