🔄 ymlify
Convert JSON, XML, CSV, TOML, and ENV files to YAML format with ease.
🚀 Installation
Global Installation
npm install -g ymlify
Local Installation
npm install ymlify
📖 Usage
CLI Usage
After global installation:
ymlify openapi.json
ymlify config.xml config.yml
ymlify data.csv
ymlify settings.toml
ymlify .env environment.yml
With npx (no installation required):
npx ymlify openapi.json
Programmatic Usage
import { ymlify, ymlifyString } from "ymlify";
ymlify("config.json", "config.yml");
const yamlString = ymlifyString('{"name": "value"}', "json");
console.log(yamlString);
ymlify("data.json", "data.yml", {
indent: 4,
lineWidth: 80,
noRefs: true,
});
🎯 Supported Formats
- JSON (.json) - JavaScript Object Notation
- XML (.xml) - Extensible Markup Language
- CSV (.csv) - Comma-Separated Values
- TOML (.toml) - Tom's Obvious, Minimal Language
- ENV (.env) - Environment Variables
🔧 API
ymlify(inputPath, outputPath?, options?)
Converts a file to YAML format.
inputPath (string): Path to the input file
outputPath (string, optional): Path to the output YAML file. Defaults to input filename with .yml extension
options (object, optional):
indent (number): Number of spaces for indentation (default: 2)
lineWidth (number): Maximum line width (default: -1, unlimited)
noRefs (boolean): Don't use anchors/references (default: true)
detectFormat (boolean): Auto-detect file format (default: true)
Returns: The output file path
ymlifyString(input, format, options?)
Converts a string to YAML format.
input (string): Content to convert
format (string): Format type ('json', 'xml', 'csv', 'toml', 'env')
options (object, optional): Same as above
Returns: YAML string
💡 Examples
Convert OpenAPI JSON to YAML
ymlify openapi.json openapi.yml
Convert XML configuration
ymlify config.xml
Convert CSV data
ymlify users.csv users.yml
Convert TOML settings
ymlify Cargo.toml
Convert ENV file
ymlify .env config.yml
Programmatic usage with TypeScript
import { ymlify, ymlifyString } from "ymlify";
const output = ymlify("./data.json");
console.log(`Created: ${output}`);
const jsonStr = '{"server": {"port": 3000, "host": "localhost"}}';
const yaml = ymlifyString(jsonStr, "json");
console.log(yaml);
const xmlStr = "<config><port>3000</port></config>";
const yamlFromXml = ymlifyString(xmlStr, "xml");
console.log(yamlFromXml);
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT
🐛 Issues
Found a bug? Please report it at the issues page.