Package detail

confbox

unjs33.6mMIT0.2.2

Compact YAML, TOML, JSONC, JSON5 and INI parser and serializer

yaml, toml, jsonc, json5

readme

confbox

npm version npm downloads bundle size install size

Parsing and serialization utils for YAML (js-yaml), TOML (smol-toml), JSONC (jsonc-parser), JSON5 (json5), INI (ini) and JSON.

✨ Zero dependency and tree-shakable

✨ Types exported out of the box

✨ Preserves code style (indentation and whitespace)

[!TIP] Use unjs/c12 for a full featured configuration loader!

Usage

Install package:

# ✨ Auto-detect
npx nypm install confbox

# npm
npm install confbox

# yarn
yarn add confbox

# pnpm
pnpm install confbox

# bun
bun install confbox

# deno
deno install confbox

Import:

ESM (Node.js, Bun, Deno)

import {
  parseJSON5,
  stringifyJSON5,
  parseJSONC,
  stringifyJSONC,
  parseYAML,
  stringifyYAML,
  parseJSON,
  stringifyJSON,
  parseTOML,
  stringifyTOML,
  parseINI,
  stringifyINI,
} from "confbox";

CDN (Deno, Bun and Browsers)

import {
  parseJSON5,
  stringifyJSON5,
  parseJSONC,
  stringifyJSONC,
  parseYAML,
  stringifyYAML,
  parseJSON,
  stringifyJSON,
  parseTOML,
  stringifyTOML,
  parseINI,
  stringifyINI,
} from "https://esm.sh/confbox";

parseINI(text, options?)

Converts an INI string into an object.

Note: Style and indentation are not preserved currently.

parseJSON(text, options?)

Converts a JSON string into an object.

Indentation status is auto-detected and preserved when stringifying back using stringifyJSON

parseJSON5(text, options?)

Converts a JSON5 string into an object.

parseJSONC(text, options?)

Converts a JSONC string into an object.

parseTOML(text)

Converts a TOML string into an object.

parseYAML(text, options?)

Converts a YAML string into an object.

stringifyINI(value, options?)

Converts a JavaScript value to an INI string.

Note: Style and indentation are not preserved currently.

stringifyJSON(value, options?)

Converts a JavaScript value to a JSON string.

Indentation status is auto detected and preserved when using value from parseJSON.

stringifyJSON5(value, options?)

Converts a JavaScript value to a JSON5 string.

stringifyJSONC(value, options?)

Converts a JavaScript value to a JSONC string.

stringifyTOML(value)

Converts a JavaScript value to a TOML string.

stringifyYAML(value, options?)

Converts a JavaScript value to a YAML string.

Contribution

<summary>Local development</summary> - Clone this repository - Install the latest LTS version of Node.js - Enable Corepack using corepack enable - Install dependencies using pnpm install - Run tests using pnpm dev or pnpm test

License

Published under the MIT license. Made by @pi0 and community 💛


🤖 auto updated with automd

changelog

Changelog

v0.2.2

compare changes

🚀 Enhancements

  • json: Default indentation to 2 (#56)

📦 Build

  • Use default condition to allow require(esm) (0083def)

🏡 Chore

❤️ Contributors

v0.2.1

compare changes

📦 Build

  • Use default condition to allow require(esm) (0083def)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.2.0

compare changes

🚀 Enhancements

  • Ini support (#50)

📦 Build

🏡 Chore

✅ Tests

⚠️ Breaking Changes

❤️ Contributors

v0.1.8

compare changes

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.7

compare changes

🚀 Enhancements

  • Json utilities with format and whitespace preservation (#7)
  • Preserve style for all utils (d4665b4)

🩹 Fixes

  • Fix stringifyTOML types (40e1ca4)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.6

compare changes

🩹 Fixes

  • Fix stringifyTOML types (40e1ca4)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.5

compare changes

🩹 Fixes

🏡 Chore

  • Apply automated updates (1475b7f)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.4

compare changes

🚀 Enhancements

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.3

compare changes

v0.1.2

compare changes

🚀 Enhancements

  • Switch to smol-toml for toml parsing (#2)

🏡 Chore

❤️ Contributors

  • Uncenter
  • Pooya Parsa (@pi0)

v0.1.1

💅 Refactors

🏡 Chore

✅ Tests

  • Add test with full coverage (7bc81b8)

❤️ Contributors

  • Pooya Parsa (@pi0)