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 2.0.0 to 3.0.0

18

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

@@ -13,2 +13,6 @@ * @license MIT

var encodedParam = function (param) {
return param === null ? '' : encodeURIComponent(String(param).trim());
};
var buildUrl = function (url, options) {

@@ -55,16 +59,16 @@ var queryString = [];

if (options.queryParams.hasOwnProperty(key) && options.queryParams[key] !== void 0) {
var encodedParam;
var param;
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);
param = options.queryParams[key][i];
queryString.push(key + '=' + encodedParam(param));
}
} else {
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
param = options.queryParams[key].toLowerCase();
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
param = options.queryParams[key];
}
queryString.push(key + '=' + encodedParam);
queryString.push(key + '=' + encodedParam(param));
}

@@ -71,0 +75,0 @@ }

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

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

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

@@ -5,3 +5,3 @@ # build-url

A library that builds a URL, including it's path, query parameters and fragment identifier. Works in node and in the browser.
A library that builds a URL, including its path, query parameters and fragment identifier. Works in node and in the browser.

@@ -153,4 +153,17 @@ ## Installation

Any null values in the `queryParams` object will be treated as empty strings:
```
buildUrl('http://example.com', {
queryParams: {
foo: 'bar',
bar: null
}
});
// returns http://example.com?foo=bar&bar=
```
## License
This is licensed under an MIT License. [See details](LICENSE)

@@ -312,2 +312,11 @@ describe('buildUrl', function () {

});
it('should treat null values in query param input as empty strings', function () {
expect(buildUrl('http://example.com', {
queryParams: {
foo: 'bar',
bar: null
}
})).toEqual('http://example.com?foo=bar&bar=');
});
});

@@ -7,2 +7,6 @@ ;(function () {

var encodedParam = function (param) {
return param === null ? '' : encodeURIComponent(String(param).trim());
};
var buildUrl = function (url, options) {

@@ -49,16 +53,16 @@ var queryString = [];

if (options.queryParams.hasOwnProperty(key) && options.queryParams[key] !== void 0) {
var encodedParam;
var param;
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);
param = options.queryParams[key][i];
queryString.push(key + '=' + encodedParam(param));
}
} else {
if (caseChange) {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim().toLowerCase());
param = options.queryParams[key].toLowerCase();
}
else {
encodedParam = encodeURIComponent(String(options.queryParams[key]).trim());
param = options.queryParams[key];
}
queryString.push(key + '=' + encodedParam);
queryString.push(key + '=' + encodedParam(param));
}

@@ -65,0 +69,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