Url Parameter Append
A quick and easy utility method for adding, updating or removing querystring parameters.
Installation
npm install url-parameter-append
Tests
Tests can be executed using the following:
npm test
How to use
Reference the package:
const urlParameterAppend = require('url-parameter-append');
or
import urlParameterAppend from 'url-parameter-append';
Add querystring:
const url = urlParameterAppend('http://example.com/', 'search', 'test');
console.log(url);
http://example.com/?search=test
or
const url = urlParameterAppend('http://example.com/', {search: 'test'});
console.log(url);
http://example.com/?search=test
Replace parameter:
const url = urlParameterAppend('http://example.com/?search=test', 'search', 'other');
console.log(url);
http://example.com/?search=other
or
const url = urlParameterAppend('http://example.com/?search=test', {search: 'other'});
console.log(url);
http://example.com/?search=other
Remove parameter:
const url = urlParameterAppend('http://example.com/?search=test', 'search', null);
console.log(url);
http://example.com/
or
const url = urlParameterAppend('http://example.com/?search=test', {search: null});
console.log(url);
http://example.com/
More examples can be found in url-parameter-append.spec.ts
Tests use the jest testing framework.