Elysia Tools

Browse tools, examples, visual explainers, and topic guides from one clear workspace.

Top Categories

Hubs

Language
ZHESPTRUFRDEEN

Elysia Tools

Navigation

Validation Libraries

Zod 4.1.8 offline validation examples

Strict object boundaries; Defaults are not coercion; Cross-field order.

Samples

Entries inside this sample collection

CodejavascriptSimple

Strict object boundaries

Run card1.cjs: positive integer id, nonempty label, no extra keys.

Tags

offline, synthetic, verified-input

javascript
// Node.js CommonJS, tested with zod 4.1.8. No I/O beyond console.
const { z } = require('zod');
const Item = z.strictObject({ id: z.number().int().positive(), label: z.string().min(1) });
const cases = [{id:1,label:'Demo'}, {id:0,label:'Demo'}, {id:1,label:''}, {id:1,label:'Demo',extra:true}];
const results = cases.map(x => Item.safeParse(x).success);
if (JSON.stringify(results) !== '[true,false,false,false]') throw Error('Unexpected validation');
console.log(results);
CodejavascriptSimple

Defaults are not coercion

Run card2.cjs with undefined, string 25 and null.

Tags

offline, synthetic, verified-input

javascript
const { z } = require('zod');
// Default handles undefined, not null. No implicit string-number coercion.
const Limit = z.number().int().min(1).max(100).default(10);
const missing = Limit.parse(undefined);
const text = Limit.safeParse('25').success;
const nullValue = Limit.safeParse(null).success;
if (missing !== 10 || text || nullValue) throw Error('Unexpected default behavior');
console.log({missing, text, nullValue});
CodejavascriptIntermediate

Cross-field order

Run card3.cjs for spans 2→5, 2→2 and 5→2.

Tags

offline, synthetic, verified-input

javascript
const { z } = require('zod');
const Span = z.object({start:z.number(),end:z.number()}).refine(x => x.end >= x.start, {message:'end must not precede start',path:['end']});
const good = Span.safeParse({start:2,end:5});
const equal = Span.safeParse({start:2,end:2});
const bad = Span.safeParse({start:5,end:2});
if (!good.success || !equal.success || bad.success || bad.error.issues[0].path[0] !== 'end') throw Error('Unexpected span result');
console.log({forward:good.success,equal:equal.success,backward:bad.success,path:bad.error.issues[0].path});

Tools

Tools frequently paired with this sample

Related

Related sample collections

Related

Related workflows

Tool usage guide

Sample-focused context for search and workflow understanding

Overview

Three executable CommonJS examples use the installed Zod 4.1.8 package and fictional data. They require no browser, API or database.

Read one source section at a time

Strict object boundaries; Defaults are not coercion; Cross-field order.

How it works

  1. 1Open the named card and read or copy its source into a local editor. Locate each section named below; the page shows code, not a running demonstration.

Edge cases & common failures

  • Scope of the examples

    All three actual examples ran against Zod 4.1.8 locally. Other versions, async refinements and application integration were not tested. Copy each card to a separate .cjs file in an environment where that package is installed.

Examples

1. Strict object boundaries

How to use

Strict object boundaries — Run card1.cjs: positive integer id, nonempty label, no extra keys.

Outcome

The valid object passes; zero id, empty label and extra key fail. Results are true,false,false,false.

2. Defaults are not coercion

How to use

Defaults are not coercion — Run card2.cjs with undefined, string 25 and null.

Outcome

undefined yields default 10. The string and null fail; .default does not turn them into numbers.

3. Cross-field order

How to use

Cross-field order — Run card3.cjs for spans 2→5, 2→2 and 5→2.

Outcome

Forward/equal pass, backward fails with issue path end. The refinement preserves an actionable field location.

Hub

Define an ISO 8601 Reporting Period and Fiscal Week

Turn a dated reporting anchor and a stated duration into an auditable calendar endpoint, ISO week label and fiscal-quarter assignment.

Hub

Cron Expression Validation and Schedule Simulation

