Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
pretty-var-export
Advanced tools
Changelog
v1.1.7 - 31 Aug 2022
Readme
Export any value to valid and equivalent JavaScript code. Uses syntax coloring for debugging from the cli.
npm install pretty-var-export
const pretty = require('pretty-var-export');
// return string suitable for logging
console.log(pretty(myValue));
// OR prettify and log
pretty.log(myValue);
// OR import and log in one line
require('pretty-var-export').log(myValue);
Note that coloring can be disabled with pretty.colors.disable()
.
Add custom handlers for formatting.
For example, show NaN as a different color than numbers:
const pretty = require('pretty-var-export');
// each handler must have a test and format method
pretty.handlers.add('nan', {
test: isNaN,
format: () => pretty.colors.palette.cyan('NaN'),
});
// reset to default list
pretty.handlers.reset();
You can remove handlers by name.
const pretty = require('pretty-var-export');
// see below for list of names
pretty.handlers.remove('nan');
// reset to default list
pretty.handlers.reset();
Default handler names:
By default, indentation is 2 spaces.
const pretty = require('pretty-var-export');
pretty.options.indent = 4; // 4 spaces
pretty.options.indent = ' '; // 4 spaces
pretty.options.indent = '\t'; // tab
Colors come from the ansi-colors npm module.
Formats include the following:
boolean
for true and false (default yellow)comment
for comments (default gray)constructor
for instantiation (default blue)escape
for string escapes (default yellowBright)null
for null (default yellow)number
for numbers, NaN, Infinity (default red)property
for object property names (default cyan)regexp
for bodies of regular expressions (default blue)string
for strings (default green)symbol
for quotes, braces, parens, commas, colons (default white)undefined
for undefined (default yellow)const pretty = require('pretty-var-export');
// existing color functions from the ansi-colors npm package
pretty.colors.symbol = pretty.colors.palette.blueBright;
// use any other function
pretty.colors.string = chalk.green;
// disable all coloring
pretty.colors.disable();
// reset to default colors and re-enable coloring
pretty.colors.reset();
There are a few options that can change display. Below are defaults.
const pretty = require('pretty-var-export');
// if true, show function bodies
pretty.options.showFunctionBody = false;
// the max length for strings
pretty.options.maxStringLength = 1024 * 4;
// max number of items to list
pretty.options.maxListItems = 100;
// output multi-line strings with backticks
pretty.options.preferBackticks = true;
// quote style for default strings (single, double or backtick)
pretty.options.quoteStyle = 'double';
// reset to defaults
pretty.options.reset();
Labels can be changed or translated.
const pretty = require('pretty-var-export');
// defaults
pretty.labels.circularReference = 'Circular Reference';
pretty.labels.codeOmitted = 'Code Omitted';
pretty.labels.itemsUnknown = 'Items Unknown';
// reset to defaults
pretty.labels.reset();
See CHANGELOG.md
Please open a ticket or PR on GitHub.
FAQs
Export any value to valid and equivalent JavaScript code
The npm package pretty-var-export receives a total of 904 weekly downloads. As such, pretty-var-export popularity was classified as not popular.
We found that pretty-var-export 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.