https://github.com/givebest/gb-url
Parse and set url search parameters.解析 、获取、设置 window.location.search (url) 参数
https://github.com/givebest/gb-url
location url url-parser
Last synced: about 1 month ago
JSON representation
Parse and set url search parameters.解析 、获取、设置 window.location.search (url) 参数
- Host: GitHub
- URL: https://github.com/givebest/gb-url
- Owner: givebest
- License: mit
- Created: 2017-06-10T01:41:06.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2022-12-06T04:04:25.000Z (over 2 years ago)
- Last Synced: 2025-03-17T11:21:35.152Z (about 1 month ago)
- Topics: location, url, url-parser
- Language: TypeScript
- Homepage:
- Size: 48.8 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GB-url
Parse and set url search parameters.
English | [简体中文](./README.zh-CN.md)
---
## 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
```bash
npm i gb-url
``````js
import { setParams, queryParam } from "gb-url";
```### Get URL parameter
```javascript
/**
* 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
```javascript
/**
* 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](./LICENSE) © 2022 [givebest](https://github.com/givebest)