query-string
Advanced tools
Comparing version 4.0.2 to 4.1.0
16
index.js
'use strict'; | ||
var strictUriEncode = require('strict-uri-encode'); | ||
function encode(value, strict) { | ||
return strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
exports.extract = function (str) { | ||
@@ -48,3 +52,7 @@ return str.split('?')[1] || ''; | ||
exports.stringify = function (obj) { | ||
exports.stringify = function (obj, opts) { | ||
opts = opts || {}; | ||
var strict = opts.strict !== false; | ||
return obj ? Object.keys(obj).sort().map(function (key) { | ||
@@ -70,5 +78,5 @@ var val = obj[key]; | ||
if (val2 === null) { | ||
result.push(strictUriEncode(key)); | ||
result.push(encode(key, strict)); | ||
} else { | ||
result.push(strictUriEncode(key) + '=' + strictUriEncode(val2)); | ||
result.push(encode(key, strict) + '=' + encode(val2, strict)); | ||
} | ||
@@ -80,3 +88,3 @@ }); | ||
return strictUriEncode(key) + '=' + strictUriEncode(val); | ||
return encode(key, strict) + '=' + encode(val, strict); | ||
}).filter(function (x) { | ||
@@ -83,0 +91,0 @@ return x.length > 0; |
{ | ||
"name": "query-string", | ||
"version": "4.0.2", | ||
"version": "4.1.0", | ||
"description": "Parse and stringify URL query strings", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -50,6 +50,14 @@ # query-string [![Build Status](https://travis-ci.org/sindresorhus/query-string.svg?branch=master)](https://travis-ci.org/sindresorhus/query-string) | ||
### .stringify(*object*) | ||
### .stringify(*object*, *[options]*) | ||
Stringify an object into a query string, sorting the keys. | ||
#### strict | ||
Type: `boolean`<br /> | ||
Default: `true` | ||
Strictly encode URI components with [strict-uri-encode](https://github.com/kevva/strict-uri-encode). It uses [encodeURIComponent](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) | ||
if set to false. You probably [don't care](https://github.com/sindresorhus/query-string/issues/42) about this option. | ||
### .extract(*string*) | ||
@@ -56,0 +64,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6055
69
87