• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Clojure
  • Created about 11 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A ClojureScript library providing wrappers for the JavaScript console API.

Shodan

A ClojureScript library providing wrappers for the JavaScript console API.

Contents

"Installation"

Add Shodan as a :dependency in your project.clj file.

[shodan "0.4.2"]

Usage

Console wrappers are in the shodan.console namespace.

(ns omfg
  (:require [shodan.console :as console :include-macros true])

Logging

Wrappers for console.log, console.debug (not available for NodeJS), console.info, console.warn, console.error.

(console/log "You move like an insect."
             "You think like an insect."
             "You are an insect.")

(console/debug "I have no choice but to destroy this starship.")
(console/info "Matters on Deck 5 also require your attention.")
(console/warn "I will not abide disobedience.")
(console/error "It is hopeless.")

Message grouping (not available for NodeJS)

Wrappers for console.group(), console.groupCollapsed(), console.groupEnd().

(console/group "SHODAN")
(console/log "Launch in to the many."
             "Cut out it's heart."
             "And I will reward you with continued existence.")
(console/warn "Fail me, and I will put an end to your disgusting biology.")
(console/group-end)

(console/group-collapsed "SHODAN")
(console/log "Only one egg remains, insect.")
(consol/group-end)

Profiling (not available for NodeJS)

Wrappers for console.profile(title) and console.profileEnd().

;; js/console.profile
(console/profile-start "Accessing the primary data loop")

(loop [xs ["x" "y" "z"] ys (array)]
  (if-let [x (first xs)]
    (recur (next xs) (.push ys x))
    ys))

;; js/console.profileEnd
(console/profile-end "Accessing the primary data loop")

Timing

Wrappers for console.time() and console.timeEnd().

(console/time-start "Addition")
(+ 1 1)
(console/time-end "Addition")

Macros

Shodan comes with a some simple macros for message grouping, profiling, and timing.

Grouping (not available for NodeJS)

(with-group "America Online"
  (dotimes [_ 10]
    (console/info "You have mail.")))

(with-group-collapsed "ERMAHRERC ERNLERN"
  (dotimes [_ 10]
    (console/info "U HERV MAHL.")))

Profiling (not available for NodeJS)

(with-profile "Perf Madness"
  "FIXME: Perf code here.")

Timing

(time (str "I run on beams. I run on laser beams."))
;; => Time Elapsed: 0.001ms

Inspection

Inspect ClojureScript data structures and display their structure to the browser console:

(ns omfg
  (:require [shodan.inspection :refer [inspect]]))

Use it just like you would clojure's clojure.pprint/pprint:

(inspect my-super-complex-data)

Why?

Because I'm tired of copy/pasting/rewriting the same code all the time and seeing everyone else do the same. Also, having a basic wrapper for the console API makes it easier to create custom logging functions and macros.

WTF is Shodan?

S.H.O.D.A.N. is actually an acronym for Sentient Hyper Optimized Data Access Network. I acknowledge this library has pretty much nothing to do with any of that.

License

Copyright Β© 2013 Joel Holdbrooks

Distributed under the Eclipse Public License, the same as Clojure.