@kitmodule/kittoon
v1.0.2
Published
Convert JavaScript objects into TOON format quickly — lightweight, human-readable, and dependency-free.
Maintainers
Readme
📝 KitTOON by Kitmodule
Convert JavaScript objects into TOON format quickly — lightweight, human-readable, and dependency-free.
✨ Features
- 📦 Convert JavaScript objects into TOON format: human-readable, lightweight.
- 🔢 Automatic uniform array:
[N]{field1,field2,...}:in inline or block style. - ⚡ Optional flatten / fold keys: flatten nested objects, concatenate keys, or remove
.. - 💨 Supports array inline
[a,b,c]or block- a\n- b. - 💎 Vanilla JS, no dependencies.
- 🔧 Quick helper to convert objects into TOON in a single line:
convertTOON(obj).
🚀 Installation
npm
npm install @kitmodule/kittoonCDN
<script src="https://unpkg.com/@kitmodule/kittoon/dist/kittoon.min.js"></script>or
<script src="https://cdn.jsdelivr.net/npm/@kitmodule/kittoon/dist/kittoon.min.js"></script>🧪 Example
const data = {
project: "KitTOON Demo",
author: {
name: "Huỳnh Nhân Quốc",
location: "Tam Kỳ"
},
users: [
{ id: 1, name: "Quốc", age: 25 },
{ id: 2, name: "Nam", age: 30 }
],
tags: ["demo", "kitmodule", "TOON"]
};
// Quick conversion to TOON
console.log(convertTOON(data));Output:
project: KitTOON Demo
author:
name: Huỳnh Nhân Quốc
location: Tam Kỳ
users[2]{id,name,age}:
1,Quốc,25
2,Nam,30
tags: [demo,kitmodule,TOON]💡 Usage
Browser (CDN)
<script src="https://unpkg.com/@kitmodule/kittoon/dist/kittoon.min.js"></script>
<script>
const obj = {
users: [
{ id: 1, name: "Quốc", role: "admin" },
{ id: 2, name: "Nam", role: "user" }
]
};
// Quick helper
console.log(convertTOON(obj));
// Or custom instance
const toon = new KitTOON(obj)
.inline() // enable inline uniform array
.flatten('user') // flatten object with prefix 'user'
.fold(true); // fold keys (remove dots)
console.log(toon.convert());
</script>Node.js / CommonJS
const { KitTOON, convertTOON } = require('@kitmodule/kittoon');
const obj = {
users: [
{ id: 1, name: "Quốc", role: "admin" },
{ id: 2, name: "Nam", role: "user" }
]
};
// Convert object to TOON
const toon = new KitTOON(obj)
.inline() // inline uniform array
.flatten(true) // flatten object
.fold(true); // fold keys
console.log(toon.convert());
// Or use the quick helper
console.log(convertTOON(obj));🧩 API Reference
new KitTOON(obj)
| Parameter | Type | Description | | --------- | ------ | ---------------------------------- | | obj | object | Plain JavaScript object to convert |
Instance Methods
| Method | Description |
| --------------------------- | ------------------------------------------------------------------ |
| .inline(enable = true) | Use inline array [1,2,3] or uniform object inline |
| .block(enable = true) | Use block array - 1\n- 2 |
| .convert() | Convert the object into TOON string |
| .fold(prefixOrBoolean) | Fold keys (remove dots) or use a custom prefix |
| .flatten(prefixOrBoolean) | Flatten nested object to single-level keys, optionally with prefix |
| .delimiter(char) | Change the delimiter for uniform arrays (default: ,) |
Global Helpers
| Function | Description |
| ---------------------------- | ------------------------------------------------------ |
| convertTOON(obj) | Quick conversion to TOON format |
| toonFrontMatter(obj, body) | Convert object to TOON front matter with optional body |
✅ Why KitTOON?
- Quickly convert object → TOON for configuration, front matter, test data.
- Human-readable, lightweight, easy to integrate.
- Provides quick helper and instance customization.
☕ Support the Author
🧾 License
Released under MIT License © 2025 Huỳnh Nhân Quốc · Open Source @Kit Module
