What is pretty-data?
The pretty-data npm package is a utility for formatting and minifying JSON, XML, and CSS data. It helps in making data more readable or compact, depending on the need.
What are pretty-data's main functionalities?
JSON Pretty Print
This feature formats JSON data to be more readable by adding indentation and line breaks.
const pd = require('pretty-data').pd;
const json = '{"name":"John","age":30,"city":"New York"}';
console.log(pd.json(json));
JSON Minify
This feature minifies JSON data by removing unnecessary whitespace, making it more compact.
const pd = require('pretty-data').pd;
const json = '{"name":"John","age":30,"city":"New York"}';
console.log(pd.jsonmin(json));
XML Pretty Print
This feature formats XML data to be more readable by adding indentation and line breaks.
const pd = require('pretty-data').pd;
const xml = '<root><name>John</name><age>30</age><city>New York</city></root>';
console.log(pd.xml(xml));
XML Minify
This feature minifies XML data by removing unnecessary whitespace, making it more compact.
const pd = require('pretty-data').pd;
const xml = '<root><name>John</name><age>30</age><city>New York</city></root>';
console.log(pd.xmlmin(xml));
CSS Pretty Print
This feature formats CSS data to be more readable by adding indentation and line breaks.
const pd = require('pretty-data').pd;
const css = 'body{margin:0;padding:0;}h1{color:red;}';
console.log(pd.css(css));
CSS Minify
This feature minifies CSS data by removing unnecessary whitespace, making it more compact.
const pd = require('pretty-data').pd;
const css = 'body{margin:0;padding:0;}h1{color:red;}';
console.log(pd.cssmin(css));
Other packages similar to pretty-data
js-beautify
js-beautify is a popular package for beautifying JavaScript, JSON, CSS, and HTML. It offers more customization options compared to pretty-data and supports a wider range of languages.
prettier
Prettier is an opinionated code formatter that supports many languages including JavaScript, JSON, CSS, and HTML. It is widely used in the development community for its ease of integration with various editors and build tools.
xml-formatter
xml-formatter is a specialized package for formatting XML data. It provides more advanced options for handling XML namespaces and attributes compared to pretty-data.
jsonminify
jsonminify is a package specifically designed for minifying JSON data. It is lightweight and focuses solely on JSON minification, making it faster for this specific task compared to pretty-data.
pretty-data - Nodejs plugin
nodejs plugin to pretty-print or minify
text in XML, JSON, CSS and SQL formats.
Version - 0.30.3
Copyright (c) 2012 Vadim Kiryukhin ( vkiryukhin @ gmail.com )
Home page: http://www.eslinstructor.net/pretty-data/
License: Dual licensed under
the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
##Description
-
pd.xml(data )
- pretty print XML;
-
pd.json(data)
- pretty print JSON;
-
pd.css(data )
- pretty print CSS;
-
pd.sql(data )
- pretty print SQL;
-
pd.xmlmin(data [, preserveComments])
- minify XML;
-
pd.jsonmin(data)
- minify JSON text;
-
pd.cssmin(data [, preserveComments] )
- minify CSS text;
-
pd.sqlmin(data)
- minify JSON text;
PARAMETERS:
@data
- String; XML, JSON, CSS or SQL text to beautify;
@preserveComments
- Bool (optional, used in npp.minxml and npp.mincss only);
Set this flag to true to prevent removing comments from @data;
@Return
- String;
USAGE:
var pd = require('pretty-data').pd;
var xml_pp = pd.xml(data);
var xml_min = pd.xmlmin(data [,true]);
var json_pp = pd.json(data);
var json_min = pd.jsonmin(data);
var css_pp = pd.css(data);
var css_min = pd.cssmin(data [, true]);
var sql_pp = pd.sql(data);
var sql_min = pd.sqlmin(data);