New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

url-params

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-params

Alter the query string parameters of url.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
74
-3.9%
Maintainers
1
Weekly downloads
 
Created
Source

url-params Build Status

Utility functions for adding, removing and setting values in url query strings. This is particularly suited to dealing with multi-value, '+' separated query strings.

Installation

If you don't have Yeoman installed yet, run the following.

npm install url-params

Usage

// Require url-params
var urlParams = require('urlParams');

var oldUrl = 'http://www.example.com/?foo=2+3+6&baz=6';

//
// Add parameters
//

// Add 4 to foo
newUrl = urlParams.add(oldUrl, 'foo', 4);
// newUrl === 'http://www.example.com/?foo=2+3+6+4&baz=6'

// Add 4 and 5 to foo
newUrl = urlParams.add(oldUrl, 'foo', [4, 5]);
// newUrl === 'http://www.example.com/?foo=2+3+6+4+5&baz=6'

// Add a boolean value
newUrl = urlParams.add(oldUrl, 'foo');
// newUrl === 'http://www.example.com/?foo=2+3+6&baz=6'
newUrl = urlParams.add(http://www.example.com/?baz=6, 'foo');
// newUrl === 'http://www.example.com/?baz=6&foo=true'


//
// Remove parameters
//

// Remove 3 from foo
newUrl = urlParams.remove(oldUrl, 'foo', 3)
// newUrl === 'http://www.example.com/?foo=2+6&baz=6'

// Remove 3 and 6 from foo
newUrl = urlParams.remove(oldUrl, 'foo', [3, 6])
// newUrl === 'http://www.example.com/?foo=2&baz=6'

// Remove a value
newUrl = urlParams.remove(oldUrl, 'foo')
// newUrl === 'http://www.example.com/?baz=6'


//
// Set parameters
//

// Set foo to 3
newUrl = urlParams.set(oldUrl, 'foo', 3)
// newUrl === 'http://www.example.com/?foo=3&baz=6'

// Set foo to 3+6
newUrl = urlParams.set(oldUrl, 'foo', [3, 6])
// newUrl === 'http://www.example.com/?foo=3+6&baz=6'

// Set foo to true
newUrl = urlParams.set(oldUrl, 'foo')
// newUrl === 'http://www.example.com/?foo=true&baz=6'

License

MIT

Keywords

url

FAQs

Package last updated on 19 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts