Created
February 22, 2020 11:42
-
-
Save simon-brooke/71aa322501830b96066337466d5cc35a to your computer and use it in GitHub Desktop.
Returning the query part of the URL in a usable form in ClojureScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns url-query.query | |
(:require [clojure.string :as cs])) | |
;; I wrote this function for a wee side project and ended up not using it - but it is quite a useful function. | |
;; Freeware, not copyrighted, no warranty. Use at your own risk. | |
(defn get-query-part-as-map | |
"Returns the query part of the current document URL as a keyword-string map." | |
[] | |
(let [query-nvs (map #(cs/split % "=") (cs/split (subs js/window.location.search 1) "&"))] | |
(when (every? #(= (count %) 2) query-nvs) | |
(zipmap (map #(keyword (first %)) query-nvs)(map #(nth % 1) query-nvs))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment