{"_id":"@ap-ent/schema","name":"@ap-ent/schema","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ap-ent/schema","version":"1.0.0","description":"Lightweight zero-dependency TypeScript validation library","license":"MIT","author":{"name":"Gordon Schauer"},"type":"module","main":"./dist/cjs/index.cjs","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","exports":{".":{"types":"./dist/esm/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.cjs"}},"scripts":{"build":"tsup","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","lint":"eslint src __tests__","typecheck":"tsc --noEmit","size":"npm run build && node -e \"const {gzipSync}=require('zlib'),{readFileSync}=require('fs');const b=gzipSync(readFileSync('dist/esm/index.js'));console.log('gzipped:',b.length,'bytes');\""},"devDependencies":{"@types/node":"^20.0.0","eslint":"^8.0.0","@typescript-eslint/parser":"^7.0.0","@typescript-eslint/eslint-plugin":"^7.0.0","tsup":"^8.0.0","typescript":"^5.4.0","vitest":"^1.6.0"},"keywords":["schema","validation","typescript","zero-dependency"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/AloysiusProductions/ap-schema.git"},"homepage":"https://github.com/AloysiusProductions/ap-schema#readme","bugs":{"url":"https://github.com/AloysiusProductions/ap-schema/issues"},"gitHead":"fd19bb5c3bf4e9048dcbfaba5813bc2f8839dd84","_id":"@ap-ent/schema@1.0.0","_nodeVersion":"25.8.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-dfbzXcVTDsgYD7UG6Pyj9TqAEP2C+FlReBpvRdHJrWHtIxzREY5W/NlJlpl+pOzIG8ozCsTAmDsBf2AYX751mA==","shasum":"6f879227fc2dc5731139da89a68b07e7383f1501","tarball":"https://registry.npmjs.org/@ap-ent/schema/-/schema-1.0.0.tgz","fileCount":13,"unpackedSize":60489,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCO3m6bWc5IuDKZzzccThGyVEFAxWwnG0WunQllRemBbQIhAJYBTl8wtRnqdz7KXXR97OwoCmGfJ1dyLjLvHH0ps3Ix"}]},"_npmUser":{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"},"directories":{},"maintainers":[{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/schema_1.0.0_1775331590970_0.652723506649266"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-04T19:39:50.821Z","1.0.0":"2026-04-04T19:39:51.101Z","modified":"2026-04-04T19:39:51.357Z"},"maintainers":[{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"}],"description":"Lightweight zero-dependency TypeScript validation library","homepage":"https://github.com/AloysiusProductions/ap-schema#readme","keywords":["schema","validation","typescript","zero-dependency"],"repository":{"type":"git","url":"git+https://github.com/AloysiusProductions/ap-schema.git"},"author":{"name":"Gordon Schauer"},"bugs":{"url":"https://github.com/AloysiusProductions/ap-schema/issues"},"license":"MIT","readme":"# @ap/schema\r\n\r\nLightweight zero-dependency TypeScript schema validation library — think Zod, but under 2 KB gzipped.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @ap/schema\r\n```\r\n\r\n## Quick Start\r\n\r\n```ts\r\nimport { ap, type Infer } from '@ap/schema';\r\n\r\n// Define a schema\r\nconst UserSchema = ap.object({\r\n  name: ap.string().min(1).max(100),\r\n  email: ap.string().email(),\r\n  age: ap.number().optional(),\r\n});\r\n\r\n// Infer the TypeScript type\r\ntype User = Infer<typeof UserSchema>;\r\n// { name: string; email: string; age: number | undefined }\r\n\r\n// Validate — throws on failure\r\nconst user = UserSchema.parse({ name: 'Alice', email: 'alice@example.com' });\r\n\r\n// Validate — returns result object\r\nconst result = UserSchema.safeParse({ name: '', email: 'bad' });\r\nif (!result.success) {\r\n  console.error(result.errors);\r\n  // [{ path: ['name'], message: 'String must be at least 1 characters' }]\r\n}\r\n```\r\n\r\n## API Reference\r\n\r\n### Primitives\r\n\r\n```ts\r\nap.string()      // string\r\nap.number()      // number (NaN rejected)\r\nap.boolean()     // boolean\r\nap.null_()       // null\r\nap.undefined_()  // undefined\r\n```\r\n\r\n### String Constraints\r\n\r\n```ts\r\nap.string().min(3)              // minimum length\r\nap.string().max(100)            // maximum length\r\nap.string().email()             // valid email format\r\nap.string().url()               // valid URL (uses URL constructor)\r\n```\r\n\r\n### Objects\r\n\r\n```ts\r\nconst schema = ap.object({\r\n  id: ap.number(),\r\n  name: ap.string(),\r\n});\r\ntype T = Infer<typeof schema>; // { id: number; name: string }\r\n```\r\n\r\n### Arrays\r\n\r\n```ts\r\nconst schema = ap.array(ap.string());\r\ntype T = Infer<typeof schema>; // string[]\r\n```\r\n\r\n### Modifiers\r\n\r\n```ts\r\nap.string().optional()  // string | undefined\r\nap.string().nullable()  // string | null\r\n```\r\n\r\n### Custom Refinements\r\n\r\n```ts\r\nconst positiveInt = ap.number()\r\n  .refine((n) => Number.isInteger(n), 'Must be an integer')\r\n  .refine((n) => n > 0, 'Must be positive');\r\n```\r\n\r\n### Parsing\r\n\r\n```ts\r\n// .parse() — throws Error on failure\r\nconst value = schema.parse(input);\r\n\r\n// .safeParse() — returns discriminated union\r\nconst result = schema.safeParse(input);\r\nif (result.success) {\r\n  console.log(result.data);\r\n} else {\r\n  console.error(result.errors); // ValidationError[]\r\n}\r\n```\r\n\r\n### Validation Errors\r\n\r\n```ts\r\ninterface ValidationError {\r\n  path: string[];   // e.g. ['user', 'email'] for nested fields\r\n  message: string;\r\n}\r\n```\r\n\r\n## Type Inference\r\n\r\n```ts\r\nimport { type Infer } from '@ap/schema';\r\n\r\nconst schema = ap.object({ x: ap.number() });\r\ntype MyType = Infer<typeof schema>; // { x: number }\r\n```\r\n\r\n## License\r\n\r\nMIT © Gordon Schauer\r\n","readmeFilename":"README.md","_rev":"1-1c4963aa4ed518e4f1ba3a233643b021"}