Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,16 @@

;; TODO: Support namespaced keywords :-)
(defn ->keyword
"Coerces `input` to a keyword, replacing whitespace with dashes by default."
([input]
(->keyword nil input))
([ignore-match input]
(->keyword ignore-match "-" input))
([ignore-match replacement input]
(if (keyword? input)
input
(let [match (or ignore-match #"\s")
replacement' (or replacement "-")]
(when input
(some-> input name str/trim str/lower-case (str/replace match replacement') keyword))))))
"Coerces `input` to a keyword, replacing whitespace with dashes by default.
Supports optional keyword arguments:
- `:replacement`: The string to replace matches with (default: \"-\").
- `:ignore-match`: The regex pattern to replace (default: #\"\\s\").
Example: `(->keyword \"my input\" :replacement \"_\")` => `:my_input`"
[input & {:keys [replacement ignore-match] :or {replacement "-" ignore-match #"\s"}}]
(if (keyword? input)
input
(when input
(some-> input name str/trim str/lower-case (str/replace ignore-match replacement) keyword))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Minimalistic spec
Expand Down
Loading