How to use the konami-js library in a ClojureScript project24 May 2020
Recently, konami-js library got included in the CLJSJS project. This post will show how to include and use the konami-js library in your ClojureScript project.
Since all packages from CLJSJS are pushed to Clojars we can include
the konami library as a regular CLJS dependency.
This is the
:dependency key Leiningen from
:dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/clojurescript "1.10.520"] [cljsjs/konami "1.6.2-0"]] ;; this is current version of the library
The library exposes only one variable which is an easter egg constructor. It accepts only one parameter, a function that will be called when the Konami code is inputted. The function represents the easter egg itself and it can do whatever is needed.
Hello world example is to display a message:
(ns konami-cljs.core (:require cljsjs.konami)) (def easter-egg (js/Konami. (fn  (js/alert "Hello Konami code!"))))
As mentioned the argument function can do anything. For example, it can redirect you to a different (secret) page:
(def easter-egg (js/Konami. (fn  (js/window.open "https://example.com"))))
Once defined the
easter-egg var can remain untouched.
You can see the whole project here.
Happy easter egg planting!