Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@esmj/schema

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esmj/schema - npm Package Compare versions

Comparing version
0.7.1
to
0.7.2
+1
dist/chunk-3C2I2ZOZ.mjs
import {c}from'./chunk-QIW3OXV4.mjs';c((i,c,m)=>{if(m?.type==="number"){let n=i;n.min=function(e,{message:t}={}){return this.refine(r=>r>=e,{message:t||`Number must be greater than or equal to ${e}.`})},n.max=function(e,{message:t}={}){return this.refine(r=>r<=e,{message:t||`Number must be less than or equal to ${e}.`})},n.positive=function({message:e}={}){return this.refine(t=>t>0,{message:e||"Number must be positive."})},n.negative=function({message:e}={}){return this.refine(t=>t<0,{message:e||"Number must be negative."})},n.int=function({message:e}={}){return this.refine(t=>Number.isInteger(t),{message:e||"Number must be an integer."})},n.float=function({message:e}={}){return this.refine(t=>Number.isFinite(t)&&!Number.isInteger(t),{message:e||"Number must be a floating point (non-integer)."})},n.multipleOf=function(e,{message:t}={}){return this.refine(r=>r%e===0,{message:t||`Number must be a multiple of ${e}.`})},n.finite=function({message:e}={}){return this.refine(t=>Number.isFinite(t),{message:e||"Number must be finite."})};}return i});
import {c}from'./chunk-QIW3OXV4.mjs';c((i,s,c)=>{if(c?.type==="string"){let r=i;r.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},r.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},r.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},r.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"String must not be empty (received empty string)"})},r.startsWith=function(t,{message:n}={}){return this.refine(e=>e.startsWith(t),{message:n||(e=>`String must start with "${t}" (received: "${e}")`)})},r.endsWith=function(t,{message:n}={}){return this.refine(e=>e.endsWith(t),{message:n||(e=>`String must end with "${t}" (received: "${e}")`)})},r.includes=function(t,{message:n}={}){return this.refine(e=>e.includes(t),{message:n||(e=>`String must include "${t}" (received: "${e}")`)})},r.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},r.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},r.trim=function(){return this.transform(t=>t.trim())},r.padStart=function(t,n=" "){return this.transform(e=>e.padStart(t,n))},r.padEnd=function(t,n=" "){return this.transform(e=>e.padEnd(t,n))},r.replace=function(t,n){return this.transform(e=>e.replace(t,n))};}return i});
import {c}from'./chunk-QIW3OXV4.mjs';c((a,o,m)=>{if(m?.type==="array"){let r=a;r.min=function(e,{message:t}={}){return this.refine(n=>n.length>=e,{message:t||`Array must contain at least ${e} items.`})},r.max=function(e,{message:t}={}){return this.refine(n=>n.length<=e,{message:t||`Array must contain at most ${e} items.`})},r.length=function(e,{message:t}={}){return this.refine(n=>n.length===e,{message:t||`Array must contain exactly ${e} items.`})},r.nonEmpty=function({message:e}={}){return this.refine(t=>t.length>0,{message:e||"Array must not be empty."})},r.unique=function({message:e}={}){return this.refine(t=>{let n=new Set;try{return t.every(c=>{let s=JSON.stringify(c);return n.has(s)?!1:(n.add(s),!0)})}catch{return new Set(t).size===t.length}},{message:e||"Array items must be unique."})},r.sort=function(){return this.transform(e=>[...e].sort())},r.reverse=function(){return this.transform(e=>[...e].reverse())};}return a});
var E={abortEarly:true};function b(e,t){if(!t)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function w(e,t,n){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)t.push(b(e.errors[a],n));}function T(e){return {...E,...e}}var d=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,D=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,t){let n=l(x,{...t,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([p,o])=>`${p}: ${o._getDescription()}`).join(", ")} })`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u={},c=[];for(let i in e){let f=e[i]._parse(r.data[i],o);if(f.success)u[i]=f.data;else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},string(e){return l(d,{...e,type:"string"})},number(e){return l(y,{...e,type:"number"})},boolean(e){return l(g,{...e,type:"boolean"})},date(e){return l(D,{...e,type:"date"})},enum(e,t){let n=r=>e.includes(r),a=r=>`Invalid ${p} value. Expected ${e.map(s=>`"${s}"`).join(" | ")}, received "${r}".`,p="enum",o=l(n,{message:a,...t,type:p});return o._getDescription=()=>`enum(${e.map(r=>`"${r}"`).join(" | ")})`,o},array(e,t){let n=l(_,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u=[],c=[];for(let i=0;i<r.data.length;i++){let f=e._parse(r.data[i],o);if(f.success)u.push(f.data);else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},any(){return l(()=>true)},preprocess(e,t){return h(t,"_parse",(n,a)=>(a=e(a),n(a))),t},union(e,t){return l(o=>{for(let r=0;r<e.length;r++){let s=e[r]._parse(o);if(s.success)return s}return false},{message:o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((r,s)=>` ${s+1}. ${r._getDescription()}`).join(",")} but received "${typeof o}" with value: ${x(o)?JSON.stringify(o):`"${o}"`}`,...t,type:"union"})},literal(e,t){let p=l(o=>o===e,{message:o=>t?.message?typeof t.message=="function"?t.message(o):t.message:`Expected literal value "${e}", received "${o}"`,name:t?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p},coerce:{string(e){return m.preprocess(t=>String(t),m.string(e))},number(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:t}))},boolean(e){return m.preprocess(t=>!!t,m.boolean(e))},date(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:t}))}},cast:{boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||n===1?true:a==="false"||a==="no"||a==="off"||a==="0"||n===0?false:n},m.boolean({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(g(n))return Number(n);if(d(n)){let a=n.trim();if(a==="")return n;let p=Number(a);if(Number.isFinite(p))return p}return n},m.number({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>g(n)||y(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.trim()),y(n)&&Number.isFinite(n)||a?new Date(a??n):n},m.date({...e,message:t}))},json(e,t){let n=t?.message??(a=>`Cannot parse "${a}" as JSON.`);return h(e,"_parse",(a,p)=>{if(d(p))try{p=JSON.parse(p);}catch{let o={message:typeof n=="function"?n(p):n};return {success:false,error:o,errors:[o]}}return a(p)}),e}}};function P(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function h(e,t,n){let a=e[t];e[t]=(...p)=>n(a,...p);}function l(e,{type:t="any",name:n,message:a}={}){a=a||P(t);let p={name:n,message:a,type:t},o={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(r,s){let u=e(r);if(u===true)return {success:true,data:r};if(typeof u=="object"&&u?.success===true)return u;let c={message:typeof a=="function"?a(r):a};return {success:false,error:c,errors:[c]}},parse(r,s){let u=o._parse(r,s);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(r,s){return o._parse(r,s)},transform(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success&&(i.data=r(i.data)),i}),this},optional(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===void 0&&(c.data=void 0,c.success=true),c}),this},nullable(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===null&&(c.data=null,c.success=true),c}),this},nullish(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s==null&&(c.success=true,c.data=s),c}),this},default(r){return h(this,"_parse",(s,u,c)=>(u===void 0&&(u=typeof r=="function"?r():r),s(u,c))),this},catch(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?i:{success:true,data:typeof r=="function"?r({input:u,error:i.error}):r}}),this},pipe(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?r._parse(i.data,c):i}),this},refine(r,{message:s,type:u}={}){return u&&(s=s||P(u),t=u),h(this,"_parse",(c,i,f)=>{let I=c(i,f);T(f);if(!I.success)return I;let S=r(I.data);if(S===true||typeof S=="object"&&S?.success===true)return I;let k={message:typeof s=="function"?s(i):s};return {success:false,error:k,errors:[k]}}),this}};return O.length>0?O.reduce((r,s)=>s(r,e,p)??r,o):o}var O=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}export{m as a,h as b,A as c};
+1
-1

@@ -1,1 +0,1 @@

