ymlify
v1.0.0
Published
Convert JSON, XML, CSV, TOML, and ENV files to YAML format
Maintainers
Readme
🔄 ymlify
Convert JSON, XML, CSV, TOML, and ENV files to YAML format with ease.
🚀 Installation
Global Installation
npm install -g ymlifyLocal 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.ymlWith npx (no installation required):
npx ymlify openapi.jsonProgrammatic Usage
import { ymlify, ymlifyString } from "ymlify";
// Convert file
ymlify("config.json", "config.yml");
// Convert string
const yamlString = ymlifyString('{"name": "value"}', "json");
console.log(yamlString);
// With options
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 fileoutputPath(string, optional): Path to the output YAML file. Defaults to input filename with.ymlextensionoptions(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 convertformat(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.ymlConvert XML configuration
ymlify config.xmlConvert CSV data
ymlify users.csv users.ymlConvert TOML settings
ymlify Cargo.tomlConvert ENV file
ymlify .env config.ymlProgrammatic usage with TypeScript
import { ymlify, ymlifyString } from "ymlify";
// Convert a JSON file
const output = ymlify("./data.json");
console.log(`Created: ${output}`);
// Convert JSON string
const jsonStr = '{"server": {"port": 3000, "host": "localhost"}}';
const yaml = ymlifyString(jsonStr, "json");
console.log(yaml);
// Convert XML string
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.
