{"id":49634,"library":"value-schema","title":"value-schema","description":"value-schema is a declarative input validator for Node.js, TypeScript, Deno, and Bun. Version 4.0.0 (stable) provides schema-based validation with automatic type coercion, default values, trimming, and checksum support (e.g., Luhn). It simplifies the common web app pattern of existence check, type check, and domain check into a single, readable schema definition. Unlike JSON Schema or Joi, it offers built-in email, date, IPv4/IPv6, and credit card validators with compact syntax. It ships TypeScript types and supports ESM and CJS.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/shimataro/value-schema","tags":["javascript","param","params","parameter","parameters","validate","validator","ajust","adjuster","typescript"],"install":[{"cmd":"npm install value-schema","lang":"bash","label":"npm"},{"cmd":"yarn add value-schema","lang":"bash","label":"yarn"},{"cmd":"pnpm add value-schema","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default ESM import. For CJS, use `const { default: vs } = require('value-schema');` or dynamic import.","wrong":"const vs = require('value-schema')","symbol":"vs","correct":"import vs from 'value-schema'"},{"note":"Named export for type usage. The default export is a factory object.","wrong":"import Schema from 'value-schema'","symbol":"Schema","correct":"import { Schema } from 'value-schema'"},{"note":"TypeScript users can import individual schema types for type annotations.","wrong":"import vsNum from 'value-schema'","symbol":"VsNumber, VsString, etc.","correct":"import { VsNumber, VsString } from 'value-schema'"}],"quickstart":{"code":"import vs from 'value-schema';\n\nconst schemaObject = {\n  id: vs.number({ minValue: 1 }),\n  name: vs.string({ maxLength: { length: 16, trims: true } }),\n  age: vs.number({ integer: vs.NUMBER.INTEGER.FLOOR_RZ, minValue: 0 }),\n  email: vs.email(),\n  state: vs.string({ only: ['active', 'inactive'] }),\n  classes: vs.array({ separatedBy: ',', each: { schema: vs.number(), ignoresErrors: true } }),\n  creditCard: vs.numericString({ separatedBy: '-', checksum: vs.NUMERIC_STRING.CHECKSUM_ALGORITHM.CREDIT_CARD }),\n  remoteAddr: vs.string({ pattern: vs.STRING.PATTERN.IPV4 }),\n  limit: vs.number({ ifUndefined: 10, integer: true, minValue: { value: 1, adjusts: true }, maxValue: { value: 100, adjusts: true } }),\n  offset: vs.number({ ifUndefined: 0, integer: true, minValue: { value: 0, adjusts: true } }),\n};\n\nconst input = {\n  id: '1',\n  name: 'Pablo Picasso',\n  birthday: '2000-01-02T03:04:05.678Z',\n  age: 20.5,\n  email: 'picasso@example.com',\n  state: 'active',\n  classes: '1,3,abc,4',\n  creditCard: '4111-1111-1111-1111',\n  remoteAddr: '127.0.0.1',\n  limit: '0',\n};\n\ntry {\n  const result = vs.applySchemaObject(schemaObject, input);\n  console.log(result);\n} catch (err) {\n  console.error(err.message);\n}","lang":"typescript","description":"Demonstrates schema definition with various validators and applying to input, showing type coercion and default values."},"warnings":[{"fix":"Use `import vs from 'value-schema'` or `const vs = (await import('value-schema')).default;` for CJS.","message":"Version 4.0.0 changed default import from `value-schema` to ESM; CJS `require` no longer works directly.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace `new Schema(...)` with `vs.object({...})` or `vs.applySchemaObject(...)`.","message":"The `Schema` class constructor pattern is deprecated in favor of using the `vs` factory object.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Wrap call in try/catch or pre-validate input existence.","message":"Common mistake: applying schema to `null` or `undefined` input throws instead of returning defaults. Use `ifUndefined` per field.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Update to new constant names from migration guide.","message":"`vs.NUMBER.INTEGER` constants renamed: `ROUND` -> `ROUND_HALF_UP`, `FLOOR` -> `FLOOR_RZ`, etc.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use `vs.string({ trim: true })` for each element or pre-trim the string.","message":"The `separatedBy` option for arrays does not trim whitespace; input like '1, 2' yields ['1', ' 2'].","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'4.0.0':19 'adjust':96 'ajust':95 'app':43 'automat':27 'base':24 'built':67 'built-in':66 'bun':17 'card':74 'check':47,49,52 'checksum':34 'cjs':87 'coercion':29 'common':41 'compact':77 'credit':73 'date':70 'declar':9 'default':30 'definit':58 'deno':15 'domain':51 'e.g':36 'email':69 'esm':85 'exist':46 'input':10 'ipv4/ipv6':71 'javascript':88 'joi':63 'json':60 'luhn':37 'node.js':13 'offer':65 'param':89,90 'paramet':91,92 'pattern':44 'provid':21 'readabl':56 'schema':3,6,23,57,61 'schema-bas':22 'ship':80 'simplifi':39 'singl':55 'stabl':20 'support':35,84 'syntax':78 'trim':32 'type':28,48,82 'typescript':14,81,97 'unlik':59 'valid':11,25,75,93,94 'valu':2,5,31 'value-schema':1,4 'version':18 'web':42","created_at":"2026-06-07T17:02:47.284206+00:00","updated_at":"2026-06-07T17:02:47.284206+00:00","problems":[{"fix":"Use `const vs = require('value-schema').default;` or switch to ESM `import vs from 'value-schema';`.","cause":"Using CJS `require` on ESM default export.","error":"TypeError: vs is not a function"},{"fix":"Run `npm install value-schema` and ensure correct import path.","cause":"Package not installed or incorrect path.","error":"Cannot find module 'value-schema'"},{"fix":"Use default import: `import vs from 'value-schema'`.","cause":"Importing the whole module as a different name (e.g., `import * as vs from 'value-schema'`) flattens exports.","error":"vs.number is not a function"},{"fix":"Ensure input is an object (use `{}` as fallback).","cause":"Passing undefined/null to `applySchemaObject` instead of an object.","error":"Error: Input is required"}],"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/shimataro/value-schema#readme","github":"https://github.com/shimataro/value-schema","docs":null,"changelog":null,"pypi":null,"npm":"value-schema","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}}