npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clogjs

v0.0.1

Published

Clog your console for fun and profit

Downloads

1

Readme

Clog

Clog your console for fun and profit!

This is a simple logging library written to address the common tasks first and provide sugar. It is Chrome browser oriented but works with node.js as well.

Clog is written in CoffeeScript, but you can use it in JavaScript with no problems. However, the examples below will be in CoffeeScript.


Installation

Clog is available on npm as clogjs (as clog has already been taken by a vastly inferior library).

// package.json
{
  "devDependencies" : {
    "clogjs" : "*"
  }
}

or you can simply include the file in your browser like so:

<script type="text/javascript" src="/path/to/console.image.js"></script>
<script type="text/javascript" src="/path/to/Clog.js"></script>

Console.image is not required, but is STRONGLY recommend to receive fun and profit.


Things it do:

Basics

  Clog.log 'howdy'

will log out "0 ---> howdy". Clog keeps and internal index of logs, so most logs will start with "#{index} --->". Clog.log will also accept multiple arguments just like console.log.

  Clog.info 'neat!'
  Clog.warn 'super neat!'

The above wraps console.info and console.warn in the same way that Clog.log wraps console.log.


Colors

Clog provides easy access to colors! Simply call the colors like so

  Clog.red    "I'm red!"
  Clog.blue   "I'm blue!"
  Clog.green  "I'm green!"
  Clog.orange "I'm orange!"
  Clog.purple "I'm purple!"

and yes this works in Chrome and Nodejs. Prefer more brevity? you can also use each color as the first three letters. For example you can call Clog.purple as Clog.pur.

Color commands will also JSON.stringify the first argument for you.


Keanu

Its often necessary to write something simple to the console, in-order to just see if that line of code executes. Many write something like:

  console.log 'woah'

with Clog, you can do abit better, with Keanu. Clog.keanu() does the same job as console.log 'woah', but will instead log out a random Keanu Reeves quote! If you have console.image installed you will get a small image of Keanu looking good in the matrix. There is also:

  // logs out either a quote or small image from the matrix
  Clog.keanu()

  // logs a nice big gif of Keanu
  Clog.keanu true 

  // also colored keanus! all supported colors available
  Clog.keanu 'red'

Arnold

With similar motivation to Keanu, sometimes you log something simple that you expect to log, and it doesn't. There is a bug in your code! So you leave that console message around and rejoice when you finally see it grace your terminal. Well here is where Arnold comes in. Instead of leaving yourself a message like console.log 'success' go big with Clog.arnold(). Arnold if you have console.image installed, you will be greeted with a random gif of Arnold Schwarzenegger kicking ass, like you just kicked ass.

  // logs out either a quote or a big gif of ass kickery
  Clog.arnold()

  // also colored arnolds! all supported colors available
  Clog.arnold 'blue'

Now and Since

For measuring time of code execution you can use Clog.now() and Clog.since() like so:

Clog.now()
$.getJSON '/slowness.json', (data) ->
  Clog.since()

This is just candy wrapping console.time (the little known native time measurement console feature). You can optionally name your measurement Clog.now('ajax delay') (useful if you have more than one time measurement going on), otherwise it will default to 'tardis' as the label.


Test

Have you written console logs to determine the value of variables? Do they look like this:

  var foo = 5, bar = 60;
  console.log 'foo', foo, 'bar', bar
  // or 
  console.log 'foo '+foo, 'bar '+bar

Its annoying to write extra code just to know the name of the variable you are logging. With Clog you have:

  var foo = 5, bar = 60;
  Clog.test foo, bar
  // roughly equivalent to 
  console.log
    foo : 5
    bar : 60

Count

For easy logging out the number of times code has executed, simply call count like so:

  for [0...5]
    Clog.count 'simple loop'
  // will log out
  console.log 'simple loop -> 1 times'
  console.log 'simple loop -> 2 times'
  console.log 'simple loop -> 3 times'
  console.log 'simple loop -> 4 times'
  console.log 'simple loop -> 5 times'
  console.log 'simple loop -> 6 times'

Game Over

If you Clog out more than 2000 logs Clog will log out a 'GAME OVER' message like below: GAMEOVER and then die to prevent your browser from crashing.


Error Memes

This one is really only if you have console.image. There are some errors you can foresee as a developer. Ones that should stop everything until its fixed. Ones that are the result of you breaking things you know you should not break. When that happens its painful, so why not preemptively inject some levity into the situation? Clog.meme fires console.image's console.meme functionality along with a native Error. If you are in an environment without console.image it just throws a native Error.