arv-validate

中文文档
1.1.4发布于 2026/11/03MITTypeScriptES Module零依赖

High-performance, reactive, and atomic form validation and sanitization engine (Vanilla JS, Vue 3, React, Node.js, zero dependencies)

原始使用文档
文档目录8 节
  1. Installation
  2. Quick Start
  3. Key Features
  4. Internationalization (i18n)
  5. Available Adapters
  6. API Reference
  7. Documentation
  8. License

arv-validate

Ultra-fast, zero-dependency, atomic, reactive form validation and data sanitization engine for JavaScript and TypeScript.

npm version license Zero Dependencies TypeScript

English | Español

arv-validate is 100% framework-agnostic. It runs in Vanilla JS, Vue 3, React, Angular, Svelte, Node.js, Bun, browsers, or Web Workers.


Installation

npm install arv-validate

Quick Start

import { createValidator, required, email, minLength, trim } from 'arv-validate'

const validator = createValidator(
  {
    name: '',
    email: ''
  },
  {
    name: [required(), minLength(3), trim()],
    email: [required(), email(), trim()]
  }
)

// 1. Live mutations automatically revalidate in real-time
validator.values.name = 'John Doe'
validator.values.email = '[email protected]'

// 2. Validate all fields (e.g. before submitting)
const isValid = await validator.validate()

// 3. Inspect errors
console.log(validator.state.errors)

// 4. Get sanitized, typed payload ready for API request
const payload = validator.getPayload()
console.log(payload) // { name: "John Doe", email: "[email protected]" }

Key Features

  • ⚡ Real-Time Live Validation: Deep recursive ES6 Proxy tracks mutations instantly and recalculates only affected fields.
  • 🌐 Built-in i18n: English by default, Spanish built-in (setLocale('es')), and custom dictionary support via configureMessages().
  • 🔌 100% Framework Agnostic: Zero DOM dependencies. Use anywhere in JavaScript or TypeScript.
  • 🧩 40+ Built-in Rules: required, email, minLength, maxLength, between, date, afterDate, sameAs, when, custom, and more.
  • 🔄 Async Validation & Race-Condition Safe: Handles promises with built-in stale token invalidation (e.g. username availability check).
  • 🧹 Transformers & Sanitization: trim(), toLowerCase(), toFloat(), round(), digitsOnly(), toDate() without altering UI input values.
  • 🌳 Nested Objects & Arrays: Full dot-notation support ('user.address.zipCode') and dynamic arrays (each()).
  • 📦 Zero Dependencies: Pure modern JavaScript (~6 kB gzipped).

Internationalization (i18n)

Switch between languages or provide custom messages:

import { setLocale, configureMessages } from 'arv-validate'

// Switch to Spanish
setLocale('es')

// Switch back to English (default)
setLocale('en')

// Override individual messages globally
configureMessages({
  required: 'Field is required',
  email: 'Must be a valid email address'
})

Available Adapters

FrameworkPackageInstallation
Vanilla JS / Node.jsarv-validatenpm i arv-validate
Vue 3arv-validate-vuenpm i arv-validate-vue
React@arv-validate/react(Coming soon)
Angular@arv-validate/angular(Coming soon)

API Reference

createValidator(initialData, schema, options) returns:

  • v.values: Reactive live-editing proxy (supports nested dot-notation).
  • v.state: Flat state snapshot { values, errors, touched, validating, isValid, isDirty }.
  • v.validate(): Marks all fields as touched, executes synchronous and asynchronous rules, returns Promise<boolean>.
  • v.validateField(field): Validates a single field immediately.
  • v.touch(field): Marks field as touched (@blur).
  • v.untouch(field): Unmarks field as touched.
  • v.hasError(field): Returns true if field is touched and has an error.
  • v.getError(field): Returns error message or null.
  • v.isValidating(field?): Returns true if an async rule is in-flight.
  • v.getPayload(customFn?): Returns sanitized and transformed object for API calls.
  • v.reset(newValues?): Resets state to clean initial values or updates with new data.
  • v.setValues(patch): Updates multiple fields simultaneously.
  • v.subscribe(callback): Registers a state change listener, returns unsubscribe function.

Documentation


License

MIT © jccallo

版本与发布记录

arv-validate 共发布 7 个版本,首次发布于 2026/10/24;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.1.4latest2026/11/03今天
1.1.32026/10/259 天前
1.1.22026/10/2410 天前
1.1.12026/10/2410 天前
1.1.02026/10/2410 天前
1.0.02026/10/2410 天前

关于 arv-validate 的常见问题

arv-validate 是什么?

高性能、反应式、原子式表单验证和清理引擎(Vanilla JS、Vue 3、React、Node.js,零依赖)

如何安装 arv-validate?

在项目目录运行 npm install arv-validate,或使用 pnpm add / yarn add / bun add。

arv-validate 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

arv-validate 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

arv-validate 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

arv-validate 可以商用吗?

arv-validate 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

arv-validate 还在维护吗?

最新版本 1.1.4 发布于 2026/11/03(今天);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/10/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。