@@ -3,6 +3,7 @@ import { writable } from "svelte/store";
33import Home from "../pages/Home.svelte" ;
44import NotFound from "../pages/NotFound.svelte" ;
55import Playlist from "../pages/Playlist.svelte" ;
6+ import { getSearchParameters , createSearchParameters } from "../scripts/util" ;
67
78const componentsPathMap = new Map ( [
89 [ "/404" , NotFound ] ,
@@ -68,35 +69,4 @@ export function navigateTo(newRoute, parameters = null) {
6869 }
6970}
7071
71- function getSearchParameters ( ) {
72- const searchParams = new URLSearchParams ( window . location . search ) ;
73- const result = { } ;
74- for ( const [ key , value ] of searchParams . entries ( ) ) {
75- if ( result [ key ] ) {
76- // If key already exists, convert to array or push into existing array
77- result [ key ] = Array . isArray ( result [ key ] ) ? [ ...result [ key ] , parseValue ( value ) ] : [ result [ key ] , parseValue ( value ) ] ;
78- } else {
79- result [ key ] = parseValue ( value ) ;
80- }
81- }
82- return result ;
83- }
84-
85- function parseValue ( value ) {
86- if ( value === "true" ) return true ;
87- if ( value === "false" ) return false ;
88- if ( ! isNaN ( value ) && value . trim ( ) !== "" ) return Number ( value ) ;
89- return value ;
90- }
9172
92- function createSearchParameters ( params ) {
93- const searchParams = new URLSearchParams ( ) ;
94- for ( const key in params ) {
95- if ( Array . isArray ( params [ key ] ) ) {
96- params [ key ] . forEach ( ( value ) => searchParams . append ( key , value ) ) ;
97- } else {
98- searchParams . set ( key , params [ key ] ) ;
99- }
100- }
101- return searchParams . toString ( ) ;
102- }
0 commit comments