A simple module to get query parameters from a url
Require
var query = require('query-extractor');
Get all query parameters and their values in an object
query.getAll("https://awesomewebsite.com?name=canon&place=India");
Output
{ name: 'canon', place: 'India' }
Get the value for a specific key in query string
query.get("https://awesomewebsite.com?name=canon&place=India", "name");
Output
canon
-
The URL in function is optional, If you want it to use the URL of current page than pass
null
instead and it'll use URL of current page -
It uses window.location.href to get URL of current page.
-
If the specified key doesn't exists in query string than it returns
null
. -
If the specified key doesn't has any value than it returns ```''````.