format
exists in ClojureScript. It comes from the Google Closure Library (GCL), which is a fundamental part of ClojureScript. Unfortunately it can be tricky to use it. The conventional way is to require both [goog.string :as gstring]
and [goog.string.format]
, and then to use gstring.format
. For example:
(ns rostering.components.services
(:require
[goog.string :as gstring]
[goog.string.format]))
(str "$" (gstring/format "%.2f" 2.5))
Pretty much the same example is at the bottom of this short page of documentation.
I can't say enough how much a part of ClojureScript is the GCL. Here is another reference. This means that format
is a function that is part of ClojureScript.
Here's a quote from that reference:
The Google Closure Library is a javascript library developed by Google, based on a modular architecture and provides cross-browser functions for DOM manipulations and events, ajax and JSON, among other features.
It’s written specifically to take advantage of the Closure Compiler (that is used internally by the ClojureScript compiler).
And ClojureScript is built on Closure Compiler and Closure Library. In fact, ClojureScript namespaces are Closure modules.
clojure.pprint/cl-format
would be available in Clojurescript. It's an alternative to Clojure's Java-basedformat
. In a quick test I did,clojure.pprint
did not seem to be available in Clojurescript, but I don't know why it wouldn't be. – Mars