'use strict';var k={abortEarly:true};function y(e,c){if(!c)return e;let p=e?.cause?.key?`${c}.${e.cause.key}`:`${c}`;return {message:`Error parsing key "${p}": ${e.message}`,cause:{key:p}}}function T(e,c,p){if(e.errors?.length)for(let u=0;u<e.errors.length;u++)c.push(y(e.errors[u],p));}function S(e){return {...k,...e}}var w=e=>typeof e=="string"||e instanceof String,P=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),A=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,c){let p=l(O,{...c,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(e).map(([o,r])=>`${o}: ${r._getDescription()}`).join(", ")} })`,m(p,"_parse",(u,o,r)=>{let t=u(o,r),{abortEarly:n}=S(r);if(t.success===false)return t;let a={},s=[];for(let i in e){let f=e[i]._parse(t.data[i],r);if(f.success)a[i]=f.data;else {if(f=f,n!==false){let h=y(f.error,i);return {success:false,error:h,errors:[h]}}T(f,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:a}}),p},string(e){return l(w,{...e,type:"string"})},number(e){return l(P,{...e,type:"number"})},boolean(e){return l(A,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,c){let p=t=>e.includes(t),u=t=>`Invalid ${o} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,o="enum",r=l(p,{message:u,...c,type:o});return r._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,r},array(e,c){let p=l(_,{...c,type:"array"});return p._getDescription=()=>`array(${e._getDescription()})`,m(p,"_parse",(u,o,r)=>{let t=u(o,r),{abortEarly:n}=S(r);if(t.success===false)return t;let a=[],s=[];for(let i=0;i<t.data.length;i++){let f=e._parse(t.data[i],r);if(f.success)a.push(f.data);else {if(f=f,n!==false){let h=y(f.error,i);return {success:false,error:h,errors:[h]}}T(f,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:a}}),p},any(){return l(()=>true)},preprocess(e,c){return m(c,"_parse",(p,u)=>(u=e(u),p(u))),c},union(e,c){return l(r=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(r);if(n.success)return n}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof r}" with value: ${O(r)?JSON.stringify(r):`"${r}"`}`,...c,type:"union"})},literal(e,c){let o=l(r=>r===e,{message:r=>c?.message?typeof c.message=="function"?c.message(r):c.message:`Expected literal value "${e}", received "${r}"`,name:c?.name,type:"literal"});return o._getDescription=()=>`literal("${e}")`,o}};function b(e){return c=>`The value "${c}" must be type of ${e} but is type of "${typeof c}".`}function m(e,c,p){let u=e[c];e[c]=(...o)=>p(u,...o);}function l(e,{type:c="any",name:p,message:u}={}){u=u||b(c);let o={name:p,message:u,type:c},r={_getName(){return p},_getType(){return c},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let s={message:typeof u=="function"?u(t):u};return {success:false,error:s,errors:[s]}},parse(t,n){let a=r._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return r._parse(t,n)},transform(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success&&(i.data=t(i.data)),i}),this},optional(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n===void 0&&(s.data=void 0,s.success=true),s}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n===null&&(s.data=null,s.success=true),s}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n==null&&(s.success=true,s.data=n),s}),this},default(t){return m(this,"_parse",(n,a,s)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,s))),this},catch(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success?i:{success:true,data:typeof t=="function"?t({input:a,error:i.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success?t._parse(i.data,s):i}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||b(a),c=a),m(this,"_parse",(s,i,f)=>{let h=s(i,f);S(f);if(!h.success)return h;let I=t(h.data);if(I===true||typeof I=="object"&&I?.success===true)return h;let g={message:typeof n=="function"?n(i):n};return {success:false,error:g,errors:[g]}}),this}};return d.length>0?d.reduce((t,n)=>n(t,e,o)??t,r):r}var d=[];function x(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");d.push(e);}x((e,c,p)=>{if(p?.type==="array"){let u=e;u.min=function(o,{message:r}={}){return this.refine(t=>t.length>=o,{message:r||`Array must contain at least ${o} items.`})},u.max=function(o,{message:r}={}){return this.refine(t=>t.length<=o,{message:r||`Array must contain at most ${o} items.`})},u.length=function(o,{message:r}={}){return this.refine(t=>t.length===o,{message:r||`Array must contain exactly ${o} items.`})},u.nonEmpty=function({message:o}={}){return this.refine(r=>r.length>0,{message:o||"Array must not be empty."})},u.unique=function({message:o}={}){return this.refine(r=>{let t=new Set;try{return r.every(n=>{let a=JSON.stringify(n);return t.has(a)?!1:(t.add(a),!0)})}catch{return new Set(r).size===r.length}},{message:o||"Array items must be unique."})},u.sort=function(){return this.transform(o=>[...o].sort())},u.reverse=function(){return this.transform(o=>[...o].reverse())};}return e});exports.extend=x;exports.hookOriginal=m;exports.s=R;
'use strict';var E={abortEarly:true};function b(e,a){if(!a)return e;let n=e?.cause?.key?`${a}.${e.cause.key}`:`${a}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function k(e,a,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)a.push(b(e.errors[r],n));}function T(e){return {...E,...e}}var l=e=>typeof e=="string"||e instanceof String,d=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,$=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,a){let n=S(x,{...a,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([u,c])=>`${u}: ${c._getDescription()}`).join(", ")} })`,h(n,"_parse",(r,u,c)=>{let t=r(u,c),{abortEarly:s}=T(c);if(t.success===false)return t;let o={},i=[];for(let p in e){let f=e[p]._parse(t.data[p],c);if(f.success)o[p]=f.data;else {if(f=f,s!==false){let I=b(f.error,p);return {success:false,error:I,errors:[I]}}k(f,i,p);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n},string(e){return S(l,{...e,type:"string"})},number(e){return S(d,{...e,type:"number"})},boolean(e){return S(g,{...e,type:"boolean"})},date(e){return S($,{...e,type:"date"})},enum(e,a){let n=t=>e.includes(t),r=t=>`Invalid ${u} value. Expected ${e.map(s=>`"${s}"`).join(" | ")}, received "${t}".`,u="enum",c=S(n,{message:r,...a,type:u});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,a){let n=S(_,{...a,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(r,u,c)=>{let t=r(u,c),{abortEarly:s}=T(c);if(t.success===false)return t;let o=[],i=[];for(let p=0;p<t.data.length;p++){let f=e._parse(t.data[p],c);if(f.success)o.push(f.data);else {if(f=f,s!==false){let I=b(f.error,p);return {success:false,error:I,errors:[I]}}k(f,i,p);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n},any(){return S(()=>true)},preprocess(e,a){return h(a,"_parse",(n,r)=>(r=e(r),n(r))),a},union(e,a){return S(c=>{for(let t=0;t<e.length;t++){let s=e[t]._parse(c);if(s.success)return s}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,s)=>` ${s+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${x(c)?JSON.stringify(c):`"${c}"`}`,...a,type:"union"})},literal(e,a){let u=S(c=>c===e,{message:c=>a?.message?typeof a.message=="function"?a.message(c):a.message:`Expected literal value "${e}", received "${c}"`,name:a?.name,type:"literal"});return u._getDescription=()=>`literal("${e}")`,u},coerce:{string(e){return m.preprocess(a=>String(a),m.string(e))},number(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:a}))},boolean(e){return m.preprocess(a=>!!a,m.boolean(e))},date(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:a}))}},cast:{boolean(e){let a=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},m.boolean({...e,message:a}))},number(e){let a=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(g(n))return Number(n);if(l(n)){let r=n.trim();if(r==="")return n;let u=Number(r);if(Number.isFinite(u))return u}return n},m.number({...e,message:a}))},string(e){let a=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>g(n)||d(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:a}))},date(e){let a=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.trim()),d(n)&&Number.isFinite(n)||r?new Date(r??n):n},m.date({...e,message:a}))},json(e,a){let n=a?.message??(r=>`Cannot parse "${r}" as JSON.`);return h(e,"_parse",(r,u)=>{if(l(u))try{u=JSON.parse(u);}catch{let c={message:typeof n=="function"?n(u):n};return {success:false,error:c,errors:[c]}}return r(u)}),e}}};function P(e){return a=>`The value "${a}" must be type of ${e} but is type of "${typeof a}".`}function h(e,a,n){let r=e[a];e[a]=(...u)=>n(r,...u);}function S(e,{type:a="any",name:n,message:r}={}){r=r||P(a);let u={name:n,message:r,type:a},c={_getName(){return n},_getType(){return a},_getDescription(){return this._getName()??this._getType()},_parse(t,s){let o=e(t);if(o===true)return {success:true,data:t};if(typeof o=="object"&&o?.success===true)return o;let i={message:typeof r=="function"?r(t):r};return {success:false,error:i,errors:[i]}},parse(t,s){let o=c._parse(t,s);if(!o.success)throw o=o,new Error(o.error.message,{cause:o.error.cause});return o.data},safeParse(t,s){return c._parse(t,s)},transform(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success&&(p.data=t(p.data)),p}),this},optional(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s===null&&(i.data=null,i.success=true),i}),this},nullish(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s==null&&(i.success=true,i.data=s),i}),this},default(t){return h(this,"_parse",(s,o,i)=>(o===void 0&&(o=typeof t=="function"?t():t),s(o,i))),this},catch(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success?p:{success:true,data:typeof t=="function"?t({input:o,error:p.error}):t}}),this},pipe(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success?t._parse(p.data,i):p}),this},refine(t,{message:s,type:o}={}){return o&&(s=s||P(o),a=o),h(this,"_parse",(i,p,f)=>{let I=i(p,f);T(f);if(!I.success)return I;let y=t(I.data);if(y===true||typeof y=="object"&&y?.success===true)return I;let w={message:typeof s=="function"?s(p):s};return {success:false,error:w,errors:[w]}}),this}};return O.length>0?O.reduce((t,s)=>s(t,e,u)??t,c):c}var O=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}A((e,a,n)=>{if(n?.type==="array"){let r=e;r.min=function(u,{message:c}={}){return this.refine(t=>t.length>=u,{message:c||`Array must contain at least ${u} items.`})},r.max=function(u,{message:c}={}){return this.refine(t=>t.length<=u,{message:c||`Array must contain at most ${u} items.`})},r.length=function(u,{message:c}={}){return this.refine(t=>t.length===u,{message:c||`Array must contain exactly ${u} items.`})},r.nonEmpty=function({message:u}={}){return this.refine(c=>c.length>0,{message:u||"Array must not be empty."})},r.unique=function({message:u}={}){return this.refine(c=>{let t=new Set;try{return c.every(s=>{let o=JSON.stringify(s);return t.has(o)?!1:(t.add(o),!0)})}catch{return new Set(c).size===c.length}},{message:u||"Array items must be unique."})},r.sort=function(){return this.transform(u=>[...u].sort())},r.reverse=function(){return this.transform(u=>[...u].reverse())};}return e});exports.extend=A;exports.hookOriginal=h;exports.s=m;exports.schema=m;

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,1 +0,1 @@

import'./chunk-4JJPVRF6.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
import'./chunk-GJNOESJT.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';

@@ -1,1 +0,1 @@

