# Espree-logging-module

![npm (scoped)](https://img.shields.io/npm/v/@alu0100901214/espree-logging-module?color=red)

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [Installation][1]
-   [Executable][2]
-   [Code][3]
-   [Example][4]
    - [Input][5]
    - [Output][6]
-   [addLogging][7]
    -   [Parameters][8]
-   [Pattern][9]
-   [Example][10]
    -   [Input][11]
    -   [Output][12]


## Installation

```
npm install @alu0100901214/espree-logging-module --save
```

## Executable

Executable usage:

```
Usage: logging-espree [options] <filename> [...]

Es un programa para parsear un fragmento de código.

Options:
  -V, --version            output the version number
  -o, --output <filename>  write the output on a filename
  -p, --pattern <pattern>  indicates the pattern of the function you want to add a log
  -h, --help               display help for command
```

## Code

Code usage:

```
const addlogging = require('@alu0100901214/espree-logging-module/src/logging-espree');
```

## Example

```
npx addlogging input.js -o output.js
```

### Input

```
function foo(a, b, c) {
    let x = 'tutu';
    let y = (function (x) { return x*x })(2);
    let z = (e => { return e +1 })(4);
}
foo(1, 'wut', 3);
```

### Output

```
function foo(a, b, c) {
    console.log(`Entering foo(${ a },${ b },${ c }) at line 1`);
    let x = 'tutu';
    let y = function (x) {
        console.log(`Entering <anonymous function>(${ x }) at line 3`);
        return x * x;
    }(2);
    let z = (e => {
        console.log(`Entering <anonymous function>(${ e }) at line 4`);
        return e + 1;
    })(4);
}
foo(1, 'wut', 3);
```

## addLogging

Add console.log in every Function.

### Parameters

-   `code` **[string][12]** String with the code.

Returns **[string][12]** Return the string with the console.log inserted.

## Pattern

Pattern option:

You can use a regex pattern that allows you to locate the name of a function and add the console.log to it.

## Example

```
npx addlogging input.js -p fo* -o output.js
```

### Input

```
function foo(a, b, c) {
    let x = 'tutu';
    let y = (function (x) { return x*x })(2);
    let z = (e => { return e +1 })(4);
}
foo(1, 'wut', 3);
```

### Output

```
function foo(a, b, c) {
    console.log(`Entering foo(${ a },${ b },${ c }) at line 1`);
    let x = 'tutu';
    let y = function (x) {
        return x * x;
    }(2);
    let z = (e => {
        return e + 1;
    })(4);
}
foo(1, 'wut', 3);
```

[1]: #Installation

[2]: #Executable

[3]: #Code

[4]: #Example

[5]: #Input

[6]: #Output

[7]: #addlogging

[8]: #parameters

[9]: #Pattern

[10]: #Example-1

[11]: #Input-1

[12]: #Output-1

[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object