mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
🔥 Remove unused string related functions from common.data
This commit is contained in:
parent
4925ca2de9
commit
44845d5d94
1 changed files with 22 additions and 37 deletions
|
@ -832,45 +832,30 @@
|
||||||
;; String Functions
|
;; String Functions
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def stylize-re1 (re-pattern "(?u)(\\p{Lu}+[\\p{Ll}\\u0027\\p{Ps}\\p{Pe}]*)"))
|
(def ^:const trail-zeros-regex-1 #"\.0+$")
|
||||||
(def stylize-re2 (re-pattern "(?u)[^\\p{L}\\p{N}\\u0027\\p{Ps}\\p{Pe}\\?!]+"))
|
(def ^:const trail-zeros-regex-2 #"(\.\d*[^0])0+$")
|
||||||
|
|
||||||
(defn- stylize-split
|
#?(:cljs
|
||||||
[s]
|
(defn format-precision
|
||||||
(some-> s
|
"Creates a number with predetermined precision and then removes the trailing 0.
|
||||||
(name)
|
Examples:
|
||||||
(str/replace stylize-re1 "-$1")
|
12.0123, 0 => 12
|
||||||
(str/split stylize-re2)
|
12.0123, 1 => 12
|
||||||
(seq)))
|
12.0123, 2 => 12.01"
|
||||||
|
[num precision]
|
||||||
|
|
||||||
(defn- stylize-join
|
(if (number? num)
|
||||||
([coll every-fn join-with]
|
(try
|
||||||
(when (seq coll)
|
(let [num-str (mth/to-fixed num precision)
|
||||||
(str/join join-with (map every-fn coll))))
|
;; Remove all trailing zeros after the comma 100.00000
|
||||||
([[fst & rst] first-fn rest-fn join-with]
|
num-str (str/replace num-str trail-zeros-regex-1 "")]
|
||||||
(when (string? fst)
|
;; Remove trailing zeros after a decimal number: 0.001|00|
|
||||||
(str/join join-with (cons (first-fn fst) (map rest-fn rst))))))
|
(if-let [m (re-find trail-zeros-regex-2 num-str)]
|
||||||
|
(str/replace num-str (first m) (second m))
|
||||||
(defn stylize
|
num-str))
|
||||||
([s every-fn join-with]
|
(catch :default _
|
||||||
(stylize s every-fn every-fn join-with))
|
(str num)))
|
||||||
([s first-fn rest-fn join-with]
|
(str num))))
|
||||||
(let [remove-empty #(seq (remove empty? %))]
|
|
||||||
(some-> (stylize-split s)
|
|
||||||
(remove-empty)
|
|
||||||
(stylize-join first-fn rest-fn join-with)))))
|
|
||||||
|
|
||||||
(defn camel
|
|
||||||
"Output will be: lowerUpperUpperNoSpaces
|
|
||||||
accepts strings and keywords"
|
|
||||||
[s]
|
|
||||||
(stylize s str/lower str/capital ""))
|
|
||||||
|
|
||||||
(defn kebab
|
|
||||||
"Output will be: lower-cased-and-separated-with-dashes
|
|
||||||
accepts strings and keywords"
|
|
||||||
[s]
|
|
||||||
(stylize s str/lower "-"))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Util protocols
|
;; Util protocols
|
||||||
|
|
Loading…
Reference in a new issue