ClojureScript - martintrojer/frinj GitHub Wiki
Frinj can run on both the JVM and JS runtimes. The main differences are explained here.
Setting up the Unit Database
The unit database needs to be loaded into Frinj. This is simple in the Clojure/JVM case where (frinj-init!)
just reads a resource from the .jar file.
On a JS runtime we need to manually handle this. Frinj comes with an example on how to do this in NodeJS, using the provided frinj.node
namespace.
(ns frinj.node.example
(:require [frinj.node :refer (frinj-init!)]
[frinj.ops :refer (fj to)]))
(defn -main [& args]
(frinj-init! "resources/units.edn")
(println (fj :inch))
(println (fj :cm))
(println (-> (fj :teaspoon :water :c :c) (to :gallons :gasoline) str)))
In this case frinj-init
takes a parameter with the name of the units file.
Browser
In a browser scenario the units.edn
file can be served and read in a similar fashion. The browser example shows how this can be done.
Other Differences
- No support live unit feeds
- No support for infix calculations
- No support for date operations, i.e.
:#2001-01-01
units and theto-date
operator
Advanced compilation
The frinj.node
namespace uses some functions in the node.js fs
module. In order for this to work when using advanced compilation mode, you need to add the externs.js file to your cljsbuild configuration.
Compilation warnings
When compiling the parser.cljs
file a number of warnings are issue by the compiler. These can be safely ignored and will be fixed in a future release.