Socket
Socket
Sign inDemoInstall

build-url

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

build-url - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

28

dist/build-url.js
/**
* build-url - A small library that builds a URL given its components
* @version v1.3.0
* @version v1.3.2
* @link https://github.com/steverydz/build-url#readme

@@ -54,12 +54,18 @@ * @license MIT

for (key in options.queryParams) {
if (options.queryParams.hasOwnProperty(key)
&& options.queryParams[key] !== void 0) {
var encodedParam;
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
}
queryString.push(key + '=' + encodedParam);
if (options.queryParams.hasOwnProperty(key) && options.queryParams[key] !== void 0) {
var encodedParam;
if (options.disableCSV && Array.isArray(options.queryParams[key]) && options.queryParams[key].length) {
for(var i = 0; i < options.queryParams[key].length; i++) {
encodedParam = encodeURIComponent(String(options.queryParams[key][i]).trim());
queryString.push(key + '=' + encodedParam);
}
} else {
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
}
queryString.push(key + '=' + encodedParam);
}
}

@@ -66,0 +72,0 @@ }

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

(function(){"use strict";var r=this,e=r.buildUrl,t=function(r,e){var t,o,i,n=[];if(i=!(!e||!e.lowerCase)&&!!e.lowerCase,null===r?o="":"object"==typeof r?(o="",e=r):o=r,o&&"/"===o[o.length-1]&&(o=o.slice(0,-1)),e){if(e.path){var a=String(e.path).trim();i&&(a=a.toLowerCase()),0===a.indexOf("/")?o+=a:o+="/"+a}if(e.queryParams){for(t in e.queryParams){var s;if(e.queryParams.hasOwnProperty(t)&&void 0!==e.queryParams[t])s=i?encodeURIComponent(String(e.queryParams[t]).trim().toLowerCase()):encodeURIComponent(String(e.queryParams[t]).trim()),n.push(t+"="+s)}o+="?"+n.join("&")}e.hash&&(o+=i?"#"+String(e.hash).trim().toLowerCase():"#"+String(e.hash).trim())}return o};t.noConflict=function(){return r.buildUrl=e,t},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=t),exports.buildUrl=t):r.buildUrl=t}).call(this);
(function(){"use strict";var r=this,e=r.buildUrl,t=function(r,e){var t,a,o,i=[];if(o=!(!e||!e.lowerCase)&&!!e.lowerCase,null===r?a="":"object"==typeof r?(a="",e=r):a=r,a&&"/"===a[a.length-1]&&(a=a.slice(0,-1)),e){if(e.path){var n=String(e.path).trim();o&&(n=n.toLowerCase()),0===n.indexOf("/")?a+=n:a+="/"+n}if(e.queryParams){for(t in e.queryParams){var s;if(e.queryParams.hasOwnProperty(t)&&void 0!==e.queryParams[t])if(e.disableCSV&&Array.isArray(e.queryParams[t])&&e.queryParams[t].length)for(var u=0;u<e.queryParams[t].length;u++)s=encodeURIComponent(String(e.queryParams[t][u]).trim()),i.push(t+"="+s);else s=o?encodeURIComponent(String(e.queryParams[t]).trim().toLowerCase()):encodeURIComponent(String(e.queryParams[t]).trim()),i.push(t+"="+s)}a+="?"+i.join("&")}e.hash&&(a+=o?"#"+String(e.hash).trim().toLowerCase():"#"+String(e.hash).trim())}return a};t.noConflict=function(){return r.buildUrl=e,t},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=t),exports.buildUrl=t):r.buildUrl=t}).call(this);
{
"name": "build-url",
"version": "1.3.1",
"version": "1.3.2",
"description": "A small library that builds a URL given its components",

@@ -5,0 +5,0 @@ "main": "./dist/build-url.js",

@@ -108,2 +108,17 @@ # build-url

If you pass an array to the `queryParams` object, and want that they should not be comma separated use `disableCSV`:
```
buildUrl('http://example.com', {
disableCSV: true,
queryParams: {
foo: 'bar',
bar: ['one', 'two', 'three']
}
});
// returns http://example.com?foo=bar&bar=one&bar=two&bar=three
```
If you only want the query string, path, hash, or any combination of the three you can skip the URL parameter or pass in an empty string or null:

@@ -110,0 +125,0 @@

@@ -277,2 +277,22 @@ describe('buildUrl', function () {

it("should make array based parameters appear as a separate param for each of the values in array", function() {
expect(buildUrl('http://example.com', {
disableCSV: true,
queryParams: {
foo: 'bar',
bar: ['one', 'two', 'three']
}
})).toEqual('http://example.com?foo=bar&bar=one&bar=two&bar=three');
});
it("should keep array based parameters comma separated if disableCSV is not opted in", function() {
expect(buildUrl('http://example.com', {
disableCSV: false,
queryParams: {
foo: 'bar',
bar: ['one', 'two', 'three']
}
})).toEqual('http://example.com?foo=bar&bar=one%2Ctwo%2Cthree');
});
});

@@ -48,12 +48,18 @@ ;(function () {

for (key in options.queryParams) {
if (options.queryParams.hasOwnProperty(key)
&& options.queryParams[key] !== void 0) {
var encodedParam;
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
}
queryString.push(key + '=' + encodedParam);
if (options.queryParams.hasOwnProperty(key) && options.queryParams[key] !== void 0) {
var encodedParam;
if (options.disableCSV && Array.isArray(options.queryParams[key]) && options.queryParams[key].length) {
for(var i = 0; i < options.queryParams[key].length; i++) {
encodedParam = encodeURIComponent(String(options.queryParams[key][i]).trim());
queryString.push(key + '=' + encodedParam);
}
} else {
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
}
queryString.push(key + '=' + encodedParam);
}
}

@@ -60,0 +66,0 @@ }

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