You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

gb-url

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gb-url

Parse and set url search parameters

1.1.6
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

GB-url

Parse and set url search parameters.

English | 简体中文

Introduction

queryParam gets the value of a parameter in window.location.search or a string that matches the rule.
setParams sets the value of one or more parameters in window.location.search or a string that matches the rule, and returns [url]?p1=1&p2=2&p3=3.

Use

npm i gb-url
import { setParams, queryParam } from "gb-url";

Get URL parameter

/**
 * gbUrl.queryParam(key, url);
 * @param  key [Name of the parameter to get]
 * @param  url [The URL to be resolved or a string that matches the rule, default is window.location.href]
 **/

const url = "a.html?a=1&b=2&c=3";
queryParam("a", url); // 1
queryParam("b", url); // 2

Set URL parameters

/**
 * gbUrl.setParams(params, url);
 * @param  params [Object to be set, assigned (key,value)]
 * @param  url [The URL to be resolved or a string that matches the rule, default is window.location.href]
 **/

const url = "a.html?a=1&b=2&c=3";
setParams(
  {
    a: "11111",
  },
  url
); // "a.html?a=11111&b=2&c=3"

setParams(
  {
    b: "2222",
    c: "3333",
    d: "4444",
  },
  url
); // "a.html?a=1&b=2222&c=3333&d=4444"

License

MIT © 2022 givebest

Keywords

url

FAQs

Package last updated on 06 Dec 2022

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