Skip to content

Commit 4536979

Browse files
authored
Merge pull request #15 from Rende11/replace
Add default empty string arg and add capitalize func
2 parents 4760df7 + 7309840 commit 4536979

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ To be written.
540540

541541
### toUpperCase(s)
542542

543+
### capitalize(s)
544+
543545
### range(begin, end, step)
544546

545547
### flatten(array)

spec/functions_spec.yml

+69
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ tests:
2222
result:
2323
first: ["foo", "bar", "baz"]
2424

25+
26+
- desc: splitStr
27+
scope:
28+
s: null
29+
template:
30+
first: $ splitStr(s, " +")
31+
result:
32+
first: [""]
33+
2534
- desc: splitStr with limit = 0
2635

2736
scope:
@@ -94,3 +103,63 @@ tests:
94103
a: "Hello JUTE mapping tool !"
95104
b: ""
96105
c: ""
106+
107+
- desc: toLowerCase
108+
scope:
109+
a: "HELLO"
110+
b: ""
111+
c: null
112+
d: "Test"
113+
114+
template:
115+
a: $ toLowerCase(a)
116+
b: $ toLowerCase(b)
117+
c: $ toLowerCase(c)
118+
d: $ toLowerCase(d)
119+
120+
result:
121+
a: "hello"
122+
b: ""
123+
c: ""
124+
d: "test"
125+
126+
- desc: toUpperCase
127+
scope:
128+
a: "HELLO"
129+
b: ""
130+
c: null
131+
d: "Test"
132+
133+
template:
134+
a: $ toUpperCase(a)
135+
b: $ toUpperCase(b)
136+
c: $ toUpperCase(c)
137+
d: $ toUpperCase(d)
138+
139+
result:
140+
a: "HELLO"
141+
b: ""
142+
c: ""
143+
d: "TEST"
144+
145+
- desc: capitalize
146+
scope:
147+
a: "HELLO"
148+
b: ""
149+
c: null
150+
d: "Test"
151+
e: "one"
152+
153+
template:
154+
a: $ capitalize(a)
155+
b: $ capitalize(b)
156+
c: $ capitalize(c)
157+
d: $ capitalize(d)
158+
e: $ capitalize(e)
159+
160+
result:
161+
a: "Hello"
162+
b: ""
163+
c: ""
164+
d: "Test"
165+
e: "One"

src/jute/core.cljc

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
(def standard-fns
111111
{:join str/join ;; deprecated
112112
:joinStr str/join
113-
:splitStr (fn [s re & [limit]] (str/split s (re-pattern re) (or limit 0)))
113+
:splitStr (fn [s re & [limit]] (str/split (or s "") (re-pattern re) (or limit 0)))
114114
:substring subs ;; deprecated
115115
:substr subs
116116
:replace (fn [s re to]
@@ -126,8 +126,9 @@
126126
:range range
127127
:randNth rand-nth
128128
:toString to-string
129-
:toLowerCase str/lower-case
130-
:toUpperCase str/upper-case
129+
:toLowerCase #(str/lower-case (or % ""))
130+
:toUpperCase #(str/upper-case (or % ""))
131+
:capitalize #(str/capitalize (or % ""))
131132
:toKeyword keyword
132133
:hash hash
133134
:toInt (fn [v] (if (string? v)

0 commit comments

Comments
 (0)