Skip to content

Instantly share code, notes, and snippets.

@simon-brooke
Created February 22, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simon-brooke/71aa322501830b96066337466d5cc35a to your computer and use it in GitHub Desktop.
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
(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