Skip to content

FieldTestValidation toolkit for content

Framework-agnostic validation for Markdown and Standard Schema — built for Astro, Next.js, and modern frameworks.

FieldTest - Framework-agnostic validation toolkit

Quick Example

typescript
import { loadUserSchema, validateWithSchema } from '@watthem/fieldtest';
import type { StandardSchemaV1 } from '@watthem/fieldtest';

// Define your schema
const blogSchema: StandardSchemaV1 = {
  version: '1',
  name: 'blog-post',
  fields: {
    title: { type: 'string', required: true },
    author: { type: 'string', required: true },
    published: { type: 'boolean', required: true },
    tags: { type: 'string', array: true }
  }
};

// Validate your content
const schema = loadUserSchema(blogSchema);
const markdown = `---
title: "Getting Started with FieldTest"
author: "Jane Developer"
published: true
tags: ["typescript", "validation", "markdown"]
---

# Getting Started

This post shows how easy it is to validate content with FieldTest!
`;

const result = validateWithSchema(markdown, schema);

if (result.valid) {
  console.log('✓ Content validated successfully!');
} else {
  result.errors.forEach(error => {
    console.error(`❌ ${error.field}: ${error.message}`);
  });
}

Framework Integration

Astro

typescript
// src/content/config.ts
import { defineCollection } from 'astro:content';
import { loadUserSchema } from '@watthem/fieldtest';

const blog = defineCollection({
  type: 'content',
  schema: (z) => z.object({
    title: z.string(),
    author: z.string()
  }).refine(data => {
    const result = validateWithSchema(
      generateMarkdown(data), 
      loadUserSchema(blogSchema)
    );
    return result.valid;
  })
});

Next.js

typescript
// Validate in generateStaticParams or getStaticProps
export async function generateStaticParams() {
  const schema = loadUserSchema(blogSchema);
  const posts = fs.readdirSync('./content');
  
  return posts.map(post => {
    const content = fs.readFileSync(`./content/${post}`, 'utf-8');
    const result = validateWithSchema(content, schema);
    
    if (!result.valid) {
      throw new Error(`Invalid post: ${result.errors.map(e => e.message)}`);
    }
    
    return { slug: post.replace('.md', '') };
  });
}

Other Frameworks

typescript
// Universal validation that works anywhere
import { validateWithSchema } from '@watthem/fieldtest';

const isValid = validateWithSchema(content, schema).valid;

Why Choose FieldTest?

🎯 Built for Modern Frameworks

Stop wrestling with framework-specific validation. FieldTest works the same way across Astro, Next.js, Remix, SvelteKit, and more.

📚 Standard Schema Foundation

Based on the emerging Standard Schema specification, ensuring your validation logic is future-proof and interoperable.

Performance Optimized

Designed to handle large content sites. Validates thousands of documents in seconds with minimal memory usage.

🔧 Developer Experience

Comprehensive TypeScript support, clear error messages, extensive documentation, and helpful tooling integrations.

Ready to Get Started?

🚀 Quick Start

Get up and running in less than 5 minutes with our comprehensive getting started guide.

Get Started →

📖 Learn by Example

Explore real-world examples and patterns for different frameworks and use cases.

Browse Examples →

🔍 API Reference

Comprehensive documentation of all functions, types, and configuration options.

View API →

Released under the MIT License.