Generate or convert cron expressions, validate semantics, visualize upcoming runs, and test them against an explicit trigger window.

Hub

Contact and Shipping Identifier Validation

Normalize and validate email, phone, postal, and tracking identifiers before import or dispatch.

Hub

Date and Time Normalization and Deadline Calculation

Turn ambiguous or mixed-format date inputs into validated, timezone-aware, business-ready timestamps, deadlines, and duration facts.

Home
Tools3216
Samples593
Visualizations473
Viewers103
Hubs239
Tags333
Images, Audio & Video657

Image, audio, and video processing, conversion, and optimization tools

Math, Date & Finance647

Calculators, numerics, date logic, statistics, and finance tools

Design & Color298

Color, layout, graphics, visual styling, and design helper tools

Text & Writing209

Writing, cleanup, formatting, extraction, and text analysis tools

Developer & Web194

Developer utilities, networking, web debugging, and automation helpers

Conversion & Encoding175

Format, file, archive, unit, and encoding conversion tools

Lead Generation Quiz Launch and Contact Handoff
Memorial Drafts: Family Review and Print Handoff
Private Habit Records: Backup, Restore and Sharing Review
Article to X and LinkedIn Drafts: Fact Review and Handoff
Markdown Interactive Deck Review and Offline Handoff

© 2026 Elysia Tools. All rights reserved.

DocsPricingAboutTerms of ServicePrivacy PolicyCookiesContact

Development

JSON Schema to Zod Schema Converter

Convert JSON Schema JSON/YAML definitions into ready-to-use Zod schemas with nested objects, arrays, enums, and common validation rules

AI Tools

MCP Server Contract Tester — stdio + WebSocket Transports, JSON Schema 2020-12 Tool Validation

End-to-end Model Context Protocol contract testing: JSON-RPC 2.0 initialize handshake and version negotiation over stdio (newline-delimited) and WebSocket (one message per text frame), tools/list inputSchema object-root and draft 2020-12 compilation, resources/list + read, prompts/list + get, ping, -32601 error semantics, sampling/createMessage round-trip, and framing discipline — with an embedded reference server for offline self-verification.

Health

Private offline period tracker

No account, AI or record uploads. The independent app has no ads or analytics.

Security

TOTP / HOTP Offline Code Generator

Generate RFC 6238 TOTP (time-based, 6/8 digits, 30/60s step) and RFC 4226 HOTP (counter-based) one-time passwords from a base32 shared secret, fully offline with HMAC-SHA1/256/512, plus an otpauth:// URI for importing into Google Authenticator / Authy

Format Conversion

XLSX Data Validation Dropdown

Batch-create dropdowns, dependent cascading dropdowns, and input prompts in Excel workbooks using data validation rules

Validation

JSON Schema Validator

Validate JSON data against a JSON Schema to verify structure and data types

Validation

Accessibility Checker

Detect common WCAG 2.1 accessibility issues in HTML, fetched pages, or design images and return fix-ready guidance

Development

API Doc Generator

Generate polished API documentation from OpenAPI or annotated comments

File System

Path Analyzer Samples

Comprehensive collection of file system paths from Windows, Linux, and macOS for path analysis and testing

Validation

Regex Pattern Alternatives

Multiple ways to write the same regex pattern with different trade-offs in readability, performance, and accuracy

Database

MySQL Database Samples

Sample MySQL database scripts with various complexity levels from simple tables to enterprise ERP systems

Testing

BDD with Cucumber - Behavior Driven Development

Comprehensive Cucumber BDD examples including feature files, step definitions, data tables, hooks, and advanced BDD patterns for collaborative development

Observability

Distributed Tracing Samples

Comprehensive distributed tracing examples using Jaeger, OpenTelemetry, and other modern observability tools for microservices architecture

DevOps

ELK Stack Log Analysis Samples

Comprehensive ELK Stack (Elasticsearch, Logstash, Kibana) samples for log aggregation, processing, and visualization in distributed systems