{"id":46989,"library":"ascertain","title":"Ascertain","description":"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.","status":"active","version":"3.2.44","language":"javascript","source_language":"en","source_url":"https://github.com/3axap4eHko/ascertain","tags":["javascript","js","schema","validation","js-validation","validator","js-validator","assert","typescript"],"install":[{"cmd":"npm install ascertain","lang":"bash","label":"npm"},{"cmd":"yarn add ascertain","lang":"bash","label":"yarn"},{"cmd":"pnpm add ascertain","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require() works but is discouraged. TypeScript types included.","wrong":"const { compile } = require('ascertain')","symbol":"compile","correct":"import { compile } from 'ascertain'"},{"note":"Default export for convenience wrapper that compiles and throws on failure.","wrong":"import { ascertain } from 'ascertain'","symbol":"ascertain","correct":"import ascertain from 'ascertain'"},{"note":"Named export from the package root.","wrong":"import optional from 'ascertain'","symbol":"optional","correct":"import { optional } from 'ascertain'"}],"quickstart":{"code":"import { compile, discriminated, optional, or } from 'ascertain';\n\nconst schema = {\n  id: Number,\n  role: or('admin', 'user', 'guest'),\n  score: optional(Number),\n  notifications: [\n    discriminated(\n      [\n        { type: 'email', address: String },\n        { type: 'sms', phone: String },\n        { type: 'push', token: String },\n      ],\n      'type',\n    ),\n  ],\n};\n\nconst validateUser = compile(schema);\n\nconst userData = {\n  id: 1,\n  role: 'admin',\n  notifications: [{ type: 'email', address: 'test@example.com' }],\n};\n\nif (!validateUser(userData)) {\n  console.error(validateUser.issues);\n} else {\n  console.log('Valid!');\n}","lang":"typescript","description":"Demonstrates compiled validation with discriminated unions, optional fields, and union literals."},"warnings":[{"fix":"Check validateUser.issues for errors instead of catching thrown exceptions.","message":"In version 3.x, compile() returns a validator object with an issues property instead of throwing directly.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use compile() for reusable validators; ascertain() for one-off throws.","message":"The ascertain() convenience function is deprecated in favor of compile() for repeated use.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure all discriminated variants include the discriminator field as a string literal.","message":"When using discriminated(), the discriminator field must be present in every variant and must be a string key.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'3.2.44':21 'ajv':32 'all-error':39,58 'array':49 'ascertain':1 'assert':94 'compil':9,51 'constructor':47 'current':17 'depend':4,69 'differenti':29 'dramat':34 'error':41,56,60 'fast':14 'faster':30,35 'first':55 'first-error':54 'form':82 'full':62 'function':16 'infer':67 'interoper':77 'javascript':5,44,83 'javascript-n':43 'js':11,84,88,92 'js-valid':87,91 'key':28 'liter':48 'mode':61 'month':27 'multipl':24 'nativ':10,45 'object':50 'per':26 'regular':23 'releas':22 'schema':6,46,74,85 'stabl':18 'standard':73 'support':64,71 'tanstack':81 'trpc':79 'type':66 'typescript':63,95 'v1':75 'valid':7,15,42,52,86,89,90,93 'valu':12 'version':19,25 'zero':3,68 'zero-depend':2 'zod':37","created_at":"2026-06-07T16:49:11.363883+00:00","updated_at":"2026-06-07T16:49:11.363883+00:00","problems":[{"fix":"Run 'npm install ascertain' and use import syntax; ensure Node.js version >=12 or use bundler.","cause":"Package not installed or running in environment without ESM support.","error":"Error: Cannot find module 'ascertain'"},{"fix":"Change to 'import { compile } from 'ascertain'.","cause":"Default import used for named export; import { compile } from 'ascertain' required.","error":"TypeError: compile is not a function"},{"fix":"Update to ascertain@3 and access validateUser.issues for error details.","cause":"Using compile() in version 2.x where return was boolean; version 3.x returns object with issues.","error":"TypeError: validateUser.issues is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/3axap4eHko/ascertain#readme","github":"https://github.com/3axap4eHko/ascertain","docs":null,"changelog":null,"pypi":null,"npm":"ascertain","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}