uniconverter
v1.0.0
Published
Uniconverter is a modern, modular, and framework-agnostic universal data converter. It supports parsing and formatting between 5 major text-based data formats: - **CSV** (Comma-Separated Values) - **TSV** (Tab-Separated Values) - **JSON** (JavaScript Obje
Maintainers
Readme
Uniconverter
Uniconverter is a modern, modular, and framework-agnostic universal data converter. It supports parsing and formatting between 5 major text-based data formats:
- CSV (Comma-Separated Values)
- TSV (Tab-Separated Values)
- JSON (JavaScript Object Notation)
- XML (eXtensible Markup Language)
- YAML (YAML Ain't Markup Language)
With a focus on the DRY (Don't Repeat Yourself) principle, it is designed as a Monorepo containing 20 individual dual-directional parsing packages centered around a fast JSON-Hub.
Features
- Agnostic & Universal: Runs flawlessly on the Browser, Node.js, Deno, and Edge environments. No Node-specific dependencies (like
fsorpath) are enforced in the parsing logic. - Modular (NPM Workspaces): You can install the entire library, or just the specific converter you need.
- Fully Typed: 100% written in TypeScript.
- Fast: Leverages lightweight dependencies like
fast-xml-parserandyamlwhere native parsing isn't enough.
Usage
1. Using the Fluent API (Unified Converter)
If you install the root uniconverter package, you get access to the advanced, framework-agnostic Converter class which supports files, URLs, and chained conversions. Node-specific libraries (fs) are imported dynamically only when you call .fromFile() or .toFile(), making this class perfectly safe for Web Browsers and React/Vue!
npm install uniconverterimport { Converter } from 'uniconverter';
// From URL to File (e.g. JSON API to XML File)
await Converter.fromUrl('https://jsonplaceholder.typicode.com/users/1', 'json')
.toType('xml')
.toFile('./output.xml');
// From File to Memory (e.g. YAML File to TSV String)
const tsvString = await Converter.fromFile('./data.yaml', 'yaml')
.toType('tsv')
.toString();
// Chained Conversions from raw string
const yamlString = Converter.fromString("id,name\n1,Alice", "csv")
.toType("tsv")
.toType("yaml")
.toString();
// Or to a native JSON Array/Object
const dataObject = Converter.fromString("user:\n name: Alice", "yaml")
.toType("json")
.toJson();2. Using Modular Packages (Recommended for Web)
To keep your bundle sizes small, you can install only the exact converter pair you need:
npm install @uniconverter/yaml-to-csvimport { yamlToCsv } from '@uniconverter/yaml-to-csv';
const csvData = yamlToCsv("- name: Alice\n age: 25\n- name: Bob\n age: 30");
console.log(csvData);Available Packages
CSV Converters
@uniconverter/csv-to-json
import { csvToJson } from '@uniconverter/csv-to-json';
const data = csvToJson("id,name\n1,Alice");
// Output: [ { id: '1', name: 'Alice' } ]@uniconverter/csv-to-tsv
import { csvToTsv } from '@uniconverter/csv-to-tsv';
const data = csvToTsv("id,name\n1,Alice");
// Output: "id\tname\n1\tAlice"@uniconverter/csv-to-xml
import { csvToXml } from '@uniconverter/csv-to-xml';
const data = csvToXml("id,name\n1,Alice");
// Output: "<0><id>1</id><name>Alice</name></0>"@uniconverter/csv-to-yaml
import { csvToYaml } from '@uniconverter/csv-to-yaml';
const data = csvToYaml("id,name\n1,Alice");
// Output: "- id: '1'\n name: Alice\n"JSON Converters
@uniconverter/json-to-csv
import { jsonToCsv } from '@uniconverter/json-to-csv';
const data = jsonToCsv([ { id: 1, name: 'Alice' } ]);
// Output: "id,name\n1,Alice"@uniconverter/json-to-tsv
import { jsonToTsv } from '@uniconverter/json-to-tsv';
const data = jsonToTsv([ { id: 1, name: 'Alice' } ]);
// Output: "id\tname\n1\tAlice"@uniconverter/json-to-xml
import { jsonToXml } from '@uniconverter/json-to-xml';
const data = jsonToXml({ user: { id: 1, name: 'Alice' } });
// Output: "<user><id>1</id><name>Alice</name></user>"@uniconverter/json-to-yaml
import { jsonToYaml } from '@uniconverter/json-to-yaml';
const data = jsonToYaml({ user: { id: 1, name: 'Alice' } });
// Output: "user:\n id: 1\n name: Alice\n"TSV Converters
@uniconverter/tsv-to-csv
import { tsvToCsv } from '@uniconverter/tsv-to-csv';
const data = tsvToCsv("id\tname\n1\tAlice");
// Output: "id,name\n1,Alice"@uniconverter/tsv-to-json
import { tsvToJson } from '@uniconverter/tsv-to-json';
const data = tsvToJson("id\tname\n1\tAlice");
// Output: [ { id: '1', name: 'Alice' } ]@uniconverter/tsv-to-xml
import { tsvToXml } from '@uniconverter/tsv-to-xml';
const data = tsvToXml("id\tname\n1\tAlice");
// Output: "<0><id>1</id><name>Alice</name></0>"@uniconverter/tsv-to-yaml
import { tsvToYaml } from '@uniconverter/tsv-to-yaml';
const data = tsvToYaml("id\tname\n1\tAlice");
// Output: "- id: '1'\n name: Alice\n"XML Converters
@uniconverter/xml-to-csv
import { xmlToCsv } from '@uniconverter/xml-to-csv';
const data = xmlToCsv("<root><item><id>1</id><name>Alice</name></item></root>");
// Output: "id,name\n1,Alice"@uniconverter/xml-to-json
import { xmlToJson } from '@uniconverter/xml-to-json';
const data = xmlToJson("<user><name>Alice</name></user>");
// Output: { user: { name: 'Alice' } }@uniconverter/xml-to-tsv
import { xmlToTsv } from '@uniconverter/xml-to-tsv';
const data = xmlToTsv("<root><item><id>1</id><name>Alice</name></item></root>");
// Output: "id\tname\n1\tAlice"@uniconverter/xml-to-yaml
import { xmlToYaml } from '@uniconverter/xml-to-yaml';
const data = xmlToYaml("<user><name>Alice</name></user>");
// Output: "user:\n name: Alice\n"YAML Converters
@uniconverter/yaml-to-csv
import { yamlToCsv } from '@uniconverter/yaml-to-csv';
const data = yamlToCsv("- id: 1\n name: Alice");
// Output: "id,name\n1,Alice"@uniconverter/yaml-to-json
import { yamlToJson } from '@uniconverter/yaml-to-json';
const data = yamlToJson("user:\n name: Alice");
// Output: { user: { name: 'Alice' } }@uniconverter/yaml-to-tsv
import { yamlToTsv } from '@uniconverter/yaml-to-tsv';
const data = yamlToTsv("- id: 1\n name: Alice");
// Output: "id\tname\n1\tAlice"@uniconverter/yaml-to-xml
import { yamlToXml } from '@uniconverter/yaml-to-xml';
const data = yamlToXml("user:\n name: Alice");
// Output: "<user><name>Alice</name></user>"License
MIT License. See LICENSE.md for more details.
