@kitql/helper
Advanced tools
Comparing version 0.0.3 to 0.0.4
export { Log, logCyan, logGreen, logRed } from './Log'; | ||
export { queryStringApprend } from './queryStringApprend'; |
31
index.js
@@ -41,2 +41,32 @@ 'use strict'; | ||
/** | ||
* Add things to the queryString. | ||
* | ||
* Normal usage: | ||
* ``` | ||
* goto(`?${queryStringApprend($page.url.searchParams, { focus: "Hello" })}`); | ||
* ``` | ||
* @param searchParams usually: $page.url.searchParams | ||
* @param queryString an object with key value pairs, something like { focus: "Hello" } | ||
* @returns a sorted query string | ||
*/ | ||
function queryStringApprend(searchParams, queryString) { | ||
let query = {}; | ||
// 1 Destructure searchParams | ||
searchParams.forEach((v, k) => { | ||
query[k] = v; | ||
}); | ||
// 2 Upset with our queryString | ||
for (const key in queryString) { | ||
query[key] = queryString[key]; | ||
} | ||
// 3 Transform in a table | ||
let qs = []; | ||
for (const key in query) { | ||
qs.push(`${key}=${query[key]}`); | ||
} | ||
// 4 send back the Query String | ||
return qs.sort().join('&'); | ||
} | ||
exports.Log = Log; | ||
@@ -46,1 +76,2 @@ exports.logCyan = logCyan; | ||
exports.logRed = logRed; | ||
exports.queryStringApprend = queryStringApprend; |
{ | ||
"name": "@kitql/helper", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "pino": "7.6.5", |
Sorry, the diff of this file is not supported yet
5243
7
156