Socket
Socket
Sign inDemoInstall

aurelia-path

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aurelia-path - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

bower.json
{
"name": "aurelia-path",
"version": "1.0.0",
"version": "1.1.0",
"description": "Utilities for path manipulation.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -107,3 +107,3 @@ define(['exports'], function (exports) {

function buildParam(key, value) {
function buildParam(key, value, traditional) {
var result = [];

@@ -115,6 +115,10 @@ if (value === null || value === undefined) {

for (var i = 0, l = value.length; i < l; i++) {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(encodeKey(key) + '=' + encode(value[i]));
} else {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !traditional) {
for (var propertyName in value) {

@@ -129,3 +133,3 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

function buildQueryString(params) {
function buildQueryString(params, traditional) {
var pairs = [];

@@ -135,3 +139,3 @@ var keys = Object.keys(params || {}).sort();

var key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -146,3 +150,3 @@

function processScalarParam(existedParam, value, isPrimitive) {
function processScalarParam(existedParam, value) {
if (Array.isArray(existedParam)) {

@@ -153,3 +157,3 @@ existedParam.push(value);

if (existedParam !== undefined) {
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -166,3 +170,4 @@

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
var prevValue = !currentParams[key] || _typeof(currentParams[key]) === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -189,3 +194,2 @@ currentParams = currentParams[key] = value;

var key = decodeURIComponent(pair[0]);
var isPrimitive = false;
if (!key) {

@@ -203,3 +207,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -213,3 +216,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -216,0 +219,0 @@ } else {

@@ -24,5 +24,6 @@

* @param params Object containing the keys and values to be used.
* @param traditional Boolean Use the old URI template standard (RFC6570)
* @returns The generated query string, excluding leading '?'.
*/
export declare function buildQueryString(params: Object): string;
export declare function buildQueryString(params: Object, traditional: Boolean): string;

@@ -29,0 +30,0 @@ /**

@@ -117,5 +117,6 @@

* @param value Parameter value to deserialize.
* @param traditional Boolean Use the old URI template standard (RFC6570)
* @return Array with serialized parameter(s)
*/
function buildParam(key: string, value: any): Array<string> {
function buildParam(key: string, value: any, traditional: boolean): Array<string> {
let result = [];

@@ -127,6 +128,10 @@ if (value === null || value === undefined) {

for (let i = 0, l = value.length; i < l; i++) {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(`${encodeKey(key)}=${encode(value[i])}`);
} else {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if (typeof (value) === 'object') {
} else if (typeof (value) === 'object' && !traditional) {
for (let propertyName in value) {

@@ -145,5 +150,6 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

* @param params Object containing the keys and values to be used.
* @param traditional Boolean Use the old URI template standard (RFC6570)
* @returns The generated query string, excluding leading '?'.
*/
export function buildQueryString(params: Object): string {
export function buildQueryString(params: Object, traditional: Boolean): string {
let pairs = [];

@@ -153,3 +159,3 @@ let keys = Object.keys(params || {}).sort();

let key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -169,6 +175,5 @@

* @param value Parameter value to append.
* @param isPrimitive If true and parameter value already specified - method overwrites it. If false - transofrm parameter to array and append new value to it.
* @returns Initial primitive value or transformed existedParam if parameter was recognized as an array.
*/
function processScalarParam(existedParam: Object, value: Object, isPrimitive: boolean): Object {
function processScalarParam(existedParam: Object, value: Object): Object {
if (Array.isArray(existedParam)) {

@@ -182,3 +187,3 @@ // value is already an array, so push on the next value.

// convert value into an array.
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -203,3 +208,6 @@ // value is a scalar.

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
// The value has to be an array or a false value
// It can happen that the value is no array if the key was repeated with traditional style like `list=1&list[]=2`
let prevValue = !currentParams[key] || typeof currentParams[key] === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -233,3 +241,2 @@ currentParams = currentParams[key] = value;

let key = decodeURIComponent(pair[0]);
let isPrimitive = false;
if (!key) {

@@ -250,3 +257,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -260,3 +266,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -263,0 +269,0 @@ } else {

@@ -103,3 +103,3 @@ 'use strict';

function buildParam(key, value) {
function buildParam(key, value, traditional) {
var result = [];

@@ -111,6 +111,10 @@ if (value === null || value === undefined) {

for (var i = 0, l = value.length; i < l; i++) {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(encodeKey(key) + '=' + encode(value[i]));
} else {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !traditional) {
for (var propertyName in value) {

@@ -125,3 +129,3 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

function buildQueryString(params) {
function buildQueryString(params, traditional) {
var pairs = [];

@@ -131,3 +135,3 @@ var keys = Object.keys(params || {}).sort();

var key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -142,3 +146,3 @@

function processScalarParam(existedParam, value, isPrimitive) {
function processScalarParam(existedParam, value) {
if (Array.isArray(existedParam)) {

@@ -149,3 +153,3 @@ existedParam.push(value);

if (existedParam !== undefined) {
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -162,3 +166,4 @@

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
var prevValue = !currentParams[key] || _typeof(currentParams[key]) === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -185,3 +190,2 @@ currentParams = currentParams[key] = value;

var key = decodeURIComponent(pair[0]);
var isPrimitive = false;
if (!key) {

@@ -199,3 +203,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -209,3 +212,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -212,0 +215,0 @@ } else {

@@ -89,3 +89,3 @@

function buildParam(key, value) {
function buildParam(key, value, traditional) {
let result = [];

@@ -97,6 +97,10 @@ if (value === null || value === undefined) {

for (let i = 0, l = value.length; i < l; i++) {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(`${ encodeKey(key) }=${ encode(value[i]) }`);
} else {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if (typeof value === 'object') {
} else if (typeof value === 'object' && !traditional) {
for (let propertyName in value) {

@@ -111,3 +115,3 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

export function buildQueryString(params) {
export function buildQueryString(params, traditional) {
let pairs = [];

@@ -117,3 +121,3 @@ let keys = Object.keys(params || {}).sort();

let key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -128,3 +132,3 @@

function processScalarParam(existedParam, value, isPrimitive) {
function processScalarParam(existedParam, value) {
if (Array.isArray(existedParam)) {

@@ -135,3 +139,3 @@ existedParam.push(value);

if (existedParam !== undefined) {
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -148,3 +152,4 @@

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
let prevValue = !currentParams[key] || typeof currentParams[key] === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -171,3 +176,2 @@ currentParams = currentParams[key] = value;

let key = decodeURIComponent(pair[0]);
let isPrimitive = false;
if (!key) {

@@ -185,3 +189,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -195,3 +198,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -198,0 +201,0 @@ } else {

@@ -92,3 +92,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

function buildParam(key, value) {
function buildParam(key, value, traditional) {
var result = [];

@@ -100,6 +100,10 @@ if (value === null || value === undefined) {

for (var i = 0, l = value.length; i < l; i++) {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(encodeKey(key) + '=' + encode(value[i]));
} else {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !traditional) {
for (var propertyName in value) {

@@ -114,3 +118,3 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

export function buildQueryString(params) {
export function buildQueryString(params, traditional) {
var pairs = [];

@@ -120,3 +124,3 @@ var keys = Object.keys(params || {}).sort();

var key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -131,3 +135,3 @@

function processScalarParam(existedParam, value, isPrimitive) {
function processScalarParam(existedParam, value) {
if (Array.isArray(existedParam)) {

@@ -138,3 +142,3 @@ existedParam.push(value);

if (existedParam !== undefined) {
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -151,3 +155,4 @@

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
var prevValue = !currentParams[key] || _typeof(currentParams[key]) === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -174,3 +179,2 @@ currentParams = currentParams[key] = value;

var key = decodeURIComponent(pair[0]);
var isPrimitive = false;
if (!key) {

@@ -188,3 +192,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -198,3 +201,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -201,0 +204,0 @@ } else {

@@ -96,3 +96,3 @@ 'use strict';

function buildParam(key, value) {
function buildParam(key, value, traditional) {
var result = [];

@@ -104,6 +104,10 @@ if (value === null || value === undefined) {

for (var i = 0, l = value.length; i < l; i++) {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(encodeKey(key) + '=' + encode(value[i]));
} else {
var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && !traditional) {
for (var propertyName in value) {

@@ -118,3 +122,3 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

function buildQueryString(params) {
function buildQueryString(params, traditional) {
var pairs = [];

@@ -124,3 +128,3 @@ var keys = Object.keys(params || {}).sort();

var key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -137,3 +141,3 @@

function processScalarParam(existedParam, value, isPrimitive) {
function processScalarParam(existedParam, value) {
if (Array.isArray(existedParam)) {

@@ -144,3 +148,3 @@ existedParam.push(value);

if (existedParam !== undefined) {
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -157,3 +161,4 @@

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
var prevValue = !currentParams[key] || _typeof(currentParams[key]) === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -180,3 +185,2 @@ currentParams = currentParams[key] = value;

var key = decodeURIComponent(pair[0]);
var isPrimitive = false;
if (!key) {

@@ -194,3 +198,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -204,3 +207,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -207,0 +210,0 @@ } else {

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

{"name":"aurelia-path","children":[{"id":10,"name":"buildQueryString","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":11,"name":"buildQueryString","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Generate a query string from an object.","returns":"The generated query string, excluding leading '?'.\n"},"parameters":[{"id":12,"name":"params","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"Object containing the keys and values to be used."},"type":{"type":"reference","name":"Object"}}],"type":{"type":"instrinct","name":"string"}}]},{"id":6,"name":"join","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":7,"name":"join","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Joins two paths.","returns":"The joined path.\n"},"parameters":[{"id":8,"name":"path1","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The first path."},"type":{"type":"instrinct","name":"string"}},{"id":9,"name":"path2","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The second path."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"string"}}]},{"id":13,"name":"parseQueryString","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":14,"name":"parseQueryString","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Parse a query string.","returns":"Object with keys and values mapped from the query string.\n"},"parameters":[{"id":15,"name":"queryString","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The query string to parse."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}]},{"id":2,"name":"relativeToFile","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":3,"name":"relativeToFile","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Calculates a path relative to a file.","returns":"The calculated path.\n"},"parameters":[{"id":4,"name":"name","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The relative path."},"type":{"type":"instrinct","name":"string"}},{"id":5,"name":"file","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The file path."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"string"}}]}],"groups":[{"title":"Functions","kind":64,"children":[10,6,13,2]}]}
{"name":"aurelia-path","children":[{"id":10,"name":"buildQueryString","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":11,"name":"buildQueryString","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Generate a query string from an object.","returns":"The generated query string, excluding leading '?'.\n"},"parameters":[{"id":12,"name":"params","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"Object containing the keys and values to be used."},"type":{"type":"reference","name":"Object"}},{"id":13,"name":"traditional","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"Boolean Use the old URI template standard (RFC6570)"},"type":{"type":"reference","name":"Boolean"}}],"type":{"type":"instrinct","name":"string"}}]},{"id":6,"name":"join","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":7,"name":"join","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Joins two paths.","returns":"The joined path.\n"},"parameters":[{"id":8,"name":"path1","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The first path."},"type":{"type":"instrinct","name":"string"}},{"id":9,"name":"path2","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The second path."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"string"}}]},{"id":14,"name":"parseQueryString","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":15,"name":"parseQueryString","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Parse a query string.","returns":"Object with keys and values mapped from the query string.\n"},"parameters":[{"id":16,"name":"queryString","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The query string to parse."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Object"}}]},{"id":2,"name":"relativeToFile","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":3,"name":"relativeToFile","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Calculates a path relative to a file.","returns":"The calculated path.\n"},"parameters":[{"id":4,"name":"name","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The relative path."},"type":{"type":"instrinct","name":"string"}},{"id":5,"name":"file","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The file path."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"string"}}]}],"groups":[{"title":"Functions","kind":64,"children":[10,6,14,2]}]}

@@ -0,1 +1,8 @@

<a name="1.1.0"></a>
# [1.1.0](https://github.com/aurelia/path/compare/1.0.0...v1.1.0) (2016-09-22)
#### Features
* **queries:** Build and parse queries also in traditional style
<a name="1.0.0"></a>

@@ -2,0 +9,0 @@ # [1.0.0](https://github.com/aurelia/path/compare/1.0.0-rc.1.0.0...v1.0.0) (2016-07-27)

@@ -9,4 +9,4 @@ <!--

Durandal Inc. offers paid support agreements. Further information regarding paid support
may be obtained by emailing support@durandal.io
Blue Spire offers paid support agreements. Further information regarding paid support
may be obtained by emailing support@bluespire.com

@@ -13,0 +13,0 @@ Future support requests submitted here will be closed.

{
"name": "aurelia-path",
"version": "1.0.0",
"version": "1.1.0",
"description": "Utilities for path manipulation.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -10,3 +10,3 @@ # aurelia-path

> To keep up to date on [Aurelia](http://www.aurelia.io/), please visit and subscribe to [the official blog](http://blog.durandal.io/) and [our email list](http://durandal.us10.list-manage1.com/subscribe?u=dae7661a3872ee02b519f6f29&id=3de6801ccc). We also invite you to [follow us on twitter](https://twitter.com/aureliaeffect). If you have questions, please [join our community on Gitter](https://gitter.im/aurelia/discuss). If you would like to have deeper insight into our development process, please install the [ZenHub](https://zenhub.io) Chrome or Firefox Extension and visit any of our repository's boards. You can get an overview of all Aurelia work by visiting [the framework board](https://github.com/aurelia/framework#boards).
> To keep up to date on [Aurelia](http://www.aurelia.io/), please visit and subscribe to [the official blog](http://blog.aurelia.io/) and [our email list](http://eepurl.com/ces50j). We also invite you to [follow us on twitter](https://twitter.com/aureliaeffect). If you have questions, please [join our community on Gitter](https://gitter.im/aurelia/discuss) or use [stack overflow](http://stackoverflow.com/search?q=aurelia). Documentation can be found [in our developer hub](http://aurelia.io/hub.html). If you would like to have deeper insight into our development process, please install the [ZenHub](https://zenhub.io) Chrome or Firefox Extension and visit any of our repository's boards.

@@ -13,0 +13,0 @@ ## Platform Support

@@ -116,5 +116,6 @@ function trimDots(ary: string[]): void {

* @param value Parameter value to deserialize.
* @param traditional Boolean Use the old URI template standard (RFC6570)
* @return Array with serialized parameter(s)
*/
function buildParam(key: string, value: any): Array<string> {
function buildParam(key: string, value: any, traditional: boolean): Array<string> {
let result = [];

@@ -126,6 +127,10 @@ if (value === null || value === undefined) {

for (let i = 0, l = value.length; i < l; i++) {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
if (traditional) {
result.push(`${encodeKey(key)}=${encode(value[i])}`);
} else {
let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']';
result = result.concat(buildParam(arrayKey, value[i]));
}
}
} else if (typeof (value) === 'object') {
} else if (typeof (value) === 'object' && !traditional) {
for (let propertyName in value) {

@@ -144,5 +149,6 @@ result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName]));

* @param params Object containing the keys and values to be used.
* @param traditional Boolean Use the old URI template standard (RFC6570)
* @returns The generated query string, excluding leading '?'.
*/
export function buildQueryString(params: Object): string {
export function buildQueryString(params: Object, traditional: Boolean): string {
let pairs = [];

@@ -152,3 +158,3 @@ let keys = Object.keys(params || {}).sort();

let key = keys[i];
pairs = pairs.concat(buildParam(key, params[key]));
pairs = pairs.concat(buildParam(key, params[key], traditional));
}

@@ -168,6 +174,5 @@

* @param value Parameter value to append.
* @param isPrimitive If true and parameter value already specified - method overwrites it. If false - transofrm parameter to array and append new value to it.
* @returns Initial primitive value or transformed existedParam if parameter was recognized as an array.
*/
function processScalarParam(existedParam: Object, value: Object, isPrimitive: boolean): Object {
function processScalarParam(existedParam: Object, value: Object): Object {
if (Array.isArray(existedParam)) {

@@ -181,3 +186,3 @@ // value is already an array, so push on the next value.

// convert value into an array.
return isPrimitive ? value : [existedParam, value];
return [existedParam, value];
}

@@ -202,3 +207,6 @@ // value is a scalar.

if (j < keysLastIndex) {
currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []);
// The value has to be an array or a false value
// It can happen that the value is no array if the key was repeated with traditional style like `list=1&list[]=2`
let prevValue = !currentParams[key] || typeof currentParams[key] === 'object' ? currentParams[key] : [currentParams[key]];
currentParams = currentParams[key] = prevValue || (isNaN(keys[j + 1]) ? {} : []);
} else {

@@ -232,3 +240,2 @@ currentParams = currentParams[key] = value;

let key = decodeURIComponent(pair[0]);
let isPrimitive = false;
if (!key) {

@@ -249,3 +256,2 @@ continue;

} else {
isPrimitive = true;
keysLastIndex = 0;

@@ -259,3 +265,3 @@ }

} else {
queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive);
queryParams[key] = processScalarParam(queryParams[key], value);
}

@@ -262,0 +268,0 @@ } else {

@@ -222,6 +222,10 @@ import { relativeToFile, join, parseQueryString, buildQueryString } from '../src/index';

expect(gen({ a: 'b', c: 'd' })).toBe('a=b&c=d');
expect(gen({ a: 'b', c: 'd' }, true)).toBe('a=b&c=d');
expect(gen({ a: 'b', c: null })).toBe('a=b');
expect(gen({ a: 'b', c: null }, true)).toBe('a=b');
expect(gen({ a: ['b', 'c'] })).toBe('a%5B%5D=b&a%5B%5D=c');
expect(gen({ a: ['b', 'c'] }, true)).toBe('a=b&a=c');
expect(gen({ '&': ['b', 'c'] })).toBe('%26%5B%5D=b&%26%5B%5D=c');
expect(gen({ '&': ['b', 'c'] }, true)).toBe('%26=b&%26=c');

@@ -234,5 +238,9 @@ expect(gen({ a: '&' })).toBe('a=%26');

expect(gen({ obj: { a: 5, b: "str", c: false } })).toBe('obj%5Ba%5D=5&obj%5Bb%5D=str&obj%5Bc%5D=false');
expect(gen({ obj: { a: 5, b: "str", c: false } }, true)).toBe('obj=%5Bobject%20Object%5D');
expect(gen({ obj:{ a: 5, b: undefined}})).toBe('obj%5Ba%5D=5');
expect(gen({a: {b: ['c','d', ['f', 'g']]}})).toBe('a%5Bb%5D%5B%5D=c&a%5Bb%5D%5B%5D=d&a%5Bb%5D%5B2%5D%5B%5D=f&a%5Bb%5D%5B2%5D%5B%5D=g');
expect(gen({a: {b: ['c','d', ['f', 'g']]}}, true)).toBe('a=%5Bobject%20Object%5D');
expect(gen({a: ['c','d', ['f', 'g']]}, true)).toBe('a=c&a=d&a=f%2Cg');
expect(gen({a: ['c','d', {f: 'g'}]}, true)).toBe('a=c&a=d&a=%5Bobject%20Object%5D');
});

@@ -256,3 +264,3 @@

expect(parse('a=b&&c=d')).toEqual({ a: 'b', c: 'd' });
expect(parse('a=b&a=c')).toEqual({ a: 'c' });
expect(parse('a=b&a=c')).toEqual({ a: ['b', 'c'] });

@@ -259,0 +267,0 @@ expect(parse('a=b&c=d=')).toEqual({ a: 'b', c: 'd' });

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