Registry / devops / sweet-data

sweet-data

JSON →
library0.1.4jsnpmunverified

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.

npm install sweet-data
INSTALL
IMPORT
SIG · SWEET-DATA
S
sweet-data
devopsjavascriptv0.1.4
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.

SweetData
import { SweetData as sd } from 'sweet-data'
const SweetData = require('sweet-data')
SweetData is a named export, not default. Use destructuring or alias.
sd (CommonJS)
const sd = require('sweet-data')
import sd from 'sweet-data'
In CommonJS, require returns the exported object directly.
xml
sd.xml(data)
xml(data)
Methods are called on the imported sd object.

Demonstrates ESM and CJS imports, promise-based format/minify, setStep configuration, and error handling for JSON, XML, CSS.

// ESM import { SweetData as sd } from 'sweet-data'; const json = { "name": "test", "value": 42 }; sd.json(json) .then(beautified => console.log(beautified)) .catch(err => console.error(err)); const xml = '<root><child>text</child></root>'; sd.xml(xml) .then(prettyXml => console.log(prettyXml)) .catch(err => console.error(err)); // CommonJS const sd = require('sweet-data'); sd.setStep(4, ' '); const css = 'a{color:red}'; sd.css(css) .then(beautifiedCss => console.log(beautifiedCss)) .catch(err => console.error(err)); // Minify sd.jsonmin(json) .then(minified => console.log(minified)) .catch(err => console.error(err));
Debug
Known issues
breakingUnder active development: breaking changes expected in minor versions before 1.0.0.
fix
Pin exact version and test upgrades thoroughly.
affects: <1.0.0
gotchaAll format/minify functions return Promises, not synchronous results. Attempting to use them synchronously will return a Promise object.
fix
Use .then()/async-await to handle results.
affects: >=0.0.0
gotchaImporting as default (import sd from 'sweet-data') yields undefined because SweetData is a named export.
fix
Use named import: import { SweetData as sd } from 'sweet-data' or const sd = require('sweet-data').
affects: >=0.0.0
deprecatedForked from pretty-data; original API may differ. Not all original options preserved.
fix
Review sweet-data docs; do not assume compatibility with pretty-data.
affects: >=0.0.0
gotchaxmlmin and cssmin accept optional preserveComments boolean, but default is to strip comments. Not specifying may lose data.
fix
Pass true as second argument to preserve comments: sd.xmlmin(xml, true).
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: sd.json is not a function
Incorrect import; imported object does not have expected methods.
fix
Ensure correct import: import { SweetData as sd } from 'sweet-data' (ESM) or const sd = require('sweet-data') (CJS).
Cannot read properties of undefined (reading 'then')
Function returned undefined instead of Promise because of misconfiguration or unsupported input type.
fix
Verify input is a string (or object for json/jsonmin). For CSS/XML/SQL, input must be string.
SyntaxError: Unexpected token < in JSON at position 0
Passing XML to sd.json() or invalid JSON to sd.xml().
fix
Use appropriate function for the data format: sd.xml() for XML, sd.json() for JSON.
import { SweetData } from 'sweet-data'; const sd = require('sweet-data');
Mixing ESM and CJS import styles in same file.
fix
Use either ESM (import) or CJS (require) consistently.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Resources
sweet-data — npm install sweet-data · libregistry