'use strict';var w={abortEarly:true};function y(n,u){if(!u)return n;let o=n?.cause?.key?`${u}.${n.cause.key}`:`${u}`;return {message:`Error parsing key "${o}": ${n.message}`,cause:{key:o}}}function O(n,u,o){if(n.errors?.length)for(let a=0;a<n.errors.length;a++)u.push(y(n.errors[a],o));}function d(n){return {...w,...n}}var k=n=>typeof n=="string"||n instanceof String,P=n=>(typeof n=="number"||n instanceof Number)&&!Number.isNaN(n),$=n=>n===true||n===false,N=n=>n instanceof Date&&!Number.isNaN(n.getTime()),E=n=>Array.isArray(n),T=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),v={object(n,u){let o=S(T,{...u,type:"object"});return o._getDescription=()=>`object({ ${Object.entries(n).map(([t,r])=>`${t}: ${r._getDescription()}`).join(", ")} })`,p(o,"_parse",(a,t,r)=>{let e=a(t,r),{abortEarly:s}=d(r);if(e.success===false)return e;let c={},i=[];for(let m in n){let f=n[m]._parse(e.data[m],r);if(f.success)c[m]=f.data;else {if(f=f,s!==false){let h=y(f.error,m);return {success:false,error:h,errors:[h]}}O(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),o},string(n){return S(k,{...n,type:"string"})},number(n){return S(P,{...n,type:"number"})},boolean(n){return S($,{...n,type:"boolean"})},date(n){return S(N,{...n,type:"date"})},enum(n,u){let o=e=>n.includes(e),a=e=>`Invalid ${t} value. Expected ${n.map(s=>`"${s}"`).join(" | ")}, received "${e}".`,t="enum",r=S(o,{message:a,...u,type:t});return r._getDescription=()=>`enum(${n.map(e=>`"${e}"`).join(" | ")})`,r},array(n,u){let o=S(E,{...u,type:"array"});return o._getDescription=()=>`array(${n._getDescription()})`,p(o,"_parse",(a,t,r)=>{let e=a(t,r),{abortEarly:s}=d(r);if(e.success===false)return e;let c=[],i=[];for(let m=0;m<e.data.length;m++){let f=n._parse(e.data[m],r);if(f.success)c.push(f.data);else {if(f=f,s!==false){let h=y(f.error,m);return {success:false,error:h,errors:[h]}}O(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),o},any(){return S(()=>true)},preprocess(n,u){return p(u,"_parse",(o,a)=>(a=n(a),o(a))),u},union(n,u){return S(r=>{for(let e=0;e<n.length;e++){let s=n[e]._parse(r);if(s.success)return s}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${n.map((e,s)=>` ${s+1}. ${e._getDescription()}`).join(",")} but received "${typeof r}" with value: ${T(r)?JSON.stringify(r):`"${r}"`}`,...u,type:"union"})},literal(n,u){let t=S(r=>r===n,{message:r=>u?.message?typeof u.message=="function"?u.message(r):u.message:`Expected literal value "${n}", received "${r}"`,name:u?.name,type:"literal"});return t._getDescription=()=>`literal("${n}")`,t}};function x(n){return u=>`The value "${u}" must be type of ${n} but is type of "${typeof u}".`}function p(n,u,o){let a=n[u];n[u]=(...t)=>o(a,...t);}function S(n,{type:u="any",name:o,message:a}={}){a=a||x(u);let t={name:o,message:a,type:u},r={_getName(){return o},_getType(){return u},_getDescription(){return this._getName()??this._getType()},_parse(e,s){let c=n(e);if(c===true)return {success:true,data:e};if(typeof c=="object"&&c?.success===true)return c;let i={message:typeof a=="function"?a(e):a};return {success:false,error:i,errors:[i]}},parse(e,s){let c=r._parse(e,s);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(e,s){return r._parse(e,s)},transform(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success&&(m.data=e(m.data)),m}),this},optional(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===null&&(i.data=null,i.success=true),i}),this},nullish(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s==null&&(i.success=true,i.data=s),i}),this},default(e){return p(this,"_parse",(s,c,i)=>(c===void 0&&(c=typeof e=="function"?e():e),s(c,i))),this},catch(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success?m:{success:true,data:typeof e=="function"?e({input:c,error:m.error}):e}}),this},pipe(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success?e._parse(m.data,i):m}),this},refine(e,{message:s,type:c}={}){return c&&(s=s||x(c),u=c),p(this,"_parse",(i,m,f)=>{let h=i(m,f);d(f);if(!h.success)return h;let l=e(h.data);if(l===true||typeof l=="object"&&l?.success===true)return h;let b={message:typeof s=="function"?s(m):s};return {success:false,error:b,errors:[b]}}),this}};return g.length>0?g.reduce((e,s)=>s(e,n,t)??e,r):r}var g=[];function I(n){if(typeof n!="function")throw new TypeError("extend() requires a function argument");g.push(n);}I((n,u,o)=>{if(o?.type==="string"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e.length>=t,{message:r||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},a.max=function(t,{message:r}={}){return this.refine(e=>e.length<=t,{message:r||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},a.length=function(t,{message:r}={}){return this.refine(e=>e.length===t,{message:r||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},a.nonEmpty=function({message:t}={}){return this.refine(r=>r.length>0,{message:t||"String must not be empty (received empty string)"})},a.startsWith=function(t,{message:r}={}){return this.refine(e=>e.startsWith(t),{message:r||(e=>`String must start with "${t}" (received: "${e}")`)})},a.endsWith=function(t,{message:r}={}){return this.refine(e=>e.endsWith(t),{message:r||(e=>`String must end with "${t}" (received: "${e}")`)})},a.includes=function(t,{message:r}={}){return this.refine(e=>e.includes(t),{message:r||(e=>`String must include "${t}" (received: "${e}")`)})},a.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},a.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},a.trim=function(){return this.transform(t=>t.trim())},a.padStart=function(t,r=" "){return this.transform(e=>e.padStart(t,r))},a.padEnd=function(t,r=" "){return this.transform(e=>e.padEnd(t,r))},a.replace=function(t,r){return this.transform(e=>e.replace(t,r))};}return n});I((n,u,o)=>{if(o?.type==="number"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e>=t,{message:r||`Number must be greater than or equal to ${t}.`})},a.max=function(t,{message:r}={}){return this.refine(e=>e<=t,{message:r||`Number must be less than or equal to ${t}.`})},a.positive=function({message:t}={}){return this.refine(r=>r>0,{message:t||"Number must be positive."})},a.negative=function({message:t}={}){return this.refine(r=>r<0,{message:t||"Number must be negative."})},a.int=function({message:t}={}){return this.refine(r=>Number.isInteger(r),{message:t||"Number must be an integer."})},a.float=function({message:t}={}){return this.refine(r=>Number.isFinite(r)&&!Number.isInteger(r),{message:t||"Number must be a floating point (non-integer)."})},a.multipleOf=function(t,{message:r}={}){return this.refine(e=>e%t===0,{message:r||`Number must be a multiple of ${t}.`})},a.finite=function({message:t}={}){return this.refine(r=>Number.isFinite(r),{message:t||"Number must be finite."})};}return n});I((n,u,o)=>{if(o?.type==="array"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e.length>=t,{message:r||`Array must contain at least ${t} items.`})},a.max=function(t,{message:r}={}){return this.refine(e=>e.length<=t,{message:r||`Array must contain at most ${t} items.`})},a.length=function(t,{message:r}={}){return this.refine(e=>e.length===t,{message:r||`Array must contain exactly ${t} items.`})},a.nonEmpty=function({message:t}={}){return this.refine(r=>r.length>0,{message:t||"Array must not be empty."})},a.unique=function({message:t}={}){return this.refine(r=>{let e=new Set;try{return r.every(s=>{let c=JSON.stringify(s);return e.has(c)?!1:(e.add(c),!0)})}catch{return new Set(r).size===r.length}},{message:t||"Array items must be unique."})},a.sort=function(){return this.transform(t=>[...t].sort())},a.reverse=function(){return this.transform(t=>[...t].reverse())};}return n});exports.extend=I;exports.hookOriginal=p;exports.s=v;
'use strict';var P={abortEarly:true};function O(e,c){if(!c)return e;let s=e?.cause?.key?`${c}.${e.cause.key}`:`${c}`;return {message:`Error parsing key "${s}": ${e.message}`,cause:{key:s}}}function k(e,c,s){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)c.push(O(e.errors[a],s));}function T(e){return {...P,...e}}var g=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),b=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),A=e=>Array.isArray(e),N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),p={object(e,c){let s=I(N,{...c,type:"object"});return s._getDescription=()=>`object({ ${Object.entries(e).map(([n,r])=>`${n}: ${r._getDescription()}`).join(", ")} })`,h(s,"_parse",(a,n,r)=>{let t=a(n,r),{abortEarly:o}=T(r);if(t.success===false)return t;let i={},u=[];for(let m in e){let f=e[m]._parse(t.data[m],r);if(f.success)i[m]=f.data;else {if(f=f,o!==false){let S=O(f.error,m);return {success:false,error:S,errors:[S]}}k(f,u,m);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),s},string(e){return I(g,{...e,type:"string"})},number(e){return I(y,{...e,type:"number"})},boolean(e){return I(b,{...e,type:"boolean"})},date(e){return I(E,{...e,type:"date"})},enum(e,c){let s=t=>e.includes(t),a=t=>`Invalid ${n} value. Expected ${e.map(o=>`"${o}"`).join(" | ")}, received "${t}".`,n="enum",r=I(s,{message:a,...c,type:n});return r._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,r},array(e,c){let s=I(A,{...c,type:"array"});return s._getDescription=()=>`array(${e._getDescription()})`,h(s,"_parse",(a,n,r)=>{let t=a(n,r),{abortEarly:o}=T(r);if(t.success===false)return t;let i=[],u=[];for(let m=0;m<t.data.length;m++){let f=e._parse(t.data[m],r);if(f.success)i.push(f.data);else {if(f=f,o!==false){let S=O(f.error,m);return {success:false,error:S,errors:[S]}}k(f,u,m);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),s},any(){return I(()=>true)},preprocess(e,c){return h(c,"_parse",(s,a)=>(a=e(a),s(a))),c},union(e,c){return I(r=>{for(let t=0;t<e.length;t++){let o=e[t]._parse(r);if(o.success)return o}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,o)=>` ${o+1}. ${t._getDescription()}`).join(",")} but received "${typeof r}" with value: ${N(r)?JSON.stringify(r):`"${r}"`}`,...c,type:"union"})},literal(e,c){let n=I(r=>r===e,{message:r=>c?.message?typeof c.message=="function"?c.message(r):c.message:`Expected literal value "${e}", received "${r}"`,name:c?.name,type:"literal"});return n._getDescription=()=>`literal("${e}")`,n},coerce:{string(e){return p.preprocess(c=>String(c),p.string(e))},number(e){let c=e?.message??(s=>`Cannot coerce "${s}" to a valid number.`);return p.preprocess(s=>Number(s),p.number({...e,message:c}))},boolean(e){return p.preprocess(c=>!!c,p.boolean(e))},date(e){let c=e?.message??(s=>`Cannot coerce "${s}" to a valid date.`);return p.preprocess(s=>new Date(s),p.date({...e,message:c}))}},cast:{boolean(e){let c=e?.message??(s=>`Cannot cast "${s}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return p.preprocess(s=>{let a;return g(s)&&(a=s.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||s===1?true:a==="false"||a==="no"||a==="off"||a==="0"||s===0?false:s},p.boolean({...e,message:c}))},number(e){let c=e?.message??(s=>`Cannot cast "${s}" to a number. Expected a numeric string or number.`);return p.preprocess(s=>{if(b(s))return Number(s);if(g(s)){let a=s.trim();if(a==="")return s;let n=Number(a);if(Number.isFinite(n))return n}return s},p.number({...e,message:c}))},string(e){let c=e?.message??(s=>`Cannot cast "${s}" to string. Expected a string, number, or boolean.`);return p.preprocess(s=>b(s)||y(s)&&Number.isFinite(s)?String(s):s,p.string({...e,message:c}))},date(e){let c=e?.message??(s=>`Cannot cast "${s}" to a valid date.`);return p.preprocess(s=>{let a;return g(s)&&(a=s.trim()),y(s)&&Number.isFinite(s)||a?new Date(a??s):s},p.date({...e,message:c}))},json(e,c){let s=c?.message??(a=>`Cannot parse "${a}" as JSON.`);return h(e,"_parse",(a,n)=>{if(g(n))try{n=JSON.parse(n);}catch{let r={message:typeof s=="function"?s(n):s};return {success:false,error:r,errors:[r]}}return a(n)}),e}}};function $(e){return c=>`The value "${c}" must be type of ${e} but is type of "${typeof c}".`}function h(e,c,s){let a=e[c];e[c]=(...n)=>s(a,...n);}function I(e,{type:c="any",name:s,message:a}={}){a=a||$(c);let n={name:s,message:a,type:c},r={_getName(){return s},_getType(){return c},_getDescription(){return this._getName()??this._getType()},_parse(t,o){let i=e(t);if(i===true)return {success:true,data:t};if(typeof i=="object"&&i?.success===true)return i;let u={message:typeof a=="function"?a(t):a};return {success:false,error:u,errors:[u]}},parse(t,o){let i=r._parse(t,o);if(!i.success)throw i=i,new Error(i.error.message,{cause:i.error.cause});return i.data},safeParse(t,o){return r._parse(t,o)},transform(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success&&(m.data=t(m.data)),m}),this},optional(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===void 0&&(u.data=void 0,u.success=true),u}),this},nullable(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===null&&(u.data=null,u.success=true),u}),this},nullish(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o==null&&(u.success=true,u.data=o),u}),this},default(t){return h(this,"_parse",(o,i,u)=>(i===void 0&&(i=typeof t=="function"?t():t),o(i,u))),this},catch(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success?m:{success:true,data:typeof t=="function"?t({input:i,error:m.error}):t}}),this},pipe(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success?t._parse(m.data,u):m}),this},refine(t,{message:o,type:i}={}){return i&&(o=o||$(i),c=i),h(this,"_parse",(u,m,f)=>{let S=u(m,f);T(f);if(!S.success)return S;let d=t(S.data);if(d===true||typeof d=="object"&&d?.success===true)return S;let x={message:typeof o=="function"?o(m):o};return {success:false,error:x,errors:[x]}}),this}};return w.length>0?w.reduce((t,o)=>o(t,e,n)??t,r):r}var w=[];function l(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");w.push(e);}l((e,c,s)=>{if(s?.type==="string"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t.length>=n,{message:r||(t=>`String must be at least ${n} characters long (received ${t.length} characters: "${t}")`)})},a.max=function(n,{message:r}={}){return this.refine(t=>t.length<=n,{message:r||(t=>`String must be at most ${n} characters long (received ${t.length} characters: "${t}")`)})},a.length=function(n,{message:r}={}){return this.refine(t=>t.length===n,{message:r||(t=>`String must be exactly ${n} characters long (received ${t.length} characters: "${t}")`)})},a.nonEmpty=function({message:n}={}){return this.refine(r=>r.length>0,{message:n||"String must not be empty (received empty string)"})},a.startsWith=function(n,{message:r}={}){return this.refine(t=>t.startsWith(n),{message:r||(t=>`String must start with "${n}" (received: "${t}")`)})},a.endsWith=function(n,{message:r}={}){return this.refine(t=>t.endsWith(n),{message:r||(t=>`String must end with "${n}" (received: "${t}")`)})},a.includes=function(n,{message:r}={}){return this.refine(t=>t.includes(n),{message:r||(t=>`String must include "${n}" (received: "${t}")`)})},a.toLowerCase=function(){return this.transform(n=>n.toLowerCase())},a.toUpperCase=function(){return this.transform(n=>n.toUpperCase())},a.trim=function(){return this.transform(n=>n.trim())},a.padStart=function(n,r=" "){return this.transform(t=>t.padStart(n,r))},a.padEnd=function(n,r=" "){return this.transform(t=>t.padEnd(n,r))},a.replace=function(n,r){return this.transform(t=>t.replace(n,r))};}return e});l((e,c,s)=>{if(s?.type==="number"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t>=n,{message:r||`Number must be greater than or equal to ${n}.`})},a.max=function(n,{message:r}={}){return this.refine(t=>t<=n,{message:r||`Number must be less than or equal to ${n}.`})},a.positive=function({message:n}={}){return this.refine(r=>r>0,{message:n||"Number must be positive."})},a.negative=function({message:n}={}){return this.refine(r=>r<0,{message:n||"Number must be negative."})},a.int=function({message:n}={}){return this.refine(r=>Number.isInteger(r),{message:n||"Number must be an integer."})},a.float=function({message:n}={}){return this.refine(r=>Number.isFinite(r)&&!Number.isInteger(r),{message:n||"Number must be a floating point (non-integer)."})},a.multipleOf=function(n,{message:r}={}){return this.refine(t=>t%n===0,{message:r||`Number must be a multiple of ${n}.`})},a.finite=function({message:n}={}){return this.refine(r=>Number.isFinite(r),{message:n||"Number must be finite."})};}return e});l((e,c,s)=>{if(s?.type==="array"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t.length>=n,{message:r||`Array must contain at least ${n} items.`})},a.max=function(n,{message:r}={}){return this.refine(t=>t.length<=n,{message:r||`Array must contain at most ${n} items.`})},a.length=function(n,{message:r}={}){return this.refine(t=>t.length===n,{message:r||`Array must contain exactly ${n} items.`})},a.nonEmpty=function({message:n}={}){return this.refine(r=>r.length>0,{message:n||"Array must not be empty."})},a.unique=function({message:n}={}){return this.refine(r=>{let t=new Set;try{return r.every(o=>{let i=JSON.stringify(o);return t.has(i)?!1:(t.add(i),!0)})}catch{return new Set(r).size===r.length}},{message:n||"Array items must be unique."})},a.sort=function(){return this.transform(n=>[...n].sort())},a.reverse=function(){return this.transform(n=>[...n].reverse())};}return e});exports.extend=l;exports.hookOriginal=h;exports.s=p;exports.schema=p;
import './string.mjs';
import './number.mjs';
import './array.mjs';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';
import './string.js';
import './number.js';
import './array.js';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';

@@ -1,1 +0,1 @@

import'./chunk-4JJPVRF6.mjs';import'./chunk-PH4B25KI.mjs';import'./chunk-LZRUIXQL.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
import'./chunk-GJNOESJT.mjs';import'./chunk-3C2I2ZOZ.mjs';import'./chunk-G6KRMWVT.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';

@@ -1,1 +0,1 @@

'use strict';var k={abortEarly:true};function d(e,s){if(!s)return e;let i=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function T(e,s,i){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)s.push(d(e.errors[o],i));}function y(e){return {...k,...e}}var x=e=>typeof e=="string"||e instanceof String,w=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),P=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),b=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$={object(e,s){let i=h(b,{...s,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([p,c])=>`${p}: ${c._getDescription()}`).join(", ")} })`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a={},r=[];for(let u in e){let f=e[u]._parse(t.data[u],c);if(f.success)a[u]=f.data;else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},string(e){return h(x,{...e,type:"string"})},number(e){return h(w,{...e,type:"number"})},boolean(e){return h(P,{...e,type:"boolean"})},date(e){return h(E,{...e,type:"date"})},enum(e,s){let i=t=>e.includes(t),o=t=>`Invalid ${p} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,p="enum",c=h(i,{message:o,...s,type:p});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let i=h(_,{...s,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a=[],r=[];for(let u=0;u<t.data.length;u++){let f=e._parse(t.data[u],c);if(f.success)a.push(f.data);else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},any(){return h(()=>true)},preprocess(e,s){return m(s,"_parse",(i,o)=>(o=e(o),i(o))),s},union(e,s){return h(c=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(c);if(n.success)return n}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${b(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})},literal(e,s){let p=h(c=>c===e,{message:c=>s?.message?typeof s.message=="function"?s.message(c):s.message:`Expected literal value "${e}", received "${c}"`,name:s?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function m(e,s,i){let o=e[s];e[s]=(...p)=>i(o,...p);}function h(e,{type:s="any",name:i,message:o}={}){o=o||O(s);let p={name:i,message:o,type:s},c={_getName(){return i},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let r={message:typeof o=="function"?o(t):o};return {success:false,error:r,errors:[r]}},parse(t,n){let a=c._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return c._parse(t,n)},transform(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success&&(u.data=t(u.data)),u}),this},optional(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===void 0&&(r.data=void 0,r.success=true),r}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===null&&(r.data=null,r.success=true),r}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n==null&&(r.success=true,r.data=n),r}),this},default(t){return m(this,"_parse",(n,a,r)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,r))),this},catch(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?u:{success:true,data:typeof t=="function"?t({input:a,error:u.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?t._parse(u.data,r):u}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||O(a),s=a),m(this,"_parse",(r,u,f)=>{let l=r(u,f);y(f);if(!l.success)return l;let I=t(l.data);if(I===true||typeof I=="object"&&I?.success===true)return l;let g={message:typeof n=="function"?n(u):n};return {success:false,error:g,errors:[g]}}),this}};return S.length>0?S.reduce((t,n)=>n(t,e,p)??t,c):c}var S=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");S.push(e);}exports.extend=A;exports.hookOriginal=m;exports.s=$;
'use strict';var E={abortEarly:true};function b(e,t){if(!t)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function w(e,t,n){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)t.push(b(e.errors[a],n));}function T(e){return {...E,...e}}var d=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,D=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,t){let n=l(x,{...t,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([p,o])=>`${p}: ${o._getDescription()}`).join(", ")} })`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u={},c=[];for(let i in e){let f=e[i]._parse(r.data[i],o);if(f.success)u[i]=f.data;else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},string(e){return l(d,{...e,type:"string"})},number(e){return l(y,{...e,type:"number"})},boolean(e){return l(g,{...e,type:"boolean"})},date(e){return l(D,{...e,type:"date"})},enum(e,t){let n=r=>e.includes(r),a=r=>`Invalid ${p} value. Expected ${e.map(s=>`"${s}"`).join(" | ")}, received "${r}".`,p="enum",o=l(n,{message:a,...t,type:p});return o._getDescription=()=>`enum(${e.map(r=>`"${r}"`).join(" | ")})`,o},array(e,t){let n=l(_,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u=[],c=[];for(let i=0;i<r.data.length;i++){let f=e._parse(r.data[i],o);if(f.success)u.push(f.data);else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},any(){return l(()=>true)},preprocess(e,t){return h(t,"_parse",(n,a)=>(a=e(a),n(a))),t},union(e,t){return l(o=>{for(let r=0;r<e.length;r++){let s=e[r]._parse(o);if(s.success)return s}return false},{message:o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((r,s)=>` ${s+1}. ${r._getDescription()}`).join(",")} but received "${typeof o}" with value: ${x(o)?JSON.stringify(o):`"${o}"`}`,...t,type:"union"})},literal(e,t){let p=l(o=>o===e,{message:o=>t?.message?typeof t.message=="function"?t.message(o):t.message:`Expected literal value "${e}", received "${o}"`,name:t?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p},coerce:{string(e){return m.preprocess(t=>String(t),m.string(e))},number(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:t}))},boolean(e){return m.preprocess(t=>!!t,m.boolean(e))},date(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:t}))}},cast:{boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||n===1?true:a==="false"||a==="no"||a==="off"||a==="0"||n===0?false:n},m.boolean({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(g(n))return Number(n);if(d(n)){let a=n.trim();if(a==="")return n;let p=Number(a);if(Number.isFinite(p))return p}return n},m.number({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>g(n)||y(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.trim()),y(n)&&Number.isFinite(n)||a?new Date(a??n):n},m.date({...e,message:t}))},json(e,t){let n=t?.message??(a=>`Cannot parse "${a}" as JSON.`);return h(e,"_parse",(a,p)=>{if(d(p))try{p=JSON.parse(p);}catch{let o={message:typeof n=="function"?n(p):n};return {success:false,error:o,errors:[o]}}return a(p)}),e}}};function P(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function h(e,t,n){let a=e[t];e[t]=(...p)=>n(a,...p);}function l(e,{type:t="any",name:n,message:a}={}){a=a||P(t);let p={name:n,message:a,type:t},o={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(r,s){let u=e(r);if(u===true)return {success:true,data:r};if(typeof u=="object"&&u?.success===true)return u;let c={message:typeof a=="function"?a(r):a};return {success:false,error:c,errors:[c]}},parse(r,s){let u=o._parse(r,s);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(r,s){return o._parse(r,s)},transform(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success&&(i.data=r(i.data)),i}),this},optional(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===void 0&&(c.data=void 0,c.success=true),c}),this},nullable(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===null&&(c.data=null,c.success=true),c}),this},nullish(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s==null&&(c.success=true,c.data=s),c}),this},default(r){return h(this,"_parse",(s,u,c)=>(u===void 0&&(u=typeof r=="function"?r():r),s(u,c))),this},catch(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?i:{success:true,data:typeof r=="function"?r({input:u,error:i.error}):r}}),this},pipe(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?r._parse(i.data,c):i}),this},refine(r,{message:s,type:u}={}){return u&&(s=s||P(u),t=u),h(this,"_parse",(c,i,f)=>{let I=c(i,f);T(f);if(!I.success)return I;let S=r(I.data);if(S===true||typeof S=="object"&&S?.success===true)return I;let k={message:typeof s=="function"?s(i):s};return {success:false,error:k,errors:[k]}}),this}};return O.length>0?O.reduce((r,s)=>s(r,e,p)??r,o):o}var O=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}exports.extend=A;exports.hookOriginal=h;exports.s=m;exports.schema=m;

@@ -231,2 +231,109 @@ type ErrorStructure = {

literal<T extends string | number | boolean>(value: T, options?: SchemaInterfaceOptions): LiteralSchemaInterface<T>;
/**
* Coerce schemas that apply a native JS constructor before validation.
* Unlike `s.preprocess`, coerce provides a consistent API for common type
* conversions with clear error messages when coercion produces an invalid result.
*
* @example
* ```typescript
* s.coerce.number().parse('42'); // 42
* s.coerce.string().parse(123); // '123'
* s.coerce.boolean().parse(0); // false
* s.coerce.date().parse('2024-01-01'); // Date object
* ```
*/
coerce: {
/**
* Creates a string schema that coerces input using `String(value)`.
* Always succeeds — `String()` never produces an invalid string.
*/
string(options?: SchemaInterfaceOptions): StringSchemaInterface;
/**
* Creates a number schema that coerces input using `Number(value)`.
* Fails when the result is `NaN` (e.g. `'bad'`, `undefined`, plain objects).
*/
number(options?: SchemaInterfaceOptions): NumberSchemaInterface;
/**
* Creates a boolean schema that coerces input using `Boolean(value)`.
* Always succeeds — `Boolean()` always produces `true` or `false`.
* Note: `Boolean('false')` is `true` because `'false'` is a non-empty string.
*/
boolean(options?: SchemaInterfaceOptions): BooleanSchemaInterface;
/**
* Creates a date schema that coerces input using `new Date(value)`.
* Fails when the result is an invalid Date (e.g. `'garbage'`).
*/
date(options?: SchemaInterfaceOptions): DateSchemaInterface;
};
/**
* Smart cast schemas that apply semantic conversion before validation.
* Unlike `s.coerce` (which uses raw JS constructors), `s.cast` understands
* common programmer-friendly string representations and rejects ambiguous
* inputs such as `null`, `undefined`, and empty strings.
*
* Differences from `s.coerce`:
* - `cast.boolean('false')` → `false` (coerce gives `true` — non-empty string)
* - `cast.boolean('yes'/'no'/'on'/'off')` → `true`/`false` (coerce doesn't understand these)
* - `cast.number(null)` → throws (coerce gives `0`)
* - `cast.number('')` → throws (coerce gives `0`)
* - `cast.string(null)` → throws (coerce gives `'null'`)
* - `cast.date(null)` → throws (coerce gives epoch Date)
*
* @example
* ```typescript
* s.cast.boolean().parse('false'); // false — unlike coerce!
* s.cast.boolean().parse('yes'); // true
* s.cast.boolean().parse('on'); // true
* s.cast.number().parse(' 42 '); // 42 — trims whitespace
* s.cast.number().parse(null); // throws
* s.cast.string().parse(123); // '123'
* s.cast.string().parse(null); // throws — unlike coerce!
* s.cast.date().parse('2024-01-01'); // Date object
* s.cast.date().parse(null); // throws — unlike coerce!
* ```
*/
cast: {
/**
* Creates a boolean schema with semantic string casting.
* Recognises (case-insensitive): `'true'/'false'`, `'yes'/'no'`, `'on'/'off'`, `'1'/'0'`.
* Numbers `1` and `0` are accepted; any other number throws.
* `null`, `undefined`, and unrecognised strings throw.
*/
boolean(options?: SchemaInterfaceOptions): BooleanSchemaInterface;
/**
* Creates a number schema with smart string parsing.
* Trims whitespace from strings before converting. Accepts booleans (`true`→1, `false`→0).
* Rejects `null`, `undefined`, empty/whitespace-only strings, and non-numeric strings.
*/
number(options?: SchemaInterfaceOptions): NumberSchemaInterface;
/**
* Creates a string schema that accepts strings, finite numbers, and booleans.
* Rejects `null`, `undefined`, objects, arrays, `NaN`, and `Infinity`.
*/
string(options?: SchemaInterfaceOptions): StringSchemaInterface;
/**
* Creates a date schema with controlled casting.
* Accepts ISO date strings (non-empty), finite integer timestamps, and existing Date objects.
* Rejects `null`, `undefined`, booleans, empty strings, and non-finite numbers.
*/
date(options?: SchemaInterfaceOptions): DateSchemaInterface;
/**
* Parses a JSON string and validates the result against the provided schema.
* If the input is not a string, it is passed directly to the inner schema.
* Produces a proper validation failure (never throws) when the JSON is malformed.
*
* @param schema - Schema to validate the parsed value against
* @param options - Optional configuration (name, message)
* @returns The same schema type, with JSON string preprocessing applied
*
* @example
* ```typescript
* const schema = s.cast.json(s.object({ name: s.string() }));
* schema.parse('{"name":"Alice"}'); // { name: 'Alice' }
* schema.parse({ name: 'Alice' }); // { name: 'Alice' } — pass-through
* schema.safeParse('not json'); // { success: false, error: ... }
* ```
*/
json<T extends SchemaType>(schema: T, options?: SchemaInterfaceOptions): T;
};
};

@@ -292,2 +399,2 @@ declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: keyof (SchemaInterface<Input, Output> | SchemaType), action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;

export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s, s as schema };

@@ -231,2 +231,109 @@ type ErrorStructure = {

literal<T extends string | number | boolean>(value: T, options?: SchemaInterfaceOptions): LiteralSchemaInterface<T>;
/**
* Coerce schemas that apply a native JS constructor before validation.
* Unlike `s.preprocess`, coerce provides a consistent API for common type
* conversions with clear error messages when coercion produces an invalid result.
*
* @example
* ```typescript
* s.coerce.number().parse('42'); // 42
* s.coerce.string().parse(123); // '123'
* s.coerce.boolean().parse(0); // false
* s.coerce.date().parse('2024-01-01'); // Date object
* ```
*/
coerce: {
/**
* Creates a string schema that coerces input using `String(value)`.
* Always succeeds — `String()` never produces an invalid string.
*/
string(options?: SchemaInterfaceOptions): StringSchemaInterface;
/**
* Creates a number schema that coerces input using `Number(value)`.
* Fails when the result is `NaN` (e.g. `'bad'`, `undefined`, plain objects).
*/
number(options?: SchemaInterfaceOptions): NumberSchemaInterface;
/**
* Creates a boolean schema that coerces input using `Boolean(value)`.
* Always succeeds — `Boolean()` always produces `true` or `false`.
* Note: `Boolean('false')` is `true` because `'false'` is a non-empty string.
*/
boolean(options?: SchemaInterfaceOptions): BooleanSchemaInterface;
/**
* Creates a date schema that coerces input using `new Date(value)`.
* Fails when the result is an invalid Date (e.g. `'garbage'`).
*/
date(options?: SchemaInterfaceOptions): DateSchemaInterface;
};
/**
* Smart cast schemas that apply semantic conversion before validation.
* Unlike `s.coerce` (which uses raw JS constructors), `s.cast` understands
* common programmer-friendly string representations and rejects ambiguous
* inputs such as `null`, `undefined`, and empty strings.
*
* Differences from `s.coerce`:
* - `cast.boolean('false')` → `false` (coerce gives `true` — non-empty string)
* - `cast.boolean('yes'/'no'/'on'/'off')` → `true`/`false` (coerce doesn't understand these)
* - `cast.number(null)` → throws (coerce gives `0`)
* - `cast.number('')` → throws (coerce gives `0`)
* - `cast.string(null)` → throws (coerce gives `'null'`)
* - `cast.date(null)` → throws (coerce gives epoch Date)
*
* @example
* ```typescript
* s.cast.boolean().parse('false'); // false — unlike coerce!
* s.cast.boolean().parse('yes'); // true
* s.cast.boolean().parse('on'); // true
* s.cast.number().parse(' 42 '); // 42 — trims whitespace
* s.cast.number().parse(null); // throws
* s.cast.string().parse(123); // '123'
* s.cast.string().parse(null); // throws — unlike coerce!
* s.cast.date().parse('2024-01-01'); // Date object
* s.cast.date().parse(null); // throws — unlike coerce!
* ```
*/
cast: {
/**
* Creates a boolean schema with semantic string casting.
* Recognises (case-insensitive): `'true'/'false'`, `'yes'/'no'`, `'on'/'off'`, `'1'/'0'`.
* Numbers `1` and `0` are accepted; any other number throws.
* `null`, `undefined`, and unrecognised strings throw.
*/
boolean(options?: SchemaInterfaceOptions): BooleanSchemaInterface;
/**
* Creates a number schema with smart string parsing.
* Trims whitespace from strings before converting. Accepts booleans (`true`→1, `false`→0).
* Rejects `null`, `undefined`, empty/whitespace-only strings, and non-numeric strings.
*/
number(options?: SchemaInterfaceOptions): NumberSchemaInterface;
/**
* Creates a string schema that accepts strings, finite numbers, and booleans.
* Rejects `null`, `undefined`, objects, arrays, `NaN`, and `Infinity`.
*/
string(options?: SchemaInterfaceOptions): StringSchemaInterface;
/**
* Creates a date schema with controlled casting.
* Accepts ISO date strings (non-empty), finite integer timestamps, and existing Date objects.
* Rejects `null`, `undefined`, booleans, empty strings, and non-finite numbers.
*/
date(options?: SchemaInterfaceOptions): DateSchemaInterface;
/**
* Parses a JSON string and validates the result against the provided schema.
* If the input is not a string, it is passed directly to the inner schema.
* Produces a proper validation failure (never throws) when the JSON is malformed.
*
* @param schema - Schema to validate the parsed value against
* @param options - Optional configuration (name, message)
* @returns The same schema type, with JSON string preprocessing applied
*
* @example
* ```typescript
* const schema = s.cast.json(s.object({ name: s.string() }));
* schema.parse('{"name":"Alice"}'); // { name: 'Alice' }
* schema.parse({ name: 'Alice' }); // { name: 'Alice' } — pass-through
* schema.safeParse('not json'); // { success: false, error: ... }
* ```
*/
json<T extends SchemaType>(schema: T, options?: SchemaInterfaceOptions): T;
};
};

@@ -292,2 +399,2 @@ declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: keyof (SchemaInterface<Input, Output> | SchemaType), action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;

export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s, s as schema };

@@ -1,1 +0,1 @@

export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';

@@ -1,1 +0,1 @@

'use strict';var k={abortEarly:true};function S(e,u){if(!u)return e;let p=e?.cause?.key?`${u}.${e.cause.key}`:`${u}`;return {message:`Error parsing key "${p}": ${e.message}`,cause:{key:p}}}function g(e,u,p){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)u.push(S(e.errors[o],p));}function d(e){return {...k,...e}}var w=e=>typeof e=="string"||e instanceof String,P=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),N=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,u){let p=l(O,{...u,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(e).map(([c,n])=>`${c}: ${n._getDescription()}`).join(", ")} })`,m(p,"_parse",(o,c,n)=>{let t=o(c,n),{abortEarly:r}=d(n);if(t.success===false)return t;let s={},a=[];for(let i in e){let f=e[i]._parse(t.data[i],n);if(f.success)s[i]=f.data;else {if(f=f,r!==false){let h=S(f.error,i);return {success:false,error:h,errors:[h]}}g(f,a,i);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),p},string(e){return l(w,{...e,type:"string"})},number(e){return l(P,{...e,type:"number"})},boolean(e){return l(N,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,u){let p=t=>e.includes(t),o=t=>`Invalid ${c} value. Expected ${e.map(r=>`"${r}"`).join(" | ")}, received "${t}".`,c="enum",n=l(p,{message:o,...u,type:c});return n._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,n},array(e,u){let p=l(_,{...u,type:"array"});return p._getDescription=()=>`array(${e._getDescription()})`,m(p,"_parse",(o,c,n)=>{let t=o(c,n),{abortEarly:r}=d(n);if(t.success===false)return t;let s=[],a=[];for(let i=0;i<t.data.length;i++){let f=e._parse(t.data[i],n);if(f.success)s.push(f.data);else {if(f=f,r!==false){let h=S(f.error,i);return {success:false,error:h,errors:[h]}}g(f,a,i);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),p},any(){return l(()=>true)},preprocess(e,u){return m(u,"_parse",(p,o)=>(o=e(o),p(o))),u},union(e,u){return l(n=>{for(let t=0;t<e.length;t++){let r=e[t]._parse(n);if(r.success)return r}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,r)=>` ${r+1}. ${t._getDescription()}`).join(",")} but received "${typeof n}" with value: ${O(n)?JSON.stringify(n):`"${n}"`}`,...u,type:"union"})},literal(e,u){let c=l(n=>n===e,{message:n=>u?.message?typeof u.message=="function"?u.message(n):u.message:`Expected literal value "${e}", received "${n}"`,name:u?.name,type:"literal"});return c._getDescription=()=>`literal("${e}")`,c}};function T(e){return u=>`The value "${u}" must be type of ${e} but is type of "${typeof u}".`}function m(e,u,p){let o=e[u];e[u]=(...c)=>p(o,...c);}function l(e,{type:u="any",name:p,message:o}={}){o=o||T(u);let c={name:p,message:o,type:u},n={_getName(){return p},_getType(){return u},_getDescription(){return this._getName()??this._getType()},_parse(t,r){let s=e(t);if(s===true)return {success:true,data:t};if(typeof s=="object"&&s?.success===true)return s;let a={message:typeof o=="function"?o(t):o};return {success:false,error:a,errors:[a]}},parse(t,r){let s=n._parse(t,r);if(!s.success)throw s=s,new Error(s.error.message,{cause:s.error.cause});return s.data},safeParse(t,r){return n._parse(t,r)},transform(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success&&(i.data=t(i.data)),i}),this},optional(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r===void 0&&(a.data=void 0,a.success=true),a}),this},nullable(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r===null&&(a.data=null,a.success=true),a}),this},nullish(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r==null&&(a.success=true,a.data=r),a}),this},default(t){return m(this,"_parse",(r,s,a)=>(s===void 0&&(s=typeof t=="function"?t():t),r(s,a))),this},catch(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success?i:{success:true,data:typeof t=="function"?t({input:s,error:i.error}):t}}),this},pipe(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success?t._parse(i.data,a):i}),this},refine(t,{message:r,type:s}={}){return s&&(r=r||T(s),u=s),m(this,"_parse",(a,i,f)=>{let h=a(i,f);d(f);if(!h.success)return h;let I=t(h.data);if(I===true||typeof I=="object"&&I?.success===true)return h;let b={message:typeof r=="function"?r(i):r};return {success:false,error:b,errors:[b]}}),this}};return y.length>0?y.reduce((t,r)=>r(t,e,c)??t,n):n}var y=[];function x(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");y.push(e);}x((e,u,p)=>{if(p?.type==="number"){let o=e;o.min=function(c,{message:n}={}){return this.refine(t=>t>=c,{message:n||`Number must be greater than or equal to ${c}.`})},o.max=function(c,{message:n}={}){return this.refine(t=>t<=c,{message:n||`Number must be less than or equal to ${c}.`})},o.positive=function({message:c}={}){return this.refine(n=>n>0,{message:c||"Number must be positive."})},o.negative=function({message:c}={}){return this.refine(n=>n<0,{message:c||"Number must be negative."})},o.int=function({message:c}={}){return this.refine(n=>Number.isInteger(n),{message:c||"Number must be an integer."})},o.float=function({message:c}={}){return this.refine(n=>Number.isFinite(n)&&!Number.isInteger(n),{message:c||"Number must be a floating point (non-integer)."})},o.multipleOf=function(c,{message:n}={}){return this.refine(t=>t%c===0,{message:n||`Number must be a multiple of ${c}.`})},o.finite=function({message:c}={}){return this.refine(n=>Number.isFinite(n),{message:c||"Number must be finite."})};}return e});exports.extend=x;exports.hookOriginal=m;exports.s=R;
'use strict';var E={abortEarly:true};function g(e,a){if(!a)return e;let n=e?.cause?.key?`${a}.${e.cause.key}`:`${a}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function w(e,a,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)a.push(g(e.errors[r],n));}function O(e){return {...E,...e}}var l=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),b=e=>e===true||e===false,$=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),f={object(e,a){let n=S(x,{...a,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([c,s])=>`${c}: ${s._getDescription()}`).join(", ")} })`,h(n,"_parse",(r,c,s)=>{let t=r(c,s),{abortEarly:u}=O(s);if(t.success===false)return t;let i={},o=[];for(let m in e){let p=e[m]._parse(t.data[m],s);if(p.success)i[m]=p.data;else {if(p=p,u!==false){let I=g(p.error,m);return {success:false,error:I,errors:[I]}}w(p,o,m);}}return o.length>0?{success:false,error:o[0],errors:o}:{success:true,data:i}}),n},string(e){return S(l,{...e,type:"string"})},number(e){return S(y,{...e,type:"number"})},boolean(e){return S(b,{...e,type:"boolean"})},date(e){return S($,{...e,type:"date"})},enum(e,a){let n=t=>e.includes(t),r=t=>`Invalid ${c} value. Expected ${e.map(u=>`"${u}"`).join(" | ")}, received "${t}".`,c="enum",s=S(n,{message:r,...a,type:c});return s._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,s},array(e,a){let n=S(_,{...a,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(r,c,s)=>{let t=r(c,s),{abortEarly:u}=O(s);if(t.success===false)return t;let i=[],o=[];for(let m=0;m<t.data.length;m++){let p=e._parse(t.data[m],s);if(p.success)i.push(p.data);else {if(p=p,u!==false){let I=g(p.error,m);return {success:false,error:I,errors:[I]}}w(p,o,m);}}return o.length>0?{success:false,error:o[0],errors:o}:{success:true,data:i}}),n},any(){return S(()=>true)},preprocess(e,a){return h(a,"_parse",(n,r)=>(r=e(r),n(r))),a},union(e,a){return S(s=>{for(let t=0;t<e.length;t++){let u=e[t]._parse(s);if(u.success)return u}return false},{message:s=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,u)=>` ${u+1}. ${t._getDescription()}`).join(",")} but received "${typeof s}" with value: ${x(s)?JSON.stringify(s):`"${s}"`}`,...a,type:"union"})},literal(e,a){let c=S(s=>s===e,{message:s=>a?.message?typeof a.message=="function"?a.message(s):a.message:`Expected literal value "${e}", received "${s}"`,name:a?.name,type:"literal"});return c._getDescription=()=>`literal("${e}")`,c},coerce:{string(e){return f.preprocess(a=>String(a),f.string(e))},number(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return f.preprocess(n=>Number(n),f.number({...e,message:a}))},boolean(e){return f.preprocess(a=>!!a,f.boolean(e))},date(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return f.preprocess(n=>new Date(n),f.date({...e,message:a}))}},cast:{boolean(e){let a=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return f.preprocess(n=>{let r;return l(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},f.boolean({...e,message:a}))},number(e){let a=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return f.preprocess(n=>{if(b(n))return Number(n);if(l(n)){let r=n.trim();if(r==="")return n;let c=Number(r);if(Number.isFinite(c))return c}return n},f.number({...e,message:a}))},string(e){let a=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return f.preprocess(n=>b(n)||y(n)&&Number.isFinite(n)?String(n):n,f.string({...e,message:a}))},date(e){let a=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return f.preprocess(n=>{let r;return l(n)&&(r=n.trim()),y(n)&&Number.isFinite(n)||r?new Date(r??n):n},f.date({...e,message:a}))},json(e,a){let n=a?.message??(r=>`Cannot parse "${r}" as JSON.`);return h(e,"_parse",(r,c)=>{if(l(c))try{c=JSON.parse(c);}catch{let s={message:typeof n=="function"?n(c):n};return {success:false,error:s,errors:[s]}}return r(c)}),e}}};function N(e){return a=>`The value "${a}" must be type of ${e} but is type of "${typeof a}".`}function h(e,a,n){let r=e[a];e[a]=(...c)=>n(r,...c);}function S(e,{type:a="any",name:n,message:r}={}){r=r||N(a);let c={name:n,message:r,type:a},s={_getName(){return n},_getType(){return a},_getDescription(){return this._getName()??this._getType()},_parse(t,u){let i=e(t);if(i===true)return {success:true,data:t};if(typeof i=="object"&&i?.success===true)return i;let o={message:typeof r=="function"?r(t):r};return {success:false,error:o,errors:[o]}},parse(t,u){let i=s._parse(t,u);if(!i.success)throw i=i,new Error(i.error.message,{cause:i.error.cause});return i.data},safeParse(t,u){return s._parse(t,u)},transform(t){return h(this,"_parse",(u,i,o)=>{let m=u(i,o);return m.success&&(m.data=t(m.data)),m}),this},optional(){return h(this,"_parse",(t,u,i)=>{let o=t(u,i);return !o.success&&u===void 0&&(o.data=void 0,o.success=true),o}),this},nullable(){return h(this,"_parse",(t,u,i)=>{let o=t(u,i);return !o.success&&u===null&&(o.data=null,o.success=true),o}),this},nullish(){return h(this,"_parse",(t,u,i)=>{let o=t(u,i);return !o.success&&u==null&&(o.success=true,o.data=u),o}),this},default(t){return h(this,"_parse",(u,i,o)=>(i===void 0&&(i=typeof t=="function"?t():t),u(i,o))),this},catch(t){return h(this,"_parse",(u,i,o)=>{let m=u(i,o);return m.success?m:{success:true,data:typeof t=="function"?t({input:i,error:m.error}):t}}),this},pipe(t){return h(this,"_parse",(u,i,o)=>{let m=u(i,o);return m.success?t._parse(m.data,o):m}),this},refine(t,{message:u,type:i}={}){return i&&(u=u||N(i),a=i),h(this,"_parse",(o,m,p)=>{let I=o(m,p);O(p);if(!I.success)return I;let d=t(I.data);if(d===true||typeof d=="object"&&d?.success===true)return I;let k={message:typeof u=="function"?u(m):u};return {success:false,error:k,errors:[k]}}),this}};return T.length>0?T.reduce((t,u)=>u(t,e,c)??t,s):s}var T=[];function P(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");T.push(e);}P((e,a,n)=>{if(n?.type==="number"){let r=e;r.min=function(c,{message:s}={}){return this.refine(t=>t>=c,{message:s||`Number must be greater than or equal to ${c}.`})},r.max=function(c,{message:s}={}){return this.refine(t=>t<=c,{message:s||`Number must be less than or equal to ${c}.`})},r.positive=function({message:c}={}){return this.refine(s=>s>0,{message:c||"Number must be positive."})},r.negative=function({message:c}={}){return this.refine(s=>s<0,{message:c||"Number must be negative."})},r.int=function({message:c}={}){return this.refine(s=>Number.isInteger(s),{message:c||"Number must be an integer."})},r.float=function({message:c}={}){return this.refine(s=>Number.isFinite(s)&&!Number.isInteger(s),{message:c||"Number must be a floating point (non-integer)."})},r.multipleOf=function(c,{message:s}={}){return this.refine(t=>t%c===0,{message:s||`Number must be a multiple of ${c}.`})},r.finite=function({message:c}={}){return this.refine(s=>Number.isFinite(s),{message:c||"Number must be finite."})};}return e});exports.extend=P;exports.hookOriginal=h;exports.s=f;exports.schema=f;

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,1 +0,1 @@

import'./chunk-PH4B25KI.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
import'./chunk-3C2I2ZOZ.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';

@@ -1,1 +0,1 @@

'use strict';var k={abortEarly:true};function I(t,o){if(!o)return t;let p=t?.cause?.key?`${o}.${t.cause.key}`:`${o}`;return {message:`Error parsing key "${p}": ${t.message}`,cause:{key:p}}}function O(t,o,p){if(t.errors?.length)for(let s=0;s<t.errors.length;s++)o.push(I(t.errors[s],p));}function d(t){return {...k,...t}}var w=t=>typeof t=="string"||t instanceof String,P=t=>(typeof t=="number"||t instanceof Number)&&!Number.isNaN(t),E=t=>t===true||t===false,$=t=>t instanceof Date&&!Number.isNaN(t.getTime()),_=t=>Array.isArray(t),b=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),A={object(t,o){let p=l(b,{...o,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(t).map(([r,n])=>`${r}: ${n._getDescription()}`).join(", ")} })`,m(p,"_parse",(s,r,n)=>{let e=s(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u={},c=[];for(let i in t){let f=t[i]._parse(e.data[i],n);if(f.success)u[i]=f.data;else {if(f=f,a!==false){let h=I(f.error,i);return {success:false,error:h,errors:[h]}}O(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),p},string(t){return l(w,{...t,type:"string"})},number(t){return l(P,{...t,type:"number"})},boolean(t){return l(E,{...t,type:"boolean"})},date(t){return l($,{...t,type:"date"})},enum(t,o){let p=e=>t.includes(e),s=e=>`Invalid ${r} value. Expected ${t.map(a=>`"${a}"`).join(" | ")}, received "${e}".`,r="enum",n=l(p,{message:s,...o,type:r});return n._getDescription=()=>`enum(${t.map(e=>`"${e}"`).join(" | ")})`,n},array(t,o){let p=l(_,{...o,type:"array"});return p._getDescription=()=>`array(${t._getDescription()})`,m(p,"_parse",(s,r,n)=>{let e=s(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u=[],c=[];for(let i=0;i<e.data.length;i++){let f=t._parse(e.data[i],n);if(f.success)u.push(f.data);else {if(f=f,a!==false){let h=I(f.error,i);return {success:false,error:h,errors:[h]}}O(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),p},any(){return l(()=>true)},preprocess(t,o){return m(o,"_parse",(p,s)=>(s=t(s),p(s))),o},union(t,o){return l(n=>{for(let e=0;e<t.length;e++){let a=t[e]._parse(n);if(a.success)return a}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${t.map((e,a)=>` ${a+1}. ${e._getDescription()}`).join(",")} but received "${typeof n}" with value: ${b(n)?JSON.stringify(n):`"${n}"`}`,...o,type:"union"})},literal(t,o){let r=l(n=>n===t,{message:n=>o?.message?typeof o.message=="function"?o.message(n):o.message:`Expected literal value "${t}", received "${n}"`,name:o?.name,type:"literal"});return r._getDescription=()=>`literal("${t}")`,r}};function T(t){return o=>`The value "${o}" must be type of ${t} but is type of "${typeof o}".`}function m(t,o,p){let s=t[o];t[o]=(...r)=>p(s,...r);}function l(t,{type:o="any",name:p,message:s}={}){s=s||T(o);let r={name:p,message:s,type:o},n={_getName(){return p},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(e,a){let u=t(e);if(u===true)return {success:true,data:e};if(typeof u=="object"&&u?.success===true)return u;let c={message:typeof s=="function"?s(e):s};return {success:false,error:c,errors:[c]}},parse(e,a){let u=n._parse(e,a);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(e,a){return n._parse(e,a)},transform(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success&&(i.data=e(i.data)),i}),this},optional(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a===void 0&&(c.data=void 0,c.success=true),c}),this},nullable(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a===null&&(c.data=null,c.success=true),c}),this},nullish(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a==null&&(c.success=true,c.data=a),c}),this},default(e){return m(this,"_parse",(a,u,c)=>(u===void 0&&(u=typeof e=="function"?e():e),a(u,c))),this},catch(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success?i:{success:true,data:typeof e=="function"?e({input:u,error:i.error}):e}}),this},pipe(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success?e._parse(i.data,c):i}),this},refine(e,{message:a,type:u}={}){return u&&(a=a||T(u),o=u),m(this,"_parse",(c,i,f)=>{let h=c(i,f);d(f);if(!h.success)return h;let S=e(h.data);if(S===true||typeof S=="object"&&S?.success===true)return h;let y={message:typeof a=="function"?a(i):a};return {success:false,error:y,errors:[y]}}),this}};return g.length>0?g.reduce((e,a)=>a(e,t,r)??e,n):n}var g=[];function x(t){if(typeof t!="function")throw new TypeError("extend() requires a function argument");g.push(t);}x((t,o,p)=>{if(p?.type==="string"){let s=t;s.min=function(r,{message:n}={}){return this.refine(e=>e.length>=r,{message:n||(e=>`String must be at least ${r} characters long (received ${e.length} characters: "${e}")`)})},s.max=function(r,{message:n}={}){return this.refine(e=>e.length<=r,{message:n||(e=>`String must be at most ${r} characters long (received ${e.length} characters: "${e}")`)})},s.length=function(r,{message:n}={}){return this.refine(e=>e.length===r,{message:n||(e=>`String must be exactly ${r} characters long (received ${e.length} characters: "${e}")`)})},s.nonEmpty=function({message:r}={}){return this.refine(n=>n.length>0,{message:r||"String must not be empty (received empty string)"})},s.startsWith=function(r,{message:n}={}){return this.refine(e=>e.startsWith(r),{message:n||(e=>`String must start with "${r}" (received: "${e}")`)})},s.endsWith=function(r,{message:n}={}){return this.refine(e=>e.endsWith(r),{message:n||(e=>`String must end with "${r}" (received: "${e}")`)})},s.includes=function(r,{message:n}={}){return this.refine(e=>e.includes(r),{message:n||(e=>`String must include "${r}" (received: "${e}")`)})},s.toLowerCase=function(){return this.transform(r=>r.toLowerCase())},s.toUpperCase=function(){return this.transform(r=>r.toUpperCase())},s.trim=function(){return this.transform(r=>r.trim())},s.padStart=function(r,n=" "){return this.transform(e=>e.padStart(r,n))},s.padEnd=function(r,n=" "){return this.transform(e=>e.padEnd(r,n))},s.replace=function(r,n){return this.transform(e=>e.replace(r,n))};}return t});exports.extend=x;exports.hookOriginal=m;exports.s=A;
'use strict';var E={abortEarly:true};function b(e,s){if(!s)return e;let n=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function k(e,s,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)s.push(b(e.errors[r],n));}function O(e){return {...E,...e}}var l=e=>typeof e=="string"||e instanceof String,g=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),y=e=>e===true||e===false,_=e=>e instanceof Date&&!Number.isNaN(e.getTime()),D=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,s){let n=I(x,{...s,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([a,c])=>`${a}: ${c._getDescription()}`).join(", ")} })`,h(n,"_parse",(r,a,c)=>{let t=r(a,c),{abortEarly:o}=O(c);if(t.success===false)return t;let i={},u=[];for(let p in e){let f=e[p]._parse(t.data[p],c);if(f.success)i[p]=f.data;else {if(f=f,o!==false){let S=b(f.error,p);return {success:false,error:S,errors:[S]}}k(f,u,p);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),n},string(e){return I(l,{...e,type:"string"})},number(e){return I(g,{...e,type:"number"})},boolean(e){return I(y,{...e,type:"boolean"})},date(e){return I(_,{...e,type:"date"})},enum(e,s){let n=t=>e.includes(t),r=t=>`Invalid ${a} value. Expected ${e.map(o=>`"${o}"`).join(" | ")}, received "${t}".`,a="enum",c=I(n,{message:r,...s,type:a});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let n=I(D,{...s,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(r,a,c)=>{let t=r(a,c),{abortEarly:o}=O(c);if(t.success===false)return t;let i=[],u=[];for(let p=0;p<t.data.length;p++){let f=e._parse(t.data[p],c);if(f.success)i.push(f.data);else {if(f=f,o!==false){let S=b(f.error,p);return {success:false,error:S,errors:[S]}}k(f,u,p);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),n},any(){return I(()=>true)},preprocess(e,s){return h(s,"_parse",(n,r)=>(r=e(r),n(r))),s},union(e,s){return I(c=>{for(let t=0;t<e.length;t++){let o=e[t]._parse(c);if(o.success)return o}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,o)=>` ${o+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${x(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})},literal(e,s){let a=I(c=>c===e,{message:c=>s?.message?typeof s.message=="function"?s.message(c):s.message:`Expected literal value "${e}", received "${c}"`,name:s?.name,type:"literal"});return a._getDescription=()=>`literal("${e}")`,a},coerce:{string(e){return m.preprocess(s=>String(s),m.string(e))},number(e){let s=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:s}))},boolean(e){return m.preprocess(s=>!!s,m.boolean(e))},date(e){let s=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:s}))}},cast:{boolean(e){let s=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},m.boolean({...e,message:s}))},number(e){let s=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(y(n))return Number(n);if(l(n)){let r=n.trim();if(r==="")return n;let a=Number(r);if(Number.isFinite(a))return a}return n},m.number({...e,message:s}))},string(e){let s=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>y(n)||g(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:s}))},date(e){let s=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.trim()),g(n)&&Number.isFinite(n)||r?new Date(r??n):n},m.date({...e,message:s}))},json(e,s){let n=s?.message??(r=>`Cannot parse "${r}" as JSON.`);return h(e,"_parse",(r,a)=>{if(l(a))try{a=JSON.parse(a);}catch{let c={message:typeof n=="function"?n(a):n};return {success:false,error:c,errors:[c]}}return r(a)}),e}}};function P(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function h(e,s,n){let r=e[s];e[s]=(...a)=>n(r,...a);}function I(e,{type:s="any",name:n,message:r}={}){r=r||P(s);let a={name:n,message:r,type:s},c={_getName(){return n},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,o){let i=e(t);if(i===true)return {success:true,data:t};if(typeof i=="object"&&i?.success===true)return i;let u={message:typeof r=="function"?r(t):r};return {success:false,error:u,errors:[u]}},parse(t,o){let i=c._parse(t,o);if(!i.success)throw i=i,new Error(i.error.message,{cause:i.error.cause});return i.data},safeParse(t,o){return c._parse(t,o)},transform(t){return h(this,"_parse",(o,i,u)=>{let p=o(i,u);return p.success&&(p.data=t(p.data)),p}),this},optional(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===void 0&&(u.data=void 0,u.success=true),u}),this},nullable(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===null&&(u.data=null,u.success=true),u}),this},nullish(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o==null&&(u.success=true,u.data=o),u}),this},default(t){return h(this,"_parse",(o,i,u)=>(i===void 0&&(i=typeof t=="function"?t():t),o(i,u))),this},catch(t){return h(this,"_parse",(o,i,u)=>{let p=o(i,u);return p.success?p:{success:true,data:typeof t=="function"?t({input:i,error:p.error}):t}}),this},pipe(t){return h(this,"_parse",(o,i,u)=>{let p=o(i,u);return p.success?t._parse(p.data,u):p}),this},refine(t,{message:o,type:i}={}){return i&&(o=o||P(i),s=i),h(this,"_parse",(u,p,f)=>{let S=u(p,f);O(f);if(!S.success)return S;let d=t(S.data);if(d===true||typeof d=="object"&&d?.success===true)return S;let w={message:typeof o=="function"?o(p):o};return {success:false,error:w,errors:[w]}}),this}};return T.length>0?T.reduce((t,o)=>o(t,e,a)??t,c):c}var T=[];function $(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");T.push(e);}$((e,s,n)=>{if(n?.type==="string"){let r=e;r.min=function(a,{message:c}={}){return this.refine(t=>t.length>=a,{message:c||(t=>`String must be at least ${a} characters long (received ${t.length} characters: "${t}")`)})},r.max=function(a,{message:c}={}){return this.refine(t=>t.length<=a,{message:c||(t=>`String must be at most ${a} characters long (received ${t.length} characters: "${t}")`)})},r.length=function(a,{message:c}={}){return this.refine(t=>t.length===a,{message:c||(t=>`String must be exactly ${a} characters long (received ${t.length} characters: "${t}")`)})},r.nonEmpty=function({message:a}={}){return this.refine(c=>c.length>0,{message:a||"String must not be empty (received empty string)"})},r.startsWith=function(a,{message:c}={}){return this.refine(t=>t.startsWith(a),{message:c||(t=>`String must start with "${a}" (received: "${t}")`)})},r.endsWith=function(a,{message:c}={}){return this.refine(t=>t.endsWith(a),{message:c||(t=>`String must end with "${a}" (received: "${t}")`)})},r.includes=function(a,{message:c}={}){return this.refine(t=>t.includes(a),{message:c||(t=>`String must include "${a}" (received: "${t}")`)})},r.toLowerCase=function(){return this.transform(a=>a.toLowerCase())},r.toUpperCase=function(){return this.transform(a=>a.toUpperCase())},r.trim=function(){return this.transform(a=>a.trim())},r.padStart=function(a,c=" "){return this.transform(t=>t.padStart(a,c))},r.padEnd=function(a,c=" "){return this.transform(t=>t.padEnd(a,c))},r.replace=function(a,c){return this.transform(t=>t.replace(a,c))};}return e});exports.extend=$;exports.hookOriginal=h;exports.s=m;exports.schema=m;

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,2 +0,2 @@

export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';

@@ -3,0 +3,0 @@ declare module './index.ts' {

@@ -1,1 +0,1 @@

import'./chunk-LZRUIXQL.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
import'./chunk-G6KRMWVT.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';
{
"name": "@esmj/schema",
"version": "0.7.1",
"version": "0.7.2",
"description": "Tiny extendable package for schema validation.",

@@ -5,0 +5,0 @@ "keywords": [

+135
-1

@@ -20,2 +20,4 @@ # Schema

- [Schema Types](#schema-types)
- [s.coerce](#scoerce)
- [s.cast](#scast)
- [Schema Methods](#schema-methods)

@@ -121,3 +123,3 @@ - [parse](#parsevalue-parseoptions)

|-------------------|---------------------------------|
| `@esmj/schema` | `~1.5 KB` |
| `@esmj/schema` | `~1.6 KB` |
| Superstruct | ~3.2 KB |

@@ -447,2 +449,19 @@ | @sinclair/typebox | ~11.7 KB |

### Coerce
- `s.coerce.string()` - Coerce any value to string, then validate
- `s.coerce.number()` - Coerce any value to number, then validate (fails for NaN)
- `s.coerce.boolean()` - Coerce any value to boolean, then validate
- `s.coerce.date()` - Coerce any value to Date, then validate (fails for invalid dates)
### Cast
Semantic casting that understands common string representations and rejects ambiguous inputs:
- `s.cast.boolean()` - Cast to boolean; understands `'true'/'false'`, `'yes'/'no'`, `'on'/'off'`, `'1'/'0'` (case-insensitive); rejects `null`/`undefined`/unrecognised strings
- `s.cast.number()` - Cast to number; trims whitespace from strings, accepts booleans (`true`→1, `false`→0); rejects `null`/`undefined`/empty strings
- `s.cast.string()` - Cast to string; accepts strings, finite numbers, and booleans; rejects `null`/`undefined`/objects/`NaN`/`Infinity`
- `s.cast.date()` - Cast to Date; accepts ISO strings, finite timestamps, and existing Dates; rejects `null`/`undefined`/booleans/empty strings
- `s.cast.json(schema)` - Parse a JSON string and validate the result against a schema; non-string inputs pass through directly; malformed JSON returns a proper validation failure
### Transformations

@@ -736,2 +755,115 @@

#### `s.coerce`
The `coerce` namespace applies a native JS constructor to the input **before** validation.
Unlike `s.preprocess`, you don't need to write the conversion yourself, and coerce methods
provide clear, specific error messages when coercion produces an invalid result.
| Method | Coercion applied | Fails when |
|---|---|---|
| `s.coerce.string(options?)` | `String(v)` | Never — `String()` always succeeds |
| `s.coerce.number(options?)` | `Number(v)` | Result is `NaN` (e.g. `'bad'`, `undefined`) |
| `s.coerce.boolean(options?)` | `Boolean(v)` | Never — `Boolean()` always succeeds |
| `s.coerce.date(options?)` | `new Date(v)` | Result is an invalid Date (e.g. `'garbage'`) |
> **Note:** `Boolean('false')` is `true` because `'false'` is a non-empty string. This matches JavaScript semantics.
```typescript
s.coerce.number().parse('42'); // 42
s.coerce.number().parse(true); // 1
s.coerce.number().parse('bad'); // throws: Cannot coerce "NaN" to a valid number.
s.coerce.string().parse(123); // '123'
s.coerce.string().parse(null); // 'null'
s.coerce.boolean().parse(0); // false
s.coerce.boolean().parse('false'); // true — non-empty string!
s.coerce.date().parse('2024-01-01'); // Date object
s.coerce.date().parse('garbage'); // throws: Cannot coerce "Invalid Date" to a valid date.
// All schema methods chain normally after coerce:
s.coerce.number().refine((v) => v > 0, { message: 'Must be positive' }).parse('5'); // 5
// Custom error message:
s.coerce.number({ message: 'Expected a numeric value' }).parse('bad'); // throws: Expected a numeric value
```
#### `s.cast`
Programmer-friendly semantic casting. Unlike `s.coerce` (raw JS constructors), `s.cast` understands
common string representations and rejects ambiguous inputs like `null`, `undefined`, and empty strings.
| Method | Accepted inputs | Rejects |
|---|---|---|
| `s.cast.string(options?)` | strings, finite numbers, booleans | `null`, `undefined`, objects, `NaN`, `Infinity` |
| `s.cast.number(options?)` | numbers (incl. booleans `true`/`false`→1/0), trimmed numeric strings | `null`, `undefined`, empty strings, non-numeric strings |
| `s.cast.boolean(options?)` | booleans, `1`/`0`, `'true'/'false'`, `'yes'/'no'`, `'on'/'off'`, `'1'/'0'` | `null`, `undefined`, unrecognised strings, other numbers |
| `s.cast.date(options?)` | `Date` objects, ISO strings, finite integer timestamps | `null`, `undefined`, booleans, empty strings, invalid date strings |
| `s.cast.json(schema, options?)` | JSON strings (parsed), any non-string value (pass-through) | malformed JSON strings |
**Key differences from `s.coerce`:**
| Input | `s.coerce.boolean()` | `s.cast.boolean()` |
|---|---|---|
| `'false'` | `true` (non-empty string!) | `false` |
| `'yes'` / `'no'` | `true` / `true` | `true` / `false` |
| `null` | `false` | throws |
| Input | `s.coerce.number()` | `s.cast.number()` |
|---|---|---|
| `null` | `0` | throws |
| `''` | `0` | throws |
| Input | `s.coerce.string()` | `s.cast.string()` |
|---|---|---|
| `null` | `'null'` | throws |
| `undefined` | `'undefined'` | throws |
```typescript
// boolean
s.cast.boolean().parse('false'); // false — unlike coerce!
s.cast.boolean().parse('yes'); // true
s.cast.boolean().parse('on'); // true
s.cast.boolean().parse('OFF'); // false (case-insensitive)
s.cast.boolean().parse(1); // true
s.cast.boolean().parse(0); // false
s.cast.boolean().parse('hello'); // throws: Cannot cast "hello" to boolean...
s.cast.boolean().parse(null); // throws
// number
s.cast.number().parse('42'); // 42
s.cast.number().parse(' 3.14 '); // 3.14 — trims whitespace
s.cast.number().parse(true); // 1
s.cast.number().parse(false); // 0
s.cast.number().parse(null); // throws: Cannot cast "null" to a number...
s.cast.number().parse(''); // throws
// string
s.cast.string().parse(123); // '123'
s.cast.string().parse(true); // 'true'
s.cast.string().parse(false); // 'false'
s.cast.string().parse(null); // throws: Cannot cast "null" to string...
s.cast.string().parse(NaN); // throws
// date
s.cast.date().parse('2024-01-01'); // Date object
s.cast.date().parse(1704067200000); // Date object
s.cast.date().parse(null); // throws: Cannot cast "null" to a valid date.
s.cast.date().parse(true); // throws
// All schema methods chain normally:
s.cast.number().refine((v) => v > 0, { message: 'Must be positive' }).parse('5'); // 5
// Custom error message:
s.cast.boolean({ message: 'Must be a boolean flag' }).parse('maybe'); // throws: Must be a boolean flag
// json
s.cast.json(s.object({ name: s.string() })).parse('{"name":"Alice"}'); // { name: 'Alice' }
s.cast.json(s.array(s.number())).parse('[1,2,3]'); // [1, 2, 3]
s.cast.json(s.object({ name: s.string() })).parse({ name: 'Alice' }); // { name: 'Alice' } — pass-through
s.cast.json(s.number()).safeParse('not json'); // { success: false, error: ... }
s.cast.json(s.number(), { message: 'Invalid JSON' }).parse('bad'); // throws: Invalid JSON
```
### Schema Methods

@@ -1367,2 +1499,4 @@

| Error format | Native Error | Plain object `{ success, error, errors }` |
| Coerce | `z.coerce.number()` | `s.coerce.number()` |
| Smart cast | No direct equivalent | `s.cast.number()` — rejects nulls, understands `'yes'/'no'`, etc. |

@@ -1369,0 +1503,0 @@ **Migration Tips:**

var k={abortEarly:true};function d(e,s){if(!s)return e;let i=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function T(e,s,i){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)s.push(d(e.errors[o],i));}function y(e){return {...k,...e}}var x=e=>typeof e=="string"||e instanceof String,w=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),P=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),b=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$={object(e,s){let i=h(b,{...s,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([p,c])=>`${p}: ${c._getDescription()}`).join(", ")} })`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a={},r=[];for(let u in e){let f=e[u]._parse(t.data[u],c);if(f.success)a[u]=f.data;else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},string(e){return h(x,{...e,type:"string"})},number(e){return h(w,{...e,type:"number"})},boolean(e){return h(P,{...e,type:"boolean"})},date(e){return h(E,{...e,type:"date"})},enum(e,s){let i=t=>e.includes(t),o=t=>`Invalid ${p} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,p="enum",c=h(i,{message:o,...s,type:p});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let i=h(_,{...s,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a=[],r=[];for(let u=0;u<t.data.length;u++){let f=e._parse(t.data[u],c);if(f.success)a.push(f.data);else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},any(){return h(()=>true)},preprocess(e,s){return m(s,"_parse",(i,o)=>(o=e(o),i(o))),s},union(e,s){return h(c=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(c);if(n.success)return n}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${b(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})},literal(e,s){let p=h(c=>c===e,{message:c=>s?.message?typeof s.message=="function"?s.message(c):s.message:`Expected literal value "${e}", received "${c}"`,name:s?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function m(e,s,i){let o=e[s];e[s]=(...p)=>i(o,...p);}function h(e,{type:s="any",name:i,message:o}={}){o=o||O(s);let p={name:i,message:o,type:s},c={_getName(){return i},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let r={message:typeof o=="function"?o(t):o};return {success:false,error:r,errors:[r]}},parse(t,n){let a=c._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return c._parse(t,n)},transform(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success&&(u.data=t(u.data)),u}),this},optional(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===void 0&&(r.data=void 0,r.success=true),r}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===null&&(r.data=null,r.success=true),r}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n==null&&(r.success=true,r.data=n),r}),this},default(t){return m(this,"_parse",(n,a,r)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,r))),this},catch(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?u:{success:true,data:typeof t=="function"?t({input:a,error:u.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?t._parse(u.data,r):u}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||O(a),s=a),m(this,"_parse",(r,u,f)=>{let l=r(u,f);y(f);if(!l.success)return l;let I=t(l.data);if(I===true||typeof I=="object"&&I?.success===true)return l;let g={message:typeof n=="function"?n(u):n};return {success:false,error:g,errors:[g]}}),this}};return S.length>0?S.reduce((t,n)=>n(t,e,p)??t,c):c}var S=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");S.push(e);}export{$ as a,m as b,A as c};
import {c}from'./chunk-2NCXW7ID.mjs';c((a,o,m)=>{if(m?.type==="array"){let r=a;r.min=function(e,{message:t}={}){return this.refine(n=>n.length>=e,{message:t||`Array must contain at least ${e} items.`})},r.max=function(e,{message:t}={}){return this.refine(n=>n.length<=e,{message:t||`Array must contain at most ${e} items.`})},r.length=function(e,{message:t}={}){return this.refine(n=>n.length===e,{message:t||`Array must contain exactly ${e} items.`})},r.nonEmpty=function({message:e}={}){return this.refine(t=>t.length>0,{message:e||"Array must not be empty."})},r.unique=function({message:e}={}){return this.refine(t=>{let n=new Set;try{return t.every(c=>{let s=JSON.stringify(c);return n.has(s)?!1:(n.add(s),!0)})}catch{return new Set(t).size===t.length}},{message:e||"Array items must be unique."})},r.sort=function(){return this.transform(e=>[...e].sort())},r.reverse=function(){return this.transform(e=>[...e].reverse())};}return a});
import {c}from'./chunk-2NCXW7ID.mjs';c((i,s,c)=>{if(c?.type==="string"){let r=i;r.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},r.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},r.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},r.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"String must not be empty (received empty string)"})},r.startsWith=function(t,{message:n}={}){return this.refine(e=>e.startsWith(t),{message:n||(e=>`String must start with "${t}" (received: "${e}")`)})},r.endsWith=function(t,{message:n}={}){return this.refine(e=>e.endsWith(t),{message:n||(e=>`String must end with "${t}" (received: "${e}")`)})},r.includes=function(t,{message:n}={}){return this.refine(e=>e.includes(t),{message:n||(e=>`String must include "${t}" (received: "${e}")`)})},r.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},r.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},r.trim=function(){return this.transform(t=>t.trim())},r.padStart=function(t,n=" "){return this.transform(e=>e.padStart(t,n))},r.padEnd=function(t,n=" "){return this.transform(e=>e.padEnd(t,n))},r.replace=function(t,n){return this.transform(e=>e.replace(t,n))};}return i});
import {c}from'./chunk-2NCXW7ID.mjs';c((i,c,m)=>{if(m?.type==="number"){let n=i;n.min=function(e,{message:t}={}){return this.refine(r=>r>=e,{message:t||`Number must be greater than or equal to ${e}.`})},n.max=function(e,{message:t}={}){return this.refine(r=>r<=e,{message:t||`Number must be less than or equal to ${e}.`})},n.positive=function({message:e}={}){return this.refine(t=>t>0,{message:e||"Number must be positive."})},n.negative=function({message:e}={}){return this.refine(t=>t<0,{message:e||"Number must be negative."})},n.int=function({message:e}={}){return this.refine(t=>Number.isInteger(t),{message:e||"Number must be an integer."})},n.float=function({message:e}={}){return this.refine(t=>Number.isFinite(t)&&!Number.isInteger(t),{message:e||"Number must be a floating point (non-integer)."})},n.multipleOf=function(e,{message:t}={}){return this.refine(r=>r%e===0,{message:t||`Number must be a multiple of ${e}.`})},n.finite=function({message:e}={}){return this.refine(t=>Number.isFinite(t),{message:e||"Number must be finite."})};}return i});