Socket
Socket
Sign inDemoInstall

babel-plugin-console-groupify

Package Overview
Dependencies
7
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-console-groupify

Wrap console.logs inside a block element (functions) inside a group with function's name


Version published
Maintainers
1
Created

Readme

Source

Console Groupify plugin for Babel

Scratching another itch with this. Sometimes when I'm developing in React, I wish there was a way to group the console.log statements when used inside the life-cycle functions, and add some kind of visual separation between console.logs in different functions.

This plugin checks for console.logs inside functions, and wraps them inside a console.group/console.groupEnd set, with the function name passed in as a variable for console.group. For example:


function aFunctionDeclaration () {
  console.log('hi');
}

const aFunctionExpression = function () {
  console.log('hi')
}

const anArrowFunction = () => {
  console.log('hi')
}

ends up looking like:

▼ aFunctionDeclaration
  | hi

▼ aFunctionExpression
  | hi

▼ anArrowFunction
  | hi

Combining this with the https://github.com/kgrz/babel-plugin-transform-console-log-variable-names, the printf-debugging becomes way better. For example, in a React component:

class MyComponent extends React.Component {
  componentWillReceiveProps ( nextProps ) {
    console.log(this.props);
    console.log(nextProps);
  }
}

prints out:

▼ componentWillReceiveProps
  | this.props: { prop1: "one" }
  | nextProps: { prop1: "two. what the!" }

Actual screenshot from actual usage:

both-plugins-together

Note that both these plugins are at a pretty alpha quality.

Usage

Install the module with:

npm install --save babel-plugin-console-groupify

Include it in your babel configuration either via .babelrc or webpack. Here's a .babelrc example:

{
	"presets": [...],
	"plugins": [
		"console-groupify"
	]
}

Known Issues

  • A spread operator inside a switch statement seems to be causing issues when used with the babel-transform-object-rest-spread plugin. For instance:

    
    function myReducer (state = {}, action = {}) {
      console.log('hi');
      switch (action.type) {
        case 'some_action':
          return { ...state, key: value }
      }
    }
    

Keywords

FAQs

Last updated on 08 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc