https://github.com/unjs/confbox
Compact and high quality YAML, TOML, JSONC and JSON5 parsers
https://github.com/unjs/confbox
Last synced: 10 months ago
JSON representation
Compact and high quality YAML, TOML, JSONC and JSON5 parsers
- Host: GitHub
- URL: https://github.com/unjs/confbox
- Owner: unjs
- License: other
- Created: 2024-02-20T13:40:57.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-26T06:43:28.000Z (over 1 year ago)
- Last Synced: 2024-11-26T07:29:16.295Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 340 KB
- Stars: 229
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-e18e - confbox - Zero-dependency parsing and serialization for YAML, TOML, JSONC, JSON5, INI, and JSON. (Utilities / Configuration)
README
# confbox
[](https://npmjs.com/package/confbox)
[](https://npm.chart.dev/confbox)
[](https://bundlephobia.com/package/confbox)
[](https://packagephobia.com/result?p=confbox)
Parsing and serialization utils for [YAML](https://yaml.org/) ([js-yaml](https://github.com/nodeca/js-yaml)), [TOML](https://toml.io/) ([smol-toml](https://github.com/squirrelchat/smol-toml)), [JSONC](https://github.com/microsoft/node-jsonc-parser) ([jsonc-parser](https://github.com/microsoft/node-jsonc-parser)), [JSON5](https://json5.org/) ([json5](https://github.com/json5/json5)), [INI](https://en.wikipedia.org/wiki/INI_file) ([ini](https://www.npmjs.com/package/ini)) and [JSON](https://www.json.org/json-en.html).
✨ Zero dependency and tree-shakable
✨ Types exported out of the box
✨ Preserves code style (indentation and whitespace)
> [!TIP]
> Use [unjs/c12](https://github.com/unjs/c12) for a full featured configuration loader!
## Usage
Install package:
```sh
# ✨ 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)
```js
import {
parseJSON5,
stringifyJSON5,
parseJSONC,
stringifyJSONC,
parseYAML,
stringifyYAML,
parseJSON,
stringifyJSON,
parseTOML,
stringifyTOML,
parseINI,
stringifyINI,
} from "confbox";
```
**CDN** (Deno, Bun and Browsers)
```js
import {
parseJSON5,
stringifyJSON5,
parseJSONC,
stringifyJSONC,
parseYAML,
stringifyYAML,
parseJSON,
stringifyJSON,
parseTOML,
stringifyTOML,
parseINI,
stringifyINI,
} from "https://esm.sh/confbox";
```
### `parseINI(text, options?)`
Converts an [INI](https://www.ini.org/ini-en.html) string into an object.
**Note:** Style and indentation are not preserved currently.
### `parseJSON(text, options?)`
Converts a [JSON](https://www.json.org/json-en.html) string into an object.
Indentation status is auto-detected and preserved when stringifying back using `stringifyJSON`
### `parseJSON5(text, options?)`
Converts a [JSON5](https://json5.org/) string into an object.
### `parseJSONC(text, options?)`
Converts a [JSONC](https://github.com/microsoft/node-jsonc-parser) string into an object.
### `parseTOML(text)`
Converts a [TOML](https://toml.io/) string into an object.
### `parseYAML(text, options?)`
Converts a [YAML](https://yaml.org/) string into an object.
### `stringifyINI(value, options?)`
Converts a JavaScript value to an [INI](https://www.ini.org/ini-en.html) string.
**Note:** Style and indentation are not preserved currently.
### `stringifyJSON(value, options?)`
Converts a JavaScript value to a [JSON](https://www.json.org/json-en.html) string.
Indentation status is auto detected and preserved when using value from parseJSON.
### `stringifyJSON5(value, options?)`
Converts a JavaScript value to a [JSON5](https://json5.org/) string.
### `stringifyJSONC(value, options?)`
Converts a JavaScript value to a [JSONC](https://github.com/microsoft/node-jsonc-parser) string.
### `stringifyTOML(value)`
Converts a JavaScript value to a [TOML](https://toml.io/) string.
### `stringifyYAML(value, options?)`
Converts a JavaScript value to a [YAML](https://yaml.org/) string.
## Contribution
Local development
- Clone this repository
- Install the latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run tests using `pnpm dev` or `pnpm test`
## License
Published under the [MIT](https://github.com/unjs/confbox/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/confbox/graphs/contributors) 💛
---
_🤖 auto updated with [automd](https://automd.unjs.io)_