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

console-log-html

v2.0.2

Published

Copies/redirects console output to HTML

Downloads

353

Readme

A tiny library that overrides the browser's console.* functions allowing the logged messages to be displayed in HTML.

Coverage Status Build Status Deps Deps

NPM

Migrating from 1.x to 2.0? See MIGRATING.md

Installation:

Simply include the file on your page:

<script type="application/javascript" src="console-log-html.min.js"></script>
<!-- Or, alternatively, use the CDN URL -->
<script type="application/javascript" src="//cdn.rawgit.com/Alorel/console-log-html/master/console-log-html.min.js"></script>

It can also be included as a dependency from npm:

npm install console-log-html --save
(function(){ // Your closure
    var ConsoleLogHTML = require('console-log-html');
})();

Usage:

    <ul id="myULContainer"></ul> <!-- I will hold the log messages -->
    <script type="application/javascript" src="console-log-html.min.js"></script>
    <script>
        ConsoleLogHTML.connect(document.getElementById("myULContainer")); // Redirect log messages
        ConsoleLogHTML.disconnect(); // Stop redirecting
    </script>

You can also instruct the script to only log to the console by passing a second argument to console.*(), e.g.:

console.log("foo"); // Logs "foo" to HTML
console.log("Look, some JSON:", {foo: 'bar'}); // Logs "Look, some JSON: Object {"foo":"bar"}" to HTML
console.skipHtml.log("bar"); // Logs only to the console

Customisation

Default styles

The default css classes can be overriden in ConsoleLogHTML.DEFAULTS:

    ConsoleLogHTML.DEFAULTS.error = "some-error-css-class"; // Will be applied to console.error()
    ConsoleLogHTML.DEFAULTS.log = "another-override"; // Will be applied to console.log()

During connect()

The connect method has the following signature:

function connect(target, options, includeTimestamp, logToConsole){}
  • target has already been covered - it's the <ul> element
  • options allows you to override the css classes in ConsoleLogHTML.DEFAULTS for the duration of the connect, i.e. it would not save the values. For example, if you wanted to override the log and warn CSS classes you could pass the object
{
     "warn": "my-warn-css-class",
     "log": "my-log-css-class"
}
  • includeTimestamp - when set to true (the default value), a timestamp will be prepended to each message as it appears in the <ul>. The timestamp's format depends on the user as it is created via
(new Date()).toLocaleTimeString()
  • logToConsole - when set to true (the default value), appear both in the console and the <ul>; when set to false, they appear only in the <ul>.
  • appendAtBottom - when set to true (default=false), log messages will be appended at the end of the <ul>-list.

More information: