Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 287eba7

Browse files
committed
parseQueries
1 parent f09a16a commit 287eba7

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

README.md

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Some functions to work better with arrays, objects and more!!
88

99
### sortBy
1010

11-
_function to sort an array_
11+
# sortBy
1212

13-
How to use it?
13+
How to import it?
1414

1515
```
1616
import { Array } from "some-javascript-utils";
@@ -44,9 +44,9 @@ Array.sortBy(array, "id", "asc") ;
4444

4545
## Browser
4646

47-
_function to get user language_
47+
# getUserLanguage
4848

49-
Hot to use it?
49+
Hot to import it?
5050

5151
```
5252
import { Browser } from "some-javascript-utils";
@@ -73,12 +73,52 @@ const userLang = getUserLanguage();
7373
// if pass a string parameter will save the language to a cookie ()
7474
// example: "en"
7575
76+
```
77+
78+
# parseQueries
79+
80+
Hot to import it?
81+
82+
```
83+
84+
import { Browser } from "some-javascript-utils";
85+
// import { parseQueries } from "some-javascript-utils";
86+
87+
```
88+
89+
or
90+
91+
```
92+
93+
const { Browser } = "some-javascript-utils";
94+
// const { parseQueries } = "some-javascript-utils";
95+
96+
```
97+
98+
#### In Action!
99+
100+
🔶⚠Very important⚠🔶!!
101+
102+
_just work in browsers_
76103

77104
```
78105
79-
_function to scroll to position_
106+
// ...imports
107+
108+
//! using location from useLocation() hook from "react-router-dom"
109+
110+
useEffect(() => {
111+
const { search } = location // ex: [some-url]?id=1&folder=sito
112+
const queryParams = parseQueries(search)
113+
// queryParams will value { id: "1", folder: "sito" }
114+
},[location])
80115
81-
Hot to use it?
116+
117+
```
118+
119+
# scrollTo
120+
121+
Hot to import it?
82122

83123
```
84124
@@ -111,9 +151,9 @@ scrollTo(0) // go to top of the page
111151
112152
```
113153

114-
_function to create a cookie_
154+
# createCookie
115155

116-
Hot to use it?
156+
Hot to import it?
117157

118158
```
119159
@@ -151,9 +191,9 @@ createCookie(name, expiration, value);
151191
152192
```
153193

154-
_function to get a cookie value_
194+
# getCookie
155195

156-
Hot to use it?
196+
Hot to import it?
157197

158198
```
159199
@@ -186,11 +226,12 @@ getCookie(name);
186226
187227
// result
188228
// sito (of previous example)
229+
189230
```
190231

191-
_function to delete a cookie_
232+
# deleteCookie
192233

193-
Hot to use it?
234+
Hot to import it?
194235

195236
```
196237
@@ -223,4 +264,7 @@ deleteCookie(name);
223264
224265
// result
225266
// (document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`);/
267+
268+
```
269+
226270
```

browser.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
*
3+
* @param {string} queries
4+
*/
5+
export const parseQueries = (queries) => {
6+
const toReturn = {};
7+
const queryParams = queries.substring(1).split("&");
8+
queryParams.forEach((item) => {
9+
const [param, value] = item.split("=");
10+
toReturn[param] = value;
11+
});
12+
return toReturn;
13+
};
14+
115
/**
216
*
317
* @param {string} cookie

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "some-javascript-utils",
3-
"version": "0.7.1",
3+
"version": "0.8.1",
44
"description": "some functions for javascript",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)