runcheck 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var a in r)c(e,a,{get:r[a],enumerable:!0})},R=(e,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==a&&c(e,n,{get:()=>r[n],enumerable:!(i=f(r,n))||i.enumerable});return e};var _=e=>R(c({},"__esModule",{value:!0}),e);var S={};p(S,{rc_boolean_autofix:()=>k,rc_number_autofix:()=>A,rc_string_autofix:()=>O});module.exports=_(S);function h(e){return{...this,a:e}}function s(e,r,a,i){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let t=n===!0?r:n.data;return e.t&&!e.t(t)?[!1,[e.n(t)]]:[!0,t]}if(e.a!==void 0)return a.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let t=e.i(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(a.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function x(e){return{...this,y:!0,i:e}}function b(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,c:!0}}function w(e){return`Type '${j(e)}' is not assignable to '${this.e}'`}function m(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function $(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:h,where:b,optional:g,n:w,nullable:m,withAutofix:x,nullish:$},P={...o,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},V={...o,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},q={...o,r(e,r){return s(this,e,r,()=>!0)},e:"any"},E={...o,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},u={...o,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...o,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},y={...o,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},I={...o,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var k=u.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),O=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),A=y.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
1
+ "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var a in r)c(e,a,{get:r[a],enumerable:!0})},R=(e,r,a,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==a&&c(e,n,{get:()=>r[n],enumerable:!(i=f(r,n))||i.enumerable});return e};var _=e=>R(c({},"__esModule",{value:!0}),e);var S={};p(S,{rc_boolean_autofix:()=>k,rc_number_autofix:()=>A,rc_string_autofix:()=>O});module.exports=_(S);function h(e){return{...this,a:e}}function s(e,r,a,i){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let t=n===!0?r:n.data;return e.t&&!e.t(t)?[!1,[e.n(t)]]:[!0,t]}if(e.a!==void 0)return a.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let t=e.i(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(a.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function x(e){return{...this,y:!0,i:e}}function b(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,c:!0}}function w(e){return`Type '${j(e)}' is not assignable to '${this.e}'`}function m(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function $(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:h,where:b,optional:g,n:w,nullable:m,withAutofix:x,nullish:$},P={...o,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},V={...o,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},I={...o,r(e,r){return s(this,e,r,()=>!0)},e:"any"},q={...o,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},u={...o,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...o,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},y={...o,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},E={...o,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var k=u.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),O=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),A=y.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
@@ -1 +1 @@
1
- import{e as f,f as t,g as o}from"./chunk-7DLJSWI7.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
1
+ import{e as f,f as t,g as o}from"./chunk-KIM2UT5Z.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
@@ -0,0 +1 @@
1
+ function A(e){return{...this,a:e}}function i(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let a=t();if(a&&(a===!0||"data"in a)){let s=a===!0?r:a.data;return e.t&&!e.t(s)?[!1,[e.n(s)]]:[!0,s]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let s=e.i(r);if(s)return e.t&&!e.t(s.fixed)?[!1,[e.n(s.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,s.fixed])}return[!1,a&&"errors"in a?a.errors:[e.n(r)]]}function S(e){return{...this,y:!0,i:e}}function P(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function V(){return{...this,c:!0}}function I(e){return`Type '${k(e)}' is not assignable to '${this.e}'`}function q(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function E(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:A,where:P,optional:V,n:I,nullable:q,withAutofix:S,nullish:E},v={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},K={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},F={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},C={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},U={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},z={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},B={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},D={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function M(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function W(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${k(e[0])}_literal`:"literals"}}function G(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function H(e,r){return{...r,o:e}}function R(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),a=n.slice(1);return`$${r}${a}: ${t}`}return`$${r}: ${e}`}function w(e){return{...o,s:e,e:"object",f:!0,r(r,n){return i(this,r,n,()=>{if(!m(r))return!1;let t=new Set(Object.keys(r)),a={},s=[];for(let[c,u]of Object.entries(e)){let p=c,l,y=c;u.o?(l=r[u.o],y=u.o,l===void 0&&(l=r[c],y=c)):l=r[c],t.delete(y);let[T,h]=u.r(l,n);if(T)a[p]=h;else{let _=h;for(let d of _)s.push(R(d,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)s.push(`Key '${c}' is not defined in the object shape`);return s.length>0?{errors:s}:{data:a}})}}}function J(e){return{...w(e),e:"strict_obj"}}function L(e,r){return w({...e.s,...r.s})}function Q(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!m(r))return!1;let t={},a=[];for(let[s,c]of Object.entries(r)){let u=r[s],[p,l]=e.r(c,n);if(p)t[s]=u;else{let y=l;for(let T of y)a.push(R(T,`.${s}`))}}return a.length>0?{errors:a}:{data:t}})}}}function $(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function b(e,r,n,t=!1,a){let s=-1,c=[],u=[],p=new Set;for(let l of e){s++;let y=Array.isArray(r)?r[s]:r,T=y.r(l,n),[h,_]=T,d=a?.unique;if(h&&d){let f=_,x=typeof d=="string";x&&(f=_[d]),p.has(f)?T=[!1,[x?R(`Type '${y.s?.[d]?.e}' with value "${f}" is not unique`,`.${d}`):`${y.e} value is not unique`]]:p.add(f)}let[O,g]=T;if(O)u.push(g);else if(t){c.push(g.map(f=>R(f,`[${s}]`)));continue}else return{errors:g.map(f=>R(f,`[${s}]`))}}if(c.length>0){if(u.length===0)return{errors:c.slice(0,5).flat()};n.warnings.push(...c.flat())}return{data:u}}function X(e,r){return $(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:b.call(this,n,e,t,!1,r):!1)}}}function Y(e,r){return $(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:b.call(this,n,e,t,!0,r):!1)}}}function Z(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:b.call(this,r,e,n))}}}function j(e,r){let n={warnings:[]},[t,a]=r.r(e,n);return t?{error:!1,data:a,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:a}}function ee(e){return r=>j(r,e)}function re(e,r){let n=j(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function N(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ne(e){return r=>N(r,e)}function te(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function se(e,r){return{...o,e:e.e,r(n,t){let[a,s]=e.r(n,t);return a?[!0,r(s)]:[!1,s]}}}function k(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{v as a,K as b,F as c,C as d,U as e,z as f,B as g,D as h,M as i,W as j,G as k,H as l,w as m,J as n,L as o,Q as p,X as q,Y as r,Z as s,j as t,ee as u,re as v,N as w,ne as x,te as y,se as z};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var q=(e,r)=>{for(var n in r)g(e,n,{get:r[n],enumerable:!0})},E=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of P(r))!V.call(e,t)&&t!==n&&g(e,t,{get:()=>r[t],enumerable:!(s=S(r,t))||s.enumerable});return e};var I=e=>E(g({},"__esModule",{value:!0}),e);var ye={};q(ye,{rc_any:()=>M,rc_array:()=>te,rc_boolean:()=>G,rc_date:()=>L,rc_instanceof:()=>Q,rc_is_valid:()=>O,rc_literals:()=>X,rc_loose_array:()=>se,rc_loose_parse:()=>ie,rc_null:()=>D,rc_number:()=>J,rc_obj_intersection:()=>re,rc_object:()=>x,rc_parse:()=>$,rc_parser:()=>oe,rc_record:()=>ne,rc_recursive:()=>ue,rc_rename_key:()=>Z,rc_strict_obj:()=>ee,rc_string:()=>H,rc_transform:()=>le,rc_tuple:()=>ae,rc_undefined:()=>B,rc_union:()=>Y,rc_unknown:()=>W,rc_validator:()=>ce});module.exports=I(ye);function N(e){return{...this,o:e}}function i(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let a=t===!0?r:t.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.y&&e.i){let a=e.i(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function v(e){return{...this,y:!0,i:e}}function K(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function F(){return{...this,c:!0}}function C(e){return`Type '${m(e)}' is not assignable to '${this.e}'`}function U(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function z(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:N,where:K,optional:F,n:C,nullable:U,withAutofix:v,nullish:z},B={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},D={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},M={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},W={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},G={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},H={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},J={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},L={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function Q(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function X(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${m(e[0])}_literal`:"literals"}}function Y(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let s of e)if(s.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function Z(e,r){return{...r,a:e}}function h(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",s]=e.split(": "),t=n.slice(1);return`$${r}${t}: ${s}`}return`$${r}: ${e}`}function x(e){return{...o,s:e,e:"object",f:!0,r(r,n){return i(this,r,n,()=>{if(!A(r))return!1;let s=new Set(Object.keys(r)),t={},a=[];for(let[c,l]of Object.entries(e)){let d=c,u,y=c;l.a?(u=r[l.a],y=l.a,u===void 0&&(u=r[c],y=c)):u=r[c],s.delete(y);let[p,R]=l.r(u,n);if(p)t[d]=R;else{let T=R;for(let _ of T)a.push(h(_,`.${c}`))}}if(this.e==="strict_obj"&&s.size>0)for(let c of s)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:{data:t}})}}}function ee(e){return{...x(e),e:"strict_obj"}}function re(e,r){return x({...e.s,...r.s})}function ne(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!A(r))return!1;let s={},t=[];for(let[a,c]of Object.entries(r)){let l=r[a],[d,u]=e.r(c,n);if(d)s[a]=l;else{let y=u;for(let p of y)t.push(h(p,`.${a}`))}}return t.length>0?{errors:t}:{data:s}})}}}function k(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function w(e,r,n,s=!1,t){let a=-1,c=[],l=new Set;for(let d of e){a++;let u=Array.isArray(r)?r[a]:r,y=u.r(d,n),[p,R]=y,T=t?.unique;if(p&&T){let f=R,j=typeof T=="string";j&&(f=R[T]),l.has(f)?y=[!1,[j?h(`Type '${u.s?.[T]?.e}' with value "${f}" is not unique`,`.${T}`):`${u.e} value is not unique`]]:l.add(f)}let[_,b]=y;if(_)c.push(b);else if(s){n.warnings.push(...b.map(f=>h(f,`[${a}]`)));continue}else return{errors:b.map(f=>h(f,`[${a}]`))}}return{data:c}}function te(e,r){return k(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return i(this,n,s,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,s,!1,r):!1)}}}function se(e,r){return k(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return i(this,n,s,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,s,!0,r):!1)}}}function ae(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:w.call(this,r,e,n))}}}function $(e,r){let n={warnings:[]},[s,t]=r.r(e,n);return s?{error:!1,data:t,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:t}}function oe(e){return r=>$(r,e)}function ie(e,r){let n=$(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function O(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ce(e){return r=>O(r,e)}function ue(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function le(e,r){return{...o,e:e.e,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function m(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function A(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_recursive,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator});
1
+ "use strict";var b=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var q=(e,r)=>{for(var n in r)b(e,n,{get:r[n],enumerable:!0})},E=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of V(r))!I.call(e,t)&&t!==n&&b(e,t,{get:()=>r[t],enumerable:!(s=P(r,t))||s.enumerable});return e};var N=e=>E(b({},"__esModule",{value:!0}),e);var fe={};q(fe,{rc_any:()=>W,rc_array:()=>se,rc_boolean:()=>H,rc_date:()=>Q,rc_instanceof:()=>X,rc_is_valid:()=>m,rc_literals:()=>Y,rc_loose_array:()=>ae,rc_loose_parse:()=>ce,rc_null:()=>M,rc_number:()=>L,rc_obj_intersection:()=>ne,rc_object:()=>x,rc_parse:()=>$,rc_parser:()=>ie,rc_record:()=>te,rc_recursive:()=>le,rc_rename_key:()=>ee,rc_strict_obj:()=>re,rc_string:()=>J,rc_transform:()=>ye,rc_tuple:()=>oe,rc_undefined:()=>D,rc_union:()=>Z,rc_unknown:()=>G,rc_validator:()=>ue});module.exports=N(fe);function v(e){return{...this,o:e}}function i(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let a=t===!0?r:t.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.y&&e.i){let a=e.i(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function K(e){return{...this,y:!0,i:e}}function F(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function C(){return{...this,c:!0}}function U(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function z(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function B(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:v,where:F,optional:C,n:U,nullable:z,withAutofix:K,nullish:B},D={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},M={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},W={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},G={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},H={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},J={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},L={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Q={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function X(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function Y(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${O(e[0])}_literal`:"literals"}}function Z(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let s of e)if(s.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function ee(e,r){return{...r,a:e}}function R(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",s]=e.split(": "),t=n.slice(1);return`$${r}${t}: ${s}`}return`$${r}: ${e}`}function x(e){return{...o,s:e,e:"object",f:!0,r(r,n){return i(this,r,n,()=>{if(!A(r))return!1;let s=new Set(Object.keys(r)),t={},a=[];for(let[c,u]of Object.entries(e)){let p=c,l,y=c;u.a?(l=r[u.a],y=u.a,l===void 0&&(l=r[c],y=c)):l=r[c],s.delete(y);let[T,h]=u.r(l,n);if(T)t[p]=h;else{let _=h;for(let d of _)a.push(R(d,`.${c}`))}}if(this.e==="strict_obj"&&s.size>0)for(let c of s)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:{data:t}})}}}function re(e){return{...x(e),e:"strict_obj"}}function ne(e,r){return x({...e.s,...r.s})}function te(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!A(r))return!1;let s={},t=[];for(let[a,c]of Object.entries(r)){let u=r[a],[p,l]=e.r(c,n);if(p)s[a]=u;else{let y=l;for(let T of y)t.push(R(T,`.${a}`))}}return t.length>0?{errors:t}:{data:s}})}}}function k(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function w(e,r,n,s=!1,t){let a=-1,c=[],u=[],p=new Set;for(let l of e){a++;let y=Array.isArray(r)?r[a]:r,T=y.r(l,n),[h,_]=T,d=t?.unique;if(h&&d){let f=_,j=typeof d=="string";j&&(f=_[d]),p.has(f)?T=[!1,[j?R(`Type '${y.s?.[d]?.e}' with value "${f}" is not unique`,`.${d}`):`${y.e} value is not unique`]]:p.add(f)}let[S,g]=T;if(S)u.push(g);else if(s){c.push(g.map(f=>R(f,`[${a}]`)));continue}else return{errors:g.map(f=>R(f,`[${a}]`))}}if(c.length>0){if(u.length===0)return{errors:c.slice(0,5).flat()};n.warnings.push(...c.flat())}return{data:u}}function se(e,r){return k(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return i(this,n,s,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,s,!1,r):!1)}}}function ae(e,r){return k(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return i(this,n,s,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,s,!0,r):!1)}}}function oe(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:w.call(this,r,e,n))}}}function $(e,r){let n={warnings:[]},[s,t]=r.r(e,n);return s?{error:!1,data:t,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:t}}function ie(e){return r=>$(r,e)}function ce(e,r){let n=$(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function m(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ue(e){return r=>m(r,e)}function le(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function ye(e,r){return{...o,e:e.e,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function A(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_recursive,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator});
@@ -45,6 +45,7 @@ declare function rc_record<V extends RcType<any>>(valueType: V): RcRecordType<V>
45
45
  declare function rc_array<T extends RcType<any>>(type: T, options?: {
46
46
  unique: boolean | string | false;
47
47
  }): RcType<RcInferType<T>[]>;
48
+ /** instead of returning a general erroro, rejects invalid array items and return warnings for these items */
48
49
  declare function rc_loose_array<T extends RcType<any>>(type: T, options?: {
49
50
  unique: boolean | string | false;
50
51
  }): RcType<RcInferType<T>[]>;
@@ -63,7 +64,9 @@ declare function rc_tuple<T extends readonly RcType<any>[]>(types: T): RcType<Ma
63
64
  */
64
65
  declare function rc_parse<S>(input: any, type: RcType<S>): RcParseResult<S>;
65
66
  type RcParser<T> = (input: any) => RcParseResult<T>;
67
+ /** create a reusable parser for a certain type */
66
68
  declare function rc_parser<S>(type: RcType<S>): RcParser<S>;
69
+ /** does the same as `rc_parse` but without requiring to check for errors before using the parsed data */
67
70
  declare function rc_loose_parse<S>(input: any, type: RcType<S>): {
68
71
  data: S | null;
69
72
  errors: string[] | false;
@@ -72,6 +75,7 @@ declare function rc_loose_parse<S>(input: any, type: RcType<S>): {
72
75
  declare function rc_is_valid<S>(input: any, type: RcType<S>): input is S;
73
76
  declare function rc_validator<S>(type: RcType<S>): (input: any) => input is S;
74
77
  declare function rc_recursive(type: () => RcType<any>): RcType<any>;
75
- declare function rc_transform<S, T>(type: RcType<S>, transform: (input: S) => T): RcType<T>;
78
+ /** validate a input or subset of input and transform the valid result */
79
+ declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => Transformed): RcType<Transformed>;
76
80
 
77
81
  export { RcInferType, RcParseResult, RcParser, RcType, rc_any, rc_array, rc_boolean, rc_date, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_null, rc_number, rc_obj_intersection, rc_object, rc_parse, rc_parser, rc_record, rc_recursive, rc_rename_key, rc_strict_obj, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_validator };
package/dist/runcheck.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-7DLJSWI7.js";export{c as rc_any,q as rc_array,e as rc_boolean,h as rc_date,i as rc_instanceof,w as rc_is_valid,j as rc_literals,r as rc_loose_array,v as rc_loose_parse,b as rc_null,g as rc_number,o as rc_obj_intersection,m as rc_object,t as rc_parse,u as rc_parser,p as rc_record,y as rc_recursive,l as rc_rename_key,n as rc_strict_obj,f as rc_string,z as rc_transform,s as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,x as rc_validator};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-KIM2UT5Z.js";export{c as rc_any,q as rc_array,e as rc_boolean,h as rc_date,i as rc_instanceof,w as rc_is_valid,j as rc_literals,r as rc_loose_array,v as rc_loose_parse,b as rc_null,g as rc_number,o as rc_obj_intersection,m as rc_object,t as rc_parse,u as rc_parser,p as rc_record,y as rc_recursive,l as rc_rename_key,n as rc_strict_obj,f as rc_string,z as rc_transform,s as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,x as rc_validator};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "runcheck",
3
3
  "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
- "version": "0.14.1",
4
+ "version": "0.15.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",
@@ -1 +0,0 @@
1
- function m(e){return{...this,a:e}}function i(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let a=t();if(a&&(a===!0||"data"in a)){let s=a===!0?r:a.data;return e.t&&!e.t(s)?[!1,[e.n(s)]]:[!0,s]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let s=e.i(r);if(s)return e.t&&!e.t(s.fixed)?[!1,[e.n(s.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,s.fixed])}return[!1,a&&"errors"in a?a.errors:[e.n(r)]]}function A(e){return{...this,y:!0,i:e}}function S(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function P(){return{...this,c:!0}}function V(e){return`Type '${k(e)}' is not assignable to '${this.e}'`}function q(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function E(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:m,where:S,optional:P,n:V,nullable:q,withAutofix:A,nullish:E},N={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},v={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},K={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},F={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},C={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},U={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},z={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},B={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function D(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function M(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${k(e[0])}_literal`:"literals"}}function W(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function G(e,r){return{...r,o:e}}function h(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),a=n.slice(1);return`$${r}${a}: ${t}`}return`$${r}: ${e}`}function w(e){return{...o,s:e,e:"object",f:!0,r(r,n){return i(this,r,n,()=>{if(!O(r))return!1;let t=new Set(Object.keys(r)),a={},s=[];for(let[c,l]of Object.entries(e)){let d=c,u,y=c;l.o?(u=r[l.o],y=l.o,u===void 0&&(u=r[c],y=c)):u=r[c],t.delete(y);let[p,R]=l.r(u,n);if(p)a[d]=R;else{let T=R;for(let _ of T)s.push(h(_,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)s.push(`Key '${c}' is not defined in the object shape`);return s.length>0?{errors:s}:{data:a}})}}}function H(e){return{...w(e),e:"strict_obj"}}function J(e,r){return w({...e.s,...r.s})}function L(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!O(r))return!1;let t={},a=[];for(let[s,c]of Object.entries(r)){let l=r[s],[d,u]=e.r(c,n);if(d)t[s]=l;else{let y=u;for(let p of y)a.push(h(p,`.${s}`))}}return a.length>0?{errors:a}:{data:t}})}}}function $(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function g(e,r,n,t=!1,a){let s=-1,c=[],l=new Set;for(let d of e){s++;let u=Array.isArray(r)?r[s]:r,y=u.r(d,n),[p,R]=y,T=a?.unique;if(p&&T){let f=R,x=typeof T=="string";x&&(f=R[T]),l.has(f)?y=[!1,[x?h(`Type '${u.s?.[T]?.e}' with value "${f}" is not unique`,`.${T}`):`${u.e} value is not unique`]]:l.add(f)}let[_,b]=y;if(_)c.push(b);else if(t){n.warnings.push(...b.map(f=>h(f,`[${s}]`)));continue}else return{errors:b.map(f=>h(f,`[${s}]`))}}return{data:c}}function Q(e,r){return $(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:g.call(this,n,e,t,!1,r):!1)}}}function X(e,r){return $(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:g.call(this,n,e,t,!0,r):!1)}}}function Y(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:g.call(this,r,e,n))}}}function j(e,r){let n={warnings:[]},[t,a]=r.r(e,n);return t?{error:!1,data:a,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:a}}function Z(e){return r=>j(r,e)}function ee(e,r){let n=j(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function I(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function re(e){return r=>I(r,e)}function ne(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function te(e,r){return{...o,e:e.e,r(n,t){let[a,s]=e.r(n,t);return a?[!0,r(s)]:[!1,s]}}}function k(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{N as a,v as b,K as c,F as d,C as e,U as f,z as g,B as h,D as i,M as j,W as k,G as l,w as m,H as n,J as o,L as p,Q as q,X as r,Y as s,j as t,Z as u,ee as v,I as w,re as x,ne as y,te as z};