
Security News
Node.js Moves Toward Stable TypeScript Support with Amaro 1.0
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
babel-plugin-console
Advanced tools
🎮
Adds useful build time console functions
Ever find yourself using console.log
to work out what the heck is going on within your functions?
And then put too many variables into the log and lose context of which value is which variable?
These problems can be solved by a computer at build time. This plugin allows you to inspect a functions parameters, variables, return value and parent scope by adding meaningful logs around the scope of the function - removing the hassle of manual console.log
statements or debugging.
With npm:
npm install --save-dev babel-plugin-console
With yarn:
yarn add -D babel-plugin-console
{
"plugins": ["console"]
}
babel --plugins console script.js
require('babel-core').transform('code', {
plugins: ['console'],
})
console.scope()
Outputs a collection of messages for a functions entire scope
Note: this API is the same as the standard console.log
console.scope(obj1 [, obj2, ..., objN]);
console.scope(msg [, subst1, ..., substN]);
obj1 ... objN
A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.
msg
A JavaScript string containing zero or more substitution strings.
subst1 ... substN
JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
const add100 = (a) => {
const oneHundred = 100;
console.scope('Add 100 to another number');
return add(a, oneHundred);
};
const add = (a, b) => {
return a + b;
};
↓ ↓ ↓ ↓ ↓ ↓
Browser:
Node:
babel-plugin-console
also ships with babel-macros supported 🎉
To use a macro you will need to
install and setup babel-macros
.
Once you have enabled babel-macros
import/require the scope
macro with:
import scope from 'babel-plugin-console/scope.macro';
// OR
const scope = require('babel-plugin-console/scope.macro');
Note: this is the same as the above usage and will generate the same logs - only difference is it uses the scope macro 😎
↑ ↑ ↑ ↑ ↑ ↑
import scope from 'babel-plugin-console/scope.macro';
const add100 = (a) => {
const oneHundred = 100;
scope('Add 100 to another number');
return add(a, oneHundred);
};
const add = (a, b) => {
return a + b;
};
This tweet led to me watching
@kentcdodds's live presentation on ASTs. This plugin is an extension on the
captains-log
demoed - Thanks Kent!
You could use a debugger with breakpoints to pause the execution of a function and inspect the values of each variable.
The above add100
function would look like the following if you used a debugger with a breakpoint:
Matt Phillips 💻 📖 🚇 ⚠️ | Stephen Bluck 📖 |
---|
MIT
FAQs
Babel plugin with additional console helper functions
The npm package babel-plugin-console receives a total of 376 weekly downloads. As such, babel-plugin-console popularity was classified as not popular.
We found that babel-plugin-console demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.