Interpreter of the Tokenscript language for design tokens, in Clojure and ClojureScript.
Tokenscript is an expression language for design token values:
{spacing.base} * 2, lighten({color.primary}, 0.2), 16px. This
library parses and evaluates it, and resolves whole token sets whose
values reference each other, with incremental updates. The same code
runs on the JVM and in JavaScript. Penpot uses it to resolve design
tokens.
It is a port of the TypeScript reference implementation, tokens-studio/tokenscript-interpreter.
Add it as a git dependency to deps.edn:
{:deps
{penpot/tokenscript-interpreter
{:git/url "https://github.com/penpot/tokenscript-interpreter"
:git/sha "<commit sha>"}}}ClojureScript builds need shadow-cljs: the bundled schemas are inlined at compile time by a macro that records the files it reads.
(require '[tokenscript.core :as ts]
'[tokenscript.processor :as processor])
(def result
(ts/build {"base" {:value "8"}
"double" {:value "{base} * 2px"}}))
(processor/tokens->strings result)
;; => {"base" "8", "double" "16px"}See docs/:
Needs the Clojure CLI, Babashka and Node.js.
bb test # JVM and ClojureScript tests
bb lint # clj-kondo and cljfmt checkSee Testing for the other tasks and CONTRIBUTING.md for the commit format.