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

babel-plugin-auto-console-log

v1.1.20

Published

A Babel plugin that adds console.log statements automatically.

Downloads

28

Readme

Auto console log 🚀

babel-plugin-auto-console-log is a Babel plugin that automatically adds console.log() statements to your JavaScript code. This library is useful for debugging code, as it adds console.log() statements to specific parts of the code so that you can see the values of variables and the results of operations.

The main goal of babel-plugin-auto-console-log is to make code debugging easier and faster by automatically adding console.log() statements to your code. This means that you won't have to manually add console.log() statements to your code every time you need to debug it, which saves time and reduces errors.

Install

npm i babel-plugin-auto-console-log --save-dev

# or

yarn add babel-plugin-auto-console-log -D 

# or

pnpm i babel-plugin-auto-console-log --dev

How to use 📝

Auto Console Log is a Babel transform that can be used both on the client-side and server-side of a JavaScript project.

Here is an example on how you can implement it using the @babel/standalone package:

  1. Install both packages:
npm i @babel/standalone babel-plugin-auto-console-log --save-dev
  1. Register the plugin and create a function to transform your code:
import Babel from '@babel/standalone';
import autoConsoleLog from 'babel-plugin-auto-console-log';
// const autoConsoleLog = require("babel-plugin-auto-console-log")

Babel.registerPlugin('babel-plugin-auto-console-log', autoConsoleLog());
  1. Create a function to transform your code:
const transform = (source) =>
    Babel.transform(source, {
      plugins: ['babel-plugin-auto-console-log']
    }).code;
  1. You are now ready to transform your code! using the transform() function.

Here is the complete code:

import Babel from '@babel/standalone';
import autoConsoleLog from 'babel-plugin-auto-console-log';
// const autoConsoleLog = require("babel-plugin-auto-console-log")

Babel.registerPlugin('babel-plugin-auto-console-log', autoConsoleLog());

const transform = (source) =>
    Babel.transform(source, {
      plugins: ['babel-plugin-auto-console-log']
    }).code;

Options

  • consoleMethod default: log : The consoleMethod parameter is used to specify the logging method to be used to print the output of a function. For example, if "warn" is provided as the value for the consoleMethod parameter, the output will be printed with the "< consoleObject >.warn" method instead of the default console.log method.

  • consoleObject default: console : The consoleObject parameter is an argument that can be provided to a function and its purpose is to specify the console object that will be used to print the output of the function. For example if "logger" is the given value the output will be "logger.< consoleMethod >".

Constants

CONSOLE_METHODS

CONSOLE_METHODS gives you a list of all the methods that console has, so that you don't make a mistake when using a method other than "log".

To use this constant you must import it from "babel-plugin-auto-console-log/constants" as follows:

import { CONSOLE_METHODS } from "babel-plugin-auto-console-log/constants"

// or 

const { CONSOLE_METHODS } = require("babel-plugin-auto-console-log/constants")

Examples

Here are some examples of how the babel-plugin-auto-console-log plugin works:

Input

const foo = 42;

foo;

Output

const foo = 42;

console.log(foo);

Input

1 + 1;

Output

console.log(1 + 1);

Input

10 > 5 ? "Yes!" : "No!";

Output

console.log(10 > 5 ? "Yes!" : "No!");

Input

function sayHi (name) {
    return `Hello ${name}!!!`
}

sayHi("foo");

Output

function sayHi (name) {
    return `Hello ${name}!!!`
}

console.log(sayHi("foo"));

Contributing 🤝

Thank you for your interest in contributing to babel-plugin-auto-console-log! We appreciate your support and welcome any contributions to this project.

To get started, please refer to the CONTRIBUTING.md file for guidelines on how to contribute to this project.

Once again, thank you for your interest in contributing to babel-plugin-auto-console-log!