@alu0100901214/espree-logging-module
Version:
Es un programa para parsear un fragmento de código.
163 lines (114 loc) • 2.9 kB
Markdown

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
- [Installation][1]
- [Executable][2]
- [Code][3]
- [Example][4]
- [Input][5]
- [Output][6]
- [addLogging][7]
- [Parameters][8]
- [Pattern][9]
- [Example][10]
- [Input][11]
- [Output][12]
```
npm install @alu0100901214/espree-logging-module --save
```
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 usage:
```
const addlogging = require('@alu0100901214/espree-logging-module/src/logging-espree');
```
```
npx addlogging input.js -o output.js
```
```
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);
```
```
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);
```
Add console.log in every Function.
- `code` **[string][12]** String with the code.
Returns **[string][12]** Return the string with the console.log inserted.
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.
```
npx addlogging input.js -p fo* -o output.js
```
```
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);
```
```
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);
```
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]:
[]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object