Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qs

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qs - npm Package Compare versions

Comparing version 0.5.6 to 0.6.0

100

index.js

@@ -9,2 +9,54 @@

/**
* Array#indexOf shim.
*/
var indexOf = typeof Array.prototype.indexOf === 'function'
? function(arr, el) { return arr.indexOf(el); }
: function(arr, el) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === el) return i;
}
return -1;
};
/**
* Array.isArray shim.
*/
var isArray = Array.isArray || function(arr) {
return toString.call(arr) == '[object Array]';
};
/**
* Object.keys shim.
*/
var objectKeys = Object.keys || function(obj) {
var ret = [];
for (var key in obj) ret.push(key);
return ret;
};
/**
* Array#forEach shim.
*/
var forEach = typeof Array.prototype.forEach === 'function'
? function(arr, fn) { return arr.forEach(fn); }
: function(arr, fn) {
for (var i = 0; i < arr.length; i++) fn(arr[i]);
};
/**
* Array#reduce shim.
*/
var reduce = function(arr, fn, initial) {
if (typeof arr.reduce === 'function') return arr.reduce(fn, initial);
var res = initial;
for (var i = 0; i < arr.length; i++) res = fn(res, arr[i]);
return res;
};
/**
* Cache non-integer test regexp.

@@ -27,3 +79,3 @@ */

if (!part) {
if (Array.isArray(parent[key])) {
if (isArray(parent[key])) {
parent[key].push(val);

@@ -41,6 +93,6 @@ } else if ('object' == typeof parent[key]) {

if (']' == part) {
if (Array.isArray(obj)) {
if (isArray(obj)) {
if ('' != val) obj.push(val);
} else if ('object' == typeof obj) {
obj[Object.keys(obj).length] = val;
obj[objectKeys(obj).length] = val;
} else {

@@ -50,9 +102,9 @@ obj = parent[key] = [parent[key], val];

// prop
} else if (~part.indexOf(']')) {
} else if (~indexOf(part, ']')) {
part = part.substr(0, part.length - 1);
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);
// key
} else {
if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);

@@ -68,3 +120,3 @@ }

function merge(parent, key, val){
if (~key.indexOf(']')) {
if (~indexOf(key, ']')) {
var parts = key.split('[')

@@ -76,3 +128,3 @@ , len = parts.length

} else {
if (!isint.test(key) && Array.isArray(parent.base)) {
if (!isint.test(key) && isArray(parent.base)) {
var t = {};

@@ -94,3 +146,3 @@ for (var k in parent.base) t[k] = parent.base[k];

var ret = { base: {} };
Object.keys(obj).forEach(function(name){
forEach(objectKeys(obj), function(name){
merge(ret, name, obj[name]);

@@ -106,17 +158,15 @@ });

function parseString(str){
return String(str)
.split('&')
.reduce(function(ret, pair){
var eql = pair.indexOf('=')
, brace = lastBraceInKey(pair)
, key = pair.substr(0, brace || eql)
, val = pair.substr(brace || eql, pair.length)
, val = val.substr(val.indexOf('=') + 1, val.length);
return reduce(String(str).split('&'), function(ret, pair){
var eql = indexOf(pair, '=')
, brace = lastBraceInKey(pair)
, key = pair.substr(0, brace || eql)
, val = pair.substr(brace || eql, pair.length)
, val = val.substr(indexOf(val, '=') + 1, val.length);
// ?foo
if ('' == key) key = pair, val = '';
if ('' == key) return ret;
// ?foo
if ('' == key) key = pair, val = '';
if ('' == key) return ret;
return merge(ret, decode(key), decode(val));
}, { base: {} }).base;
return merge(ret, decode(key), decode(val));
}, { base: {} }).base;
}

@@ -148,3 +198,3 @@

var stringify = exports.stringify = function(obj, prefix) {
if (Array.isArray(obj)) {
if (isArray(obj)) {
return stringifyArray(obj, prefix);

@@ -203,3 +253,3 @@ } else if ('[object Object]' == toString.call(obj)) {

var ret = []
, keys = Object.keys(obj)
, keys = objectKeys(obj)
, key;

@@ -237,3 +287,3 @@

obj[key] = val;
} else if (Array.isArray(v)) {
} else if (isArray(v)) {
v.push(val);

@@ -240,0 +290,0 @@ } else {

{
"name": "qs",
"description": "querystring parser",
"version": "0.5.6",
"version": "0.6.0",
"keywords": ["query string", "parser", "component"],

@@ -14,2 +14,5 @@ "repository": {

},
"scripts": {
"test": "make test"
},
"component": {

@@ -16,0 +19,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc