npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

zod-to-from

v1.0.1

Published

A collection of to/from adapters that convert between I/O formats and Zod-validated objects

Downloads

19

Readme

Zod-to-From (ZTF) v1.0.1

A comprehensive format conversion library with Zod schema validation

ZTF is a powerful, extensible library that provides seamless conversion between various data formats while ensuring type safety through Zod schema validation. Whether you're working with JSON, YAML, CSV, or specialized formats like GPX, KML, or Office documents, ZTF has you covered.

🆕 What's New in v1.0.1

  • New from/to API - Clean, intuitive function naming with Zod schema validation
  • 47 Format Adapters - Comprehensive format support
  • 94 Export Functions - Direct access to all adapters with schema validation
  • Improved Type Safety - Better JSDoc documentation and runtime validation
  • Enhanced Testing - Comprehensive test coverage with schema validation

🚀 Features

  • 47 Format Adapters - Support for JSON, YAML, CSV, XML, Office documents, geospatial data, and more
  • Zod Schema Validation - Type-safe data conversion with runtime validation
  • New from/to API - Clean, intuitive function naming with schema validation
  • AI-Powered Adapters - Intelligent parsing for complex documents using Ollama
  • Streaming Support - Handle large datasets efficiently
  • Provenance Tracking - Audit trail for all conversions
  • Extensible Architecture - Easy to add custom adapters
  • Zero Dependencies - Core library has no external dependencies
  • JSDoc Documentation - Comprehensive type information

📦 Installation

# Using pnpm (recommended)
pnpm add zod-to-from

# Using npm
npm install zod-to-from

# Using yarn
yarn add zod-to-from

🎯 Quick Start

New from/to API (v1.0.1)

import {
  fromJson,
  toJson,
  fromCsv,
  toCsv,
  fromYaml,
  toYaml,
} from 'zod-to-from';
import { z } from 'zod';

// Define your schema
const UserSchema = z.object({
  name: z.string(),
  age: z.number(),
  email: z.string().email(),
});

// Parse JSON to structured data with schema validation
const jsonData = '{"name": "Alice", "age": 30, "email": "[email protected]"}';
const user = await fromJson(UserSchema, jsonData);
console.log(user); // { name: "Alice", age: 30, email: "[email protected]" }

// Format structured data to JSON with schema validation
const jsonOutput = await toJson(UserSchema, {
  name: 'Bob',
  age: 25,
  email: '[email protected]',
});
console.log(jsonOutput);
// {
//   "name": "Bob",
//   "age": 25,
//   "email": "[email protected]"
// }

// Parse CSV to structured data with schema validation
const csvData = 'name,age,email\nCharlie,35,[email protected]';
const csvResult = await fromCsv(UserSchema, csvData);
console.log(csvResult.items); // [{ name: "Charlie", age: 35, email: "[email protected]" }]

// Format structured data to CSV with schema validation
const csvOutput = await toCsv(UserSchema, {
  items: [
    { name: 'David', age: 40, email: '[email protected]' },
  ],
});
console.log(csvOutput);
// name,age,email
// David,40,[email protected]

Legacy API (still supported)

import { parseFrom, formatTo, convert } from 'zod-to-from';
import { z } from 'zod';

// Define your schema
const UserSchema = z.object({
  name: z.string(),
  age: z.number(),
  email: z.string().email(),
});

// Parse JSON data
const jsonData = '{"name": "Alice", "age": 30, "email": "[email protected]"}';
const user = await parseFrom(UserSchema, 'json', jsonData);
console.log(user); // { name: "Alice", age: 30, email: "[email protected]" }

// Format to YAML
const yamlOutput = await formatTo(UserSchema, 'yaml', user);
console.log(yamlOutput);
// name: Alice
// age: 30
// email: [email protected]

📚 Documentation

🔌 Available Adapters

Core Data Formats

  • JSON - JavaScript Object Notation
  • YAML - YAML Ain't Markup Language
  • TOML - Tom's Obvious, Minimal Language
  • CSV - Comma-Separated Values
  • NDJSON - Newline Delimited JSON

Office & Documents

  • DOCX - Microsoft Word documents (with AI assistance)
  • PPTX - PowerPoint presentations
  • XLSX - Excel spreadsheets
  • PDF - PDF text extraction and table support
  • HTML - HyperText Markup Language
  • Markdown - Markdown formatting

Geospatial

  • GPX - GPS Exchange Format
  • KML - Keyhole Markup Language
  • TopoJSON - Topological JSON
  • WKT - Well-Known Text geometries

Communications

  • cURL - HTTP request commands
  • EML - Email messages
  • ICS - Calendar events
  • vCard - Contact information
  • MessagePack - Binary serialization

DevOps & Config

  • Docker Compose - Container orchestration
  • Dockerfile - Container definitions
  • Kubernetes - K8s manifests
  • Terraform HCL - Infrastructure as code
  • Environment Variables - .env files
  • INI - Configuration files

Graph & Knowledge

  • JSON-LD - Linked Data
  • Turtle - RDF serialization
  • N-Quads - RDF quads
  • PlantUML - Diagram definitions

Media & Archives

  • EXIF - Image metadata
  • ID3 - Audio metadata
  • TAR - Archive format
  • ZIP - Compressed archives

Templating

  • Nunjucks - Template engine
  • Frontmatter - Document metadata

🧠 AI-Powered Adapters

ZTF includes AI-powered adapters that use Ollama for intelligent document parsing:

import { parseFrom } from 'zod-to-from';
import { z } from 'zod';

const DocumentSchema = z.object({
  title: z.string(),
  summary: z.string(),
  keyPoints: z.array(z.string()),
});

// AI-assisted DOCX parsing
const docxBuffer = fs.readFileSync('document.docx');
const parsed = await parseFrom(DocumentSchema, 'docx-ai', docxBuffer, {
  adapter: {
    model: 'qwen3-coder',
    prompt: 'Extract the main points from this document',
  },
});

🔄 Streaming Support

Handle large datasets efficiently with streaming:

import { parseFrom } from 'zod-to-from';

const result = await parseFrom(Schema, 'csv', largeCsvData, {
  streaming: true,
});

📊 Provenance Tracking

Track the history of your data transformations:

const result = await parseFrom(Schema, 'json', data, {
  includeProvenance: true,
});

console.log(result.provenance);
// {
//   timestamp: "2024-01-01T12:00:00.000Z",
//   adapter: "json",
//   version: "0.1.0",
//   schemaHash: "abc123..."
// }

🛠️ Advanced Usage

Custom Adapters

import { registerAdapter } from 'zod-to-from';

registerAdapter('custom', {
  async parse(input, opts = {}) {
    // Your parsing logic
    return { data: parsedData, metadata: {} };
  },
  async format(data, opts = {}) {
    // Your formatting logic
    return { data: formattedString, metadata: {} };
  },
  supportsStreaming: false,
  isAI: false,
  version: '1.0.0',
});

Error Handling

import { parseFrom } from 'zod-to-from';
import { z } from 'zod';

try {
  const result = await parseFrom(Schema, 'json', invalidData);
} catch (error) {
  if (error.name === 'ZodError') {
    console.log('Schema validation failed:', error.issues);
  } else {
    console.log('Parsing failed:', error.message);
  }
}

🧪 Testing

# Run all tests
pnpm test

# Run specific test suites
pnpm test:unit
pnpm test:adapters
pnpm test:e2e

# Run with coverage
pnpm test:coverage

📈 Performance

ZTF is designed for performance:

  • Zero Dependencies - Core library has no external dependencies
  • Lazy Loading - Adapters are loaded only when needed
  • Streaming Support - Handle large datasets without memory issues
  • Efficient Parsing - Optimized for common use cases

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/seanchatmangpt/zod-to-from.git
cd zod-to-from

# Install dependencies
pnpm install

# Run development server
pnpm dev

# Run tests
pnpm test

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • Zod for schema validation
  • Ollama for AI capabilities
  • All the open-source libraries that power our adapters

📞 Support


Made with ❤️ by the ZTF Team