A small library providing composable, extensible string & date formatters and number parser helper functions for Clojure/Clojurescript. This library is the result of a thi.ng projectwide restructuring / dissolving of the thi.ng/common library.
Note: This library relies on the conditional reader syntax of recent Clojure & Clojurescript versions and therefore is not compatible with Clojure versions < 1.7.0…
[thi.ng/strf "0.2.3"]
(require '[thi.ng.strf.core :as f])
(f/parse-long "decafbad" 16)
;; 3737844653
(f/parse-int "w00t" 10 :fail)
;; :fail
(f/parse-float "3.1415926")
;; 3.1415926
(f/parse-float "w00t" :fail)
;; :fail
(f/format ["Rounded to 1/100th: " (f/float 2)] 3.1415926)
;; "Rounded to 1/100th: 3.14"
(f/format ["#" (f/hex 2) (f/hex 2) (f/hex 2)] 8 64 192)
;; "#0840c0"
(f/format-date (f/now))
;; "2015-05-23 01:43:21"
(f/format-date :mm-dd-yyyy (f/now))
;; "05/23/2015"
(keys f/date-formatters)
;; (:yyyy-mm-dd :yyyy-mm-dd-hh-mm-ss :dd-mm-yyyy :mm-dd-yyyy :dd-mm-yy :hh-mm-ss)
- TBD
0.2.3
[org.clojure/clojure "1.11.1"]
[org.clojure/clojurescript "1.11.4"]
[criterium "0.4.6"]
[com.cemerick/clojurescript.test "0.3.3"]
[lein-cljsbuild "1.1.8"]
This project is written in a literate programming format and requires
Emacs & Org-mode to generate usable source code. Assuming both tools
are installed, the easiest way to generate a working project is via
command line (make sure emacs
is on your path or else edit its path
in tangle.sh
):
git clone https://github.com/thi.ng/strf.git
cd strf
./tangle.sh src/*.org test/*.org
Tangling is the process of extracting & combining source blocks from
.org
files into an actual working project/source tree. Once tangling
is complete, you can cd
into the generated project directory
(babel
) and then use lein
as usual.
The project.clj
file defines an alias to trigger a complete build &
tests for both CLJ & CLJS versions.
cd babel
lein cleantest
To build the Clojurescript version simply run lein cljsbuild test
from the same directory. A small HTML harness for the resulting JS
file is also located in that folder (babel/index.html
), allowing for
further experimentation in the browser.
Editing code blocks or files in Org-mode, then re-loading & testing
changes is quite trivial. Simply launch a REPL (via lein
or Emacs)
as usual. Everytime you’ve made changes to an .org
file, re-tangle
it from Emacs (C-c C-v t
) or tangle.sh
, then reload the namespace
in the REPL via (require 'thi.ng.strf... :reload)
or similar.
(defproject thi.ng/strf "<<version>>"
:description "Extensible CLJ/CLJS string formatting"
:url "<<project-url>>"
:license {:name "Apache Software License 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0"
:distribution :repo}
:scm {:name "git"
:url "[email protected]:thi-ng/strf.git"}
:min-lein-vesion "2.4.0"
:dependencies [<<dep-clj>>
<<dep-cljs>>]
:source-paths ["src"]
:test-paths ["test"]
:profiles {:dev {:dependencies [<<dep-criterium>>]
:plugins [<<dep-cljsbuild>>
<<dep-cljs-test>>]
:global-vars {*warn-on-reflection* true}
:jvm-opts ^:replace []
:aliases {"cleantest" ["do" "clean," "test," "cljsbuild" "test"]}
}}
:cljsbuild {:builds [{:id "simple"
:source-paths ["src" "test"]
:compiler {:output-to "<<cljs-artefact-path>>"
:optimizations :whitespace
:pretty-print true}}]
:test-commands {"unit-tests" ["phantomjs" :runner "<<cljs-artefact-path>>"]}}
:pom-addition [:developers [:developer
[:name "Karsten Schmidt"]
[:url "https://thi.ng"]
[:timezone "0"]]])
<!DOCTYPE html>
<html lang="en">
<head>
<title><<lein-coords>> test</title>
</head>
<body>
<script type="text/javascript" src="<<cljs-artefact-path>>"></script>
</body>
</html>
The autogenerated namespace thi.ng.strf.version
contains a single
symbol version
holding the version string defined above:
(use '[thi.ng.strf.version])
(prn version)
; "<<version>>"
Version | Released | Lein coordinates | Description | Tagged Github URL |
---|---|---|---|---|
0.2.3 | 2022-04-23 | [thi.ng/strf "0.2.3"] | update deps | 0.2.3 |
0.2.2 | 2016-02-28 | [thi.ng/strf "0.2.2"] | bugfix float formatting for certain locales | 0.2.2 |
0.2.1 | 2015-08-30 | [thi.ng/strf "0.2.1"] | bugfix rand-bits-hex | 0.2.1 |
0.2.0 | 2015-08-30 | [thi.ng/strf "0.2.0"] | add date formats, UUIDv4 gen & hex formatters | 0.2.0 |
0.1.0 | 2015-05-25 | [thi.ng/strf "0.1.0"] | initial test release | 0.1.0 |
Name | Role | Website |
---|---|---|
Karsten Schmidt | initiator & principal developer | https://thi.ng |
I’ve got a fairly detailed roadmap and task list to implement over the coming months, but am always happy to receive feedback & suggestions and have issues filed. Once the core engine is more refined I’ll be gladly welcoming other contributions. Thanks for understanding!
This project is open source and licensed under the Apache Software License 2.0.