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

devtools-chopper

v1.2.0

Published

Chopper is a Javascript log display devtool which allows you to monitor application logs in DOM

Downloads

22

Readme

by Protosus

devtools-chopper

Github Build Status npm version License Li

Chopper is a Javascript log display devtool which allows you to monitor application logs in DOM. Main feature being the ability to PIN specific type logs to make is easier to track log messages you're most interested in.

Its highly customizable and extends overdrag package which allows element to be dragged, resized and placed anywhere on screen.

🌲🌲🌲 chopping logs 🌲🌲🌲

Demo

You can view a live demo here

Validator

Installation

NPM

To install devtools-chopper, use p/npm yarn:

  • using npm
npm install devtools-chopper
  • using yarn
yarn add devtools-chopper
  • using pnpm
pnpm add devtools-chopper

Usage

devtools-chopper is framework agnostic and can be used in any JS environment, React, Angular, Vue and supports TS out-of-the-box.

import Chopper from "devtools-chopper";
const chopper = new Chopper();

// standard scroll
chopper.$log('Message');
// pinned
chopper.$pin.log('Message');

API

Standard log API available:

  • $debug()
  • $log()
  • $info()
  • $warn()
  • $error()

To pin a message that is not los in scrolling jungle, use $pin.<type>, the message will be printed as a pinned entry as well as in the scrolling set of messages. Its a great way to track logs without searching for it. However, using standard console of devtools, you can simply enter a filter parameter to achieve the very same effect.

Each takes unlimited number of arguments, just like a typical console method would.

// ...
chopper.$log('arg1', 'arg3', 'arg3', ...);

Messages will not be rendered if logLevel is set to filter out a message log type.

Ex: If logLevel is set to none, no messages will be printed.

Here is a map of logLevel gates:

{
    "verbose": ["debug", "log", "info", "warn", "error"],
    "info": ["info", "warn", "error"],
    "warn": ["warn", "error"],
    "error": ["error"],
    "none": [],
}
  • setLogLevel( level Levels ): changes current log level
  • console(data: unknown[], type: ConsoleType, info: EntryInfo): Override method that prints to console. Ex: if you'd like it to print only raw data without prettifying it with styles and other info.
  • renderEntry(parent: HTMLElement, data: unknown[], type: ConsoleType, info: EntryInfo): override how the chopper renders log entry element.

Constructor

The Overdrag class constructor accepts an object with the following properties:

  • name (required): name of logging

Optional:

  • level (default: 'verbose'): Controls both chopper's and console outputs made by chopper.

  • styles (default: current chopper console only theme): CSS styles object. Use plain CSS to style DOM elements.

  • console (default: 'true'): Print to console.

  • element (default: randomly positioned div in body): The DOM element container of chopper.

  • minContentHeight (default: Overdrag.DEFAULTS.minContentHeight): The minimum height of the DOM element (CSS height) in pixels. This prevents resizing smaller than the specified value.

  • minContentWidth (default: Overdrag.DEFAULTS.minContentWidth): The minimum width of the DOM element (CSS width) in pixels. This prevents resizing smaller than the specified value.

  • maxContentHeight (default: Overdrag.DEFAULTS.maxContentHeight: Infinity): The max height of the DOM element (CSS height) in pixels. This prevents resizing bigger than the specified value.

  • maxContentWidth (default: Overdrag.DEFAULTS.maxContentWidth: Infinity): The max width of the DOM element (CSS width) in pixels. This prevents resizing bigger than the specified value.

  • snapThreshold (default: Overdrag.DEFAULTS.snapThreshold): The distance to the edge of the relative parent element (top, left, bottom, right) when the element should snap to it.

  • controlsThreshold (default: Overdrag.DEFAULTS.controlsThreshold): The distance to the edge of the element (top, left, bottom, right) when the element should show resize cursor and activate control points.

  • clickDetectionThreshold (default: Overdrag.DEFAULTS.clickDetectionThreshold): The threshold distance to detect a click event. If you've started dragging the element, mouse up event will not trigger click event.

  • stack (default: false): If true, an Overdrag parent element that has a recursively embedded Overdrag elements as a child will retain over state while the child is active. Else, the parent element will be set to out state (inactive)

NOTE
Multiple instances can be spawned. Each will position itself randomly unless you specify its element style or provide your own element.

Extending Class

Use devtools-chopper functionality to track any class instances logs, so you can monitor its activity:

import Chopper from "devtools-chopper";

class MyClass extends Chopper {
    constructor(){
        super({name: 'MyClass'});
        this.$log(this.name + 'initialized');
    }
}

NOTE
Extends overdrag which inherits eventemitter3.

Description

You can control many different aspects of the instance by referring to its overdrag extension documentation

Log Entry

Each log entry includes the following info:

  • Type of log and time of entry <log type>@<time> ex: debug@12345555353
  • Log call origin file path and position: <file path>:<line>:<column>
  • Log message as string

In Brief:

devtools-chopper includes the following functionalities and interactions:

  • Draggable: within offsetParent bounds
  • Resizable: using 8 control points
  • Play, Pause of scrollable logs
  • Level switch: changes level interactively, by using header buttons
  • Style every aspect of it using CSS or provide JSON styles options

Console

devtools-chopper prints to console automatically using its current gates. When printing to console, the theme will be applied as well! Alt text

NOTE
You can disable console printing by passing {console: false}

const chopper = new Chopper({name: 'Event Monitoring', console: false});

Road map

  • Enable unit tests
  • Enable pinning logs interactively by selecting log origin you're interested in.
  • Enable logged objects preview

PS

Li

Enjoy! 🎉🎉🎉