1.1.4 • Published 10 months ago

logs-injector v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

logs-injector

A simple and useful tool to automatically insert console.log statements into your JavaScript functions for debugging purposes.

Table of Contents

Installation

This package is available via npm.

Before installing, make sure you have Node.js installed.

To install the package, run the following command:

Usage

The logs-injector tool can be used to automatically insert console.log statements into your JavaScript functions. Here’s how to use it effectively:

Step 1: Install the Package

Make sure you have installed the package using npm:

npm install logs-injector

Start

install logs-injector

Run the Tool

node path/to/logs-injector.js path/to/your/javascript-file.js

Example

function multiply(x, y) {
  return x * y;
}

console.log(multiply(5, 10));

After Running logs-injector

function multiply(x, y) {
  console.log('Function: multiply | Variables: x, y');
  return x * y;
}

console.log(multiply(5, 10));

Features

Parsing: The JavaScript file is read and parsed into an AST.

const ast = parser.parse(code, { sourceType: 'module', plugins: ['jsx'] });

Explanation

The AST is traversed to locate function declarations, expressions, and arrow functions.

traverse(ast, {
    FunctionDeclaration(path) {
        insertConsoleLog(path);
    },
    FunctionExpression(path) {
        insertConsoleLog(path);
    },
    ArrowFunctionExpression(path) {
        insertConsoleLog(path);
    },
});

Log Injection:

A console log statement is injected at the start of each identified function.

Code Generation:

The modified AST is transformed back into JavaScript code.

1.1.4

10 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago