Registry / testing / pretty-data

pretty-data

JSON →
library0.40.0jsnpmunverified

A library for pretty-printing and minifying XML, JSON, CSS, and SQL strings. Version 0.40.0 is the latest stable release; no active development since 2016. Lightweight with zero dependencies, it provides simple functions for formatting and minifying common data formats. Unlike formatters specific to one format (e.g., js-beautify for JS/HTML/CSS), pretty-data handles multiple formats in a single package, but lacks tree-shaking and is not modular. ESM is not supported; only CommonJS.

npm install pretty-data
INSTALL
IMPORT
SIG · PRETTY-DATA
P
pretty-data
testingjavascriptv0.40.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

prettyData (default import)
✓ const pd = require('pretty-data');
✗ import pd from 'pretty-data';
Require-style only; library does not support ESM imports.
pd.xml
✓ pd.xml.prettyPrint(xmlStr); pd.xml.min(xmlStr);
XML functions are under pd.xml namespace.
pd.json
✓ pd.json.prettyPrint(jsonStr); pd.json.min(jsonStr);
✗ JSON.parse then JSON.stringify with spacing; that's not minification.
Input must be a JSON string, not an object.
pd.css
✓ pd.css.prettyPrint(cssStr); pd.css.min(cssStr);
✗ Using pd.css.min on non-string input.
Both functions expect string input.
pd.sql
✓ pd.sql.prettyPrint(sqlStr); pd.sql.min(sqlStr);
SQL support is basic; may not handle all dialects.

Demonstrates pretty-printing and minifying XML, JSON, CSS, and SQL using the library's CommonJS interface.

const pd = require('pretty-data'); const xml = '<root><child>data</child></root>'; console.log(pd.xml.prettyPrint(xml)); // Output: // <root> // <child>data</child> // </root> const json = '{"name":"test","value":123}'; console.log(pd.json.prettyPrint(json)); // Output: // { // "name": "test", // "value": 123 // } console.log(pd.json.min(json)); // Output: {"name":"test","value":123} const css = 'body { color: red; font-size: 12px; }'; console.log(pd.css.prettyPrint(css)); // Output: // body { // color: red; // font-size: 12px; // } const sql = 'SELECT * FROM users WHERE id = 1'; console.log(pd.sql.prettyPrint(sql)); // Output: // SELECT * FROM users // WHERE id = 1
Debug
Known issues
gotchaAll functions expect a string input; passing an object will cause errors.
fix
Ensure to convert objects to JSON strings using JSON.stringify before passing to pd.json functions.
affects: *
gotchaLibrary does not support ES module imports; using import will fail.
fix
Use require('pretty-data') instead of import.
affects: *
deprecatedThe library has not been updated since 2016. No bug fixes or new features are expected.
fix
Consider migrating to more actively maintained libraries like js-beautify for CSS/JSON or sql-formatter for SQL.
affects: >=0.40.0
gotchaJSON prettyPrint does not sort keys; output order is based on input.
fix
If key sorting is needed, sort keys manually before pretty-printing.
affects: *
gotchaSQL formatting is very basic; complex queries may not be formatted correctly.
fix
Use a dedicated SQL formatter like sql-formatter for complex queries.
affects: *
Errors
Common errors & fixes
TypeError: pd.json.prettyPrint is not a function
Attempting to use pd.json.prettyPrint directly if pd is the result of a property access without the default import.
fix
Ensure const pd = require('pretty-data'); then use pd.json.prettyPrint.
SyntaxError: Unexpected token o in JSON at position 1
Passing a JavaScript object to pd.json.prettyPrint instead of a JSON string.
fix
Convert object to string: pd.json.prettyPrint(JSON.stringify(obj)).
Unexpected token u in JSON at position 0
Passing undefined or null to pd.json functions.
fix
Check that the input is a valid string before calling prettyPrint or min.
Cannot find module 'pretty-data'
The package is not installed or import path is incorrect.
fix
Run npm install pretty-data, then use require('pretty-data').
ReferenceError: pd is not defined
Forgetting to require the library before using pd.
fix
Add const pd = require('pretty-data'); at the top of the file.
Upgrade
Version history
0.40.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pretty-data — npm install pretty-data · libregistry