-
Notifications
You must be signed in to change notification settings - Fork 7
ClojureScript
Frinj can run on both the JVM and JS runtimes. The main differences are explained here.
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.
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.
- No support live unit feeds
- No support for infix calculations
- No support for date operations, i.e.
:#2001-01-01units and theto-dateoperator
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.
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.