{"id":49523,"library":"tiny-schema-validator","title":"Tiny Schema Validator","description":"JSON schema validator with excellent type inference for JavaScript and TypeScript. Current stable version is 5.0.3. It provides a declarative API using an underscore (_) namespace for defining schemas with built-in validators like string, number, boolean, union, record, list, etc. Differentiators include automatic TypeScript type inference via the produce method, detailed error objects that mirror the schema shape, and a lightweight bundle (minzipped size shown in badge). The library is actively maintained, supports Node.js >=10, and is ESM and CJS compatible.","status":"active","version":"5.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/5alidz/tiny-schema-validator","tags":["javascript","typescript"],"install":[{"cmd":"npm install tiny-schema-validator","lang":"bash","label":"npm"},{"cmd":"yarn add tiny-schema-validator","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiny-schema-validator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is recommended; CommonJS require also works for Node.js environments.","wrong":"const { createSchema } = require('tiny-schema-validator')","symbol":"createSchema","correct":"import { createSchema } from 'tiny-schema-validator'"},{"note":"The underscore must be a named import, not default. Aliasing is optional but recommended for clarity.","wrong":"import _ from 'tiny-schema-validator'","symbol":"_","correct":"import { _ as validators } from 'tiny-schema-validator'"},{"note":"Type inference is obtained via ReturnType on the produce method, not a separate type utility.","wrong":"import { createSchema } from 'tiny-schema-validator'; export type UserType = InferType<typeof User>","symbol":"ReturnType","correct":"import { createSchema, _ } from 'tiny-schema-validator'; export type UserType = ReturnType<typeof User.produce>"}],"quickstart":{"code":"import { createSchema, _ } from 'tiny-schema-validator';\n\nconst Person = createSchema({\n  name: _.string(),\n  age: _.number(),\n  email: _.string()\n});\n\nconst data = { name: 'Alice', age: 30, email: 'alice@example.com' };\nconsole.log(Person.is(data)); // true\nconsole.log(Person.validate(data)); // null\ntry {\n  Person.produce(data);\n  console.log('valid');\n} catch (e) {\n  console.error(e.message);\n}","lang":"typescript","description":"Creates a Person schema, then demonstrates is(), validate(), and produce() methods."},"warnings":[{"fix":"For optional fields, define a separate schema and embed it: const OptionalName = createSchema({ name: _.string() }).embed({ optional: true }).","message":"All validators are required by default. To make a field optional, use the embed() method with { optional: true }.","severity":"gotcha","affected_versions":"*"},{"fix":"Update code to check the return value of validate() instead of using try/catch.","message":"In version 5.0.0, the `validate` method changed from throwing on invalid data to returning an errors object or null.","severity":"breaking","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Use `_.list([_.string(), _.number()])` for a tuple [string, number].","message":"The `_.listof` validator returns an array type, not a tuple. For fixed-length tuples, use `_.list([...])`.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `_.record` or `_.list` for object/array constants.","message":"The `_.constant` validator requires a primitive value. Passing objects or arrays will not produce the expected type inference.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'10':79 '5.0.3':19 'activ':75 'api':24 'automat':47 'badg':71 'boolean':40 'built':34 'built-in':33 'bundl':66 'cjs':84 'compat':85 'current':15 'declar':23 'defin':30 'detail':55 'differenti':45 'error':56 'esm':82 'etc':44 'excel':8 'includ':46 'infer':10,50 'javascript':12,86 'json':4 'librari':73 'lightweight':65 'like':37 'list':43 'maintain':76 'method':54 'minzip':67 'mirror':59 'namespac':28 'node.js':78 'number':39 'object':57 'produc':53 'provid':21 'record':42 'schema':2,5,31,61 'shape':62 'shown':69 'size':68 'stabl':16 'string':38 'support':77 'tini':1 'type':9,49 'typescript':14,48,87 'underscor':27 'union':41 'use':25 'valid':3,6,36 'version':17 'via':51","created_at":"2026-06-07T17:02:12.463525+00:00","updated_at":"2026-06-07T17:02:12.463525+00:00","problems":[{"fix":"Change import to: import { createSchema } from 'tiny-schema-validator'","cause":"Importing createSchema as default export instead of named export.","error":"TypeError: createSchema is not a function"},{"fix":"Change import to: import { _ } from 'tiny-schema-validator'","cause":"Importing _ as default export instead of named export.","error":"TypeError: _.string is not a function"},{"fix":"Use: type PersonType = ReturnType<typeof Person.produce>","cause":"Attempting to use the schema directly as a type without extracting the inferred type.","error":"TypeScript error: 'Person' refers to a value, but is being used as a type here."}],"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/5alidz/tiny-schema-validator#readme","github":"https://github.com/5alidz/tiny-schema-validator","docs":null,"changelog":null,"pypi":null,"npm":"tiny-schema-validator","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}}