Registry / testing / ascertain

ascertain

JSON →
library3.2.44jsnpmunverified

Zero-dependency JavaScript schema validator that compiles native JS values into fast validator functions. Current stable version is 3.2.44. Released regularly (multiple versions per month). Key differentiators: faster than AJV and dramatically faster than Zod for all-errors validation, JavaScript-native schemas (constructors, literals, arrays, objects), compiled validators with first-error and all-errors modes, full TypeScript support with type inference, zero dependencies, and support for Standard Schema v1 for interoperability with tRPC and TanStack Form.

npm install ascertain
INSTALL
IMPORT
SIG · ASCERTAIN
A
ascertain
testingjavascriptv3.2.44
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'ascertain'
const { compile } = require('ascertain')
ESM-only; CommonJS require() works but is discouraged. TypeScript types included.
ascertain
import ascertain from 'ascertain'
import { ascertain } from 'ascertain'
Default export for convenience wrapper that compiles and throws on failure.
optional
import { optional } from 'ascertain'
import optional from 'ascertain'
Named export from the package root.

Demonstrates compiled validation with discriminated unions, optional fields, and union literals.

import { compile, discriminated, optional, or } from 'ascertain'; const schema = { id: Number, role: or('admin', 'user', 'guest'), score: optional(Number), notifications: [ discriminated( [ { type: 'email', address: String }, { type: 'sms', phone: String }, { type: 'push', token: String }, ], 'type', ), ], }; const validateUser = compile(schema); const userData = { id: 1, role: 'admin', notifications: [{ type: 'email', address: 'test@example.com' }], }; if (!validateUser(userData)) { console.error(validateUser.issues); } else { console.log('Valid!'); }
Debug
Known issues
breakingIn version 3.x, compile() returns a validator object with an issues property instead of throwing directly.
fix
Check validateUser.issues for errors instead of catching thrown exceptions.
affects: >=3.0.0
deprecatedThe ascertain() convenience function is deprecated in favor of compile() for repeated use.
fix
Use compile() for reusable validators; ascertain() for one-off throws.
affects: >=2.0.0
gotchaWhen using discriminated(), the discriminator field must be present in every variant and must be a string key.
fix
Ensure all discriminated variants include the discriminator field as a string literal.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'ascertain'
Package not installed or running in environment without ESM support.
fix
Run 'npm install ascertain' and use import syntax; ensure Node.js version >=12 or use bundler.
TypeError: compile is not a function
Default import used for named export; import { compile } from 'ascertain' required.
fix
Change to 'import { compile } from 'ascertain'.
TypeError: validateUser.issues is undefined
Using compile() in version 2.x where return was boolean; version 3.x returns object with issues.
fix
Update to ascertain@3 and access validateUser.issues for error details.
Upgrade
Version history
3.2.44latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
ascertain — npm install ascertain · libregistry