confbox
v0.1.8
Published
Compact and high quality YAML, TOML, JSONC and JSON5 parsers
Downloads
20,369,821
Readme
confbox
Parsing and serialization utils for YAML (js-yaml), TOML (smol-toml), JSONC (jsonc-parser), JSON5 (json5), and JSON.
✨ Zero dependency and tree-shakable
✨ Types exported out of the box
✨ Presrves 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,
} from "confbox";
CommonJS (Legacy Node.js)
const {
parseJSON5,
stringifyJSON5,
parseJSONC,
stringifyJSONC,
parseYAML,
stringifyYAML,
parseJSON,
stringifyJSON,
parseTOML,
stringifyTOML,
} = require("confbox");
CDN (Deno, Bun and Browsers)
import {
parseJSON5,
stringifyJSON5,
parseJSONC,
stringifyJSONC,
parseYAML,
stringifyYAML,
parseJSON,
stringifyJSON,
parseTOML,
stringifyTOML,
} from "https://esm.sh/confbox";
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.
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
- 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
orpnpm test
License
Published under the MIT license. Made by @pi0 and community 💛
🤖 auto updated with automd