seturlparameter
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "seturlparameter", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "set an url parameter", | ||
"main": "setUrlParameter.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "google-closure-compiler --js=setUrlParameter.js --js_output_file=setUrlParameter.min.js" | ||
}, | ||
"author": "Raphael Hättich", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"google-closure-compiler": "^20190121.0.0" | ||
} | ||
} |
# setUrlParameter | ||
## Installation | ||
``` | ||
npm install seturlparameter | ||
``` | ||
## Usage | ||
``` | ||
const setUrlParameter = require('seturlparameter'); | ||
const url = 'https://www.example.com/index.html?aaa=bbb&ccc=ddd'; | ||
let key = 'eee'; | ||
const value = 'fff'; | ||
const urlWithNewParam = setUrlParameter(url, key, value); | ||
console.log(urlWithNewParam); // result is: 'https://www.example.com/index.html?aaa=bbb&ccc=ddd&eee=fff' | ||
key = 'aaa'; | ||
const urlWithReplacedParam = setUrlParameter(url, key, value); | ||
console.log(urlWithReplacedParam); // result is: 'https://www.example.com/index.html?aaa=fff&ccc=ddd' | ||
``` |
@@ -15,3 +15,3 @@ const setParam = (urlQueryString, newParam, encodedValue, encodedKey) => { | ||
return urlQueryString + '&' + newParam; | ||
} | ||
}; | ||
@@ -38,4 +38,4 @@ const setUrlParameter = (url, key, value) => { | ||
return baseUrl + params; | ||
} | ||
}; | ||
module.exports = setUrlParameter; |
@@ -1,1 +0,1 @@ | ||
var setParam=function(a,b,c,d){var e=new RegExp("([?&])"+d+"[^&]*");d=new RegExp("([?&])"+d+"=[^&;]+[&;]?");return"undefined"===typeof c||null===c||""===c?a.replace(d,"$1").replace(/[&;]$/,""):null!==a.match(e)?a.replace(e,"$1"+b):""==a?"?"+b:a+"&"+b},setUrlParameter=function(a,b,c){b=encodeURIComponent(b);var d=encodeURIComponent(c);c=a.split("?")[0];var e=b+"="+d;a=(a=void 0==a.split("?")[1]?"":"?"+a.split("?")[1])?setParam(a,e,d,b):"?"+e;return"?"===a?"":c+a};module.exports=setUrlParameter; | ||
var setParam=function(a,b,c,d){var e=new RegExp("([?&])"+d+"[^&]*");d=new RegExp("([?&])"+d+"=[^&;]+[&;]?");return"undefined"===typeof c||null===c||""===c?a.replace(d,"$1").replace(/[&;]$/,""):null!==a.match(e)?a.replace(e,"$1"+b):""==a?"?"+b:a+"&"+b},setUrlParameter=function(a,b,c){b=encodeURIComponent(b);var d=encodeURIComponent(c);c=a.split("?")[0];var e=b+"="+d;a=(a=void 0==a.split("?")[1]?"":"?"+a.split("?")[1])?setParam(a,e,d,b):"?"+e;return"?"===a?"":c+a};module.exports=setUrlParameter; |
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
10296
6
32
26
1