{"id":44017,"library":"sweet-data","title":"sweet-data","description":"A Node.js text formatting plugin for pretty-printing and minifying XML, JSON, CSS, and SQL. Version 0.1.4 is under active development with breaking changes expected. Forked from pretty-data, it offers synchronous and promise-based APIs, custom indentation via setStep(), and dual ESM/CJS support. Compared to alternatives like js-beautify, it covers SQL and XML natively and provides both beautify and minify functions in one package.","status":"active","version":"0.1.4","language":"javascript","source_language":"en","source_url":"https://github.com/bgerhards/sweet-data","tags":["javascript","pretty print","beautify","minify","XML","JSON","CSS","SQL","tabs"],"install":[{"cmd":"npm install sweet-data","lang":"bash","label":"npm"},{"cmd":"yarn add sweet-data","lang":"bash","label":"yarn"},{"cmd":"pnpm add sweet-data","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"SweetData is a named export, not default. Use destructuring or alias.","wrong":"const SweetData = require('sweet-data')","symbol":"SweetData","correct":"import { SweetData as sd } from 'sweet-data'"},{"note":"In CommonJS, require returns the exported object directly.","wrong":"import sd from 'sweet-data'","symbol":"sd (CommonJS)","correct":"const sd = require('sweet-data')"},{"note":"Methods are called on the imported sd object.","wrong":"xml(data)","symbol":"xml","correct":"sd.xml(data)"}],"quickstart":{"code":"// ESM\nimport { SweetData as sd } from 'sweet-data';\n\nconst json = { \"name\": \"test\", \"value\": 42 };\nsd.json(json)\n  .then(beautified => console.log(beautified))\n  .catch(err => console.error(err));\n\nconst xml = '<root><child>text</child></root>';\nsd.xml(xml)\n  .then(prettyXml => console.log(prettyXml))\n  .catch(err => console.error(err));\n\n// CommonJS\nconst sd = require('sweet-data');\nsd.setStep(4, ' ');\nconst css = 'a{color:red}';\nsd.css(css)\n  .then(beautifiedCss => console.log(beautifiedCss))\n  .catch(err => console.error(err));\n\n// Minify\nsd.jsonmin(json)\n  .then(minified => console.log(minified))\n  .catch(err => console.error(err));","lang":"typescript","description":"Demonstrates ESM and CJS imports, promise-based format/minify, setStep configuration, and error handling for JSON, XML, CSS."},"warnings":[{"fix":"Pin exact version and test upgrades thoroughly.","message":"Under active development: breaking changes expected in minor versions before 1.0.0.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use .then()/async-await to handle results.","message":"All format/minify functions return Promises, not synchronous results. Attempting to use them synchronously will return a Promise object.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use named import: import { SweetData as sd } from 'sweet-data' or const sd = require('sweet-data').","message":"Importing as default (import sd from 'sweet-data') yields undefined because SweetData is a named export.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Review sweet-data docs; do not assume compatibility with pretty-data.","message":"Forked from pretty-data; original API may differ. Not all original options preserved.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Pass true as second argument to preserve comments: sd.xmlmin(xml, true).","message":"xmlmin and cssmin accept optional preserveComments boolean, but default is to strip comments. Not specifying may lose data.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.1.4':21 'activ':24 'altern':53 'api':42 'base':41 'beautifi':57,67,77 'break':27 'chang':28 'compar':51 'cover':59 'css':17,81 'custom':43 'data':3,34 'develop':25 'dual':48 'esm/cjs':49 'expect':29 'fork':30 'format':7 'function':70 'indent':44 'javascript':74 'js':56 'js-beautifi':55 'json':16,80 'like':54 'minifi':14,69,78 'nativ':63 'node.js':5 'offer':36 'one':72 'packag':73 'plugin':8 'pretti':11,33,75 'pretty-data':32 'pretty-print':10 'print':12,76 'promis':40 'promise-bas':39 'provid':65 'setstep':46 'sql':19,60,82 'support':50 'sweet':2 'sweet-data':1 'synchron':37 'tab':83 'text':6 'version':20 'via':45 'xml':15,62,79","created_at":"2026-06-05T17:02:35.119568+00:00","updated_at":"2026-06-05T17:02:35.119568+00:00","problems":[{"fix":"Ensure correct import: import { SweetData as sd } from 'sweet-data' (ESM) or const sd = require('sweet-data') (CJS).","cause":"Incorrect import; imported object does not have expected methods.","error":"TypeError: sd.json is not a function"},{"fix":"Verify input is a string (or object for json/jsonmin). For CSS/XML/SQL, input must be string.","cause":"Function returned undefined instead of Promise because of misconfiguration or unsupported input type.","error":"Cannot read properties of undefined (reading 'then')"},{"fix":"Use appropriate function for the data format: sd.xml() for XML, sd.json() for JSON.","cause":"Passing XML to sd.json() or invalid JSON to sd.xml().","error":"SyntaxError: Unexpected token < in JSON at position 0"},{"fix":"Use either ESM (import) or CJS (require) consistently.","cause":"Mixing ESM and CJS import styles in same file.","error":"import { SweetData } from 'sweet-data'; const sd = require('sweet-data');"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://bgerhards.github.io/sweet-data/","github":"https://github.com/bgerhards/sweet-data","docs":null,"changelog":null,"pypi":null,"npm":"sweet-data","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}