如果您曾经需要在 node 或 web 浏览器上调试 react 或 vue 组件、箭头函数或复杂表达式,您就会知道添加多个 console.log 语句和进行不必要的代码更改的痛苦。这就是 jstracetoix 发挥作用的地方!
项目链接
主要特点:
奖励:如果您使用 python,请查看 pytracetoix,它为您的 python 项目提供了同样强大的调试工具。
立即学习“前端免费学习笔记(深入)”;
告别复杂、凌乱的调试——使用 jstracetoix,您可以一步捕获输入并显示结果,让调试更干净、更快!
查看 jstracetoix 并了解它如何简化您的调试过程。
environment | require installation |
---|---|
browser | no |
node.js | yes |
react | optional |
vue | yes |
npm install jstracetoix --save-dev
在此示例中:
d__ 将生成以下输出:
i0:`rice` | price:`10` | citytax:`5` | _:`15` i0:`coffee` | price:`30` | citytax:`15` | _:`45` i0:`shoes` | price:`100` | citytax:`15` | _:`115`
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) => c__(price, {name: 'price'}) > 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 => <tr key={product.id}> <td>{c__(product.title)}</td> <td>{d__(product.price + c__(citytax(product.price), { name: 'citytax' }))}</td> </tr> ); return ( <table><tbody>{listitems}</tbody></table> ); } function app() { return ( <div classname="app"> <header classname="app-header"> <shoppinglist /> </header> </div> ); } export default app;
在此示例中:
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) => price < 1000 ? 1.10 : 1; const prices = d__(products.map(product => c__(product.price, { allow: (index, name, value) => value > 40.00 ? Math.floor(value * factor(value)) : false, name: product.name.substring(0, 10) })), { allow: (data) => data._.map((v, i) => `${i}:${v}`), after: (data) => 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; }
environment | default output function |
---|---|
browser | console.debug |
node.js | process.stdout |
react | console.debug |
vue | console.debug |
除 node.js 环境外,输出显示在浏览器开发者工具的“控制台选项卡”下。
由于输出是使用 console.debug 生成的,因此可以轻松地从常规 console.log 消息中过滤掉它。
可以使用 init__({'stream': new_stream.log })
d__ 函数回调允许,before 和 after 将接收一个参数数据,其中包含允许的输入以及以下元项:
软件包文档
以上就是JsTraceToIX - 调试 React、Vue 和 Nodejs 变得更容易! – 无需用“consolelog”弄乱您的代码库!的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号