Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cloojure/tupelo
Browse files Browse the repository at this point in the history
  • Loading branch information
catalan42 committed Dec 4, 2024
2 parents d5c402f + f0b51d8 commit 4285e8a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@
}
}
}

8 changes: 8 additions & 0 deletions src/tupelo/string.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@
txt :- s/Str]
(clojure.string/join (clojure.core/take n txt)))

(s/defn drop-lines :- s/Str
"Drops the first N lines of a multi-line string, returning a string result."
[N :- s/Int
text :- s/Str]
(clojure.string/join \newline
(clojure.core/drop N
(clojure.string/split-lines text))))

(s/defn indent :- s/Str ; #todo add readme
"Indents a string by pre-pending N spaces. Returns a string result."
[n :- s/Int
Expand Down
12 changes: 12 additions & 0 deletions test/tst/tupelo/string.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,15 @@
(is= "Cost: 00123" (str/format "Cost: %05d" 123))
(is= "Cost: 123.46" (str/format "Cost: %8.2f" xx))))

(verify
(let [sample-text "hello
there
again"
drop-1-str (str/drop-lines 1 sample-text)
drop-2-str (str/drop-lines 2 sample-text)]
(is-nonblank-lines= drop-1-str
"there
again")
(is-nonblank-lines= drop-2-str
"again")))

0 comments on commit 4285e8a

Please sign in to comment.