Home Web Front-end JS Tutorial JsTraceToIX - Debugging React, Vue, and Node.js just got easier! – no need to clutter your codebase with `console.log`!

JsTraceToIX - Debugging React, Vue, and Node.js just got easier! – no need to clutter your codebase with `console.log`!

Oct 17, 2024 am 06:20 AM

JsTraceToIX - Debugging React, Vue, and Node.js just got easier! – no need to clutter your codebase with `console.log`!

If you've ever had to debug React or Vue components, arrow functions, or complex expressions on Node or the Web Browser, you know the pain of adding multiple console.log statements and making unnecessary code changes. That's where JsTraceToIX comes in!

Project Link

Key Features:

  • Simplifies debugging with minimal code changes.
  • Supports debugging of React, Vue, and Node.js environments, as well as regular browsers.
  • Handles single-line expressions and arrow functions with ease.
  • Easily define names, filter results, and override inputs and outputs for better traceability.
  • Simple function names, like c__ and d__, make it easy to spot and remove traces after catching the bug.
  • Works seamlessly with multithreaded environments.

Bonus: If you're working with Python, check out PyTraceToIX, which offers the same powerful debugging tools for your Python projects.

Say goodbye to complex and messy debugging – with JsTraceToIX, you can capture inputs and display results all in one step, making debugging cleaner and faster!

Check out JsTraceToIX and see how it can simplify your debugging process.

Installation

Environment Require Installation
Browser No
Node.js Yes
React Optional
Vue Yes
npm install jstracetoix --save-dev
Copy after login

React Usage

In this example:

  • cityTax arrow function captures the input price and names it 'Price'.
  • On ShoppingList function:
    • c__ captures the title in the first <td>.
    • c__ captures the output of the cityTax and names it CityTax in the 2nd <td>.
    • d__ displays the aggregated information in a single line: title, price, cityTax, total Price.

The d__ will generate this output:

i0:`Rice` | Price:`10` | CityTax:`5` | _:`15`
i0:`Coffee` | Price:`30` | CityTax:`15` | _:`45`
i0:`Shoes` | Price:`100` | CityTax:`15` | _:`115`
Copy after login
import './App.css';
// Without local installation
import { c__, d__ } from 'https://cdn.jsdelivr.net/gh/a-bentofreire/jstracetoix@1.1.0/component/jstracetoix.mjs';

// If it's installed locally via "npm install jstracetoix --save-dev"
// import { c__, d__ } from 'jstracetoix/component/jstracetoix.mjs';

const cityTax = (price) =&gt; c__(price, {name: 'Price'}) &gt; 20 ? 15 : 5;
const products = [
    { title: 'Rice', price: 10, id: 1 },
    { title: 'Coffee', price: 30, id: 2 },
    { title: 'Shoes', price: 100, id: 3 },
];

function ShoppingList() {
    const listItems = products.map(product =&gt;
        &lt;tr key={product.id}&gt;
            &lt;td&gt;{c__(product.title)}&lt;/td&gt;
            &lt;td&gt;{d__(product.price + c__(cityTax(product.price), { name: 'CityTax' }))}&lt;/td&gt;
        &lt;/tr&gt;
    );

    return (
        &lt;table&gt;&lt;tbody&gt;{listItems}&lt;/tbody&gt;&lt;/table&gt;
    );
}

function App() {
    return (
        &lt;div className="App"&gt;
            &lt;header className="App-header"&gt;
                &lt;ShoppingList /&gt;
            &lt;/header&gt;
        &lt;/div&gt;
    );
}

export default App;
Copy after login

Node.js Usage

In this example:

  • c__.allow() - overrides the input value being debugged when value > 40.00, for other values it doesn't captures the input.
  • d__.allow() - overrides the result value being debugged.
  • d__.after() - stops the program after displaying the result and the captured fields.
import { c__, d__ } from 'jstracetoix';

const products = [
    { "name": "Smartphone 128GB", "price": 699.00 },
    { "name": "Coffee Maker", "price": 49.99 },
    { "name": "Electric Toothbrush", "price": 39.95 },
    { "name": "4K Ultra HD TV", "price": 999.99 },
    { "name": "Gaming Laptop", "price": 1299.00 }];

const factor = (price) =&gt; price &lt; 1000 ? 1.10 : 1;

const prices = d__(products.map(product =&gt; c__(product.price,
    {
        allow: (index, name, value) =&gt; value &gt; 40.00 ?
            Math.floor(value * factor(value)) : false,
        name: product.name.substring(0, 10)
    })), {
    allow: (data) =&gt; data._.map((v, i) =&gt; `${i}:${v}`),
    after: (data) =&gt; process.exit() // exits after displaying the results
});
// Smartphone:`768` | Coffee Mak:`54` | 4K Ultra H:`1099` | Gaming Lap:`1299` | _:`["0:699","1:49.99","2:39.95","3:999.99","4:1299"]`

// this code is unreachable
for (const price in prices) {
    let value = price;
}
Copy after login

Output

Environment Default Output Function
Browser console.debug
Node.js process.stdout
React console.debug
Vue console.debug

Except for Node.js environment, the output is displayed in the browser's developer tools under the "Console Tab".
Since the output is generated using console.debug, it can easily be filtered out from regular console.log messages.

The default output function can be override using init__({'stream': new_stream.log })

Metadata

The d__ function callbacks allow, before and after will receive a parameter data with the allowed inputs plus the following meta items:

  • meta__: list of meta keys including the name key.
  • thread_id__: thread_id being executed
  • allow_input_count__: total number of inputs that are allowed.
  • input_count__: total number of inputs being captured.
  • allow__: If false it was allowed. Use this for after callback.
  • output__: Text passed to before without new_line.
  • name: name parameter

Documentation

Package Documentation

The above is the detailed content of JsTraceToIX - Debugging React, Vue, and Node.js just got easier! – no need to clutter your codebase with `console.log`!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

Example Colors JSON File Example Colors JSON File Mar 03, 2025 am 12:35 AM

Example Colors JSON File

8 Stunning jQuery Page Layout Plugins 8 Stunning jQuery Page Layout Plugins Mar 06, 2025 am 12:48 AM

8 Stunning jQuery Page Layout Plugins

Build Your Own AJAX Web Applications Build Your Own AJAX Web Applications Mar 09, 2025 am 12:11 AM

Build Your Own AJAX Web Applications

What is 'this' in JavaScript? What is 'this' in JavaScript? Mar 04, 2025 am 01:15 AM

What is 'this' in JavaScript?

Improve Your jQuery Knowledge with the Source Viewer Improve Your jQuery Knowledge with the Source Viewer Mar 05, 2025 am 12:54 AM

Improve Your jQuery Knowledge with the Source Viewer

10 Mobile Cheat Sheets for Mobile Development 10 Mobile Cheat Sheets for Mobile Development Mar 05, 2025 am 12:43 AM

10 Mobile Cheat Sheets for Mobile Development

See all articles