runcheck 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -63,6 +63,16 @@ const shape = rc_obj_intersection(
63
63
  )
64
64
  ```
65
65
 
66
+ ## `rc_record`
67
+
68
+ Validates only the values of a object, equivalent to `Record<string, T>` in typescript.
69
+
70
+ ```ts
71
+ const shape = rc_record(rc_number)
72
+
73
+ // shape type is `Record<string, number>`
74
+ ```
75
+
66
76
  # Parsing
67
77
 
68
78
  ```ts
@@ -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 s in r)c(e,s,{get:r[s],enumerable:!0})},R=(e,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==s&&c(e,n,{get:()=>r[n],enumerable:!(i=f(r,n))||i.enumerable});return e};var _=e=>R(c({},"__esModule",{value:!0}),e);var N={};p(N,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>k,rc_string_autofix:()=>$});module.exports=_(N);function b(e){return{...this,s:e}}function o(e,r,s,i){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&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.s!==void 0)return s.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.l&&e.o){let t=e.o(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(s.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,l:!0,o:e}}function h(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,i:!0}}function j(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function w(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function m(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var a={withFallback:b,where:h,optional:g,n:j,nullable:w,withAutofix:x,nullish:m},P={...a,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},I={...a,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},v={...a,r(e,r){return o(this,e,r,()=>!0)},e:"any"},u={...a,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...a,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},y={...a,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},E={...a,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var A=u.withAutofix(e=>e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),$=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),k=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 i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var s in r)i(e,s,{get:r[s],enumerable:!0})},R=(e,r,s,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==s&&i(e,n,{get:()=>r[n],enumerable:!(c=f(r,n))||c.enumerable});return e};var _=e=>R(i({},"__esModule",{value:!0}),e);var N={};p(N,{rc_boolean_autofix:()=>$,rc_number_autofix:()=>k,rc_string_autofix:()=>A});module.exports=_(N);function x(e){return{...this,s:e}}function o(e,r,s,c){if(e.c&&r===void 0)return[!0,r];if(e.i&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let n=c();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.s!==void 0)return s.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.y&&e.o){let t=e.o(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(s.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function b(e){return{...this,y:!0,o:e}}function h(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,c:!0}}function j(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function w(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function m(){return{...this,i:!0,e:`${this.e}_or_nullish`}}var a={withFallback:x,where:h,optional:g,n:j,nullable:w,withAutofix:b,nullish:m},S={...a,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},V={...a,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},E={...a,r(e,r){return o(this,e,r,()=>!0)},e:"any"},u={...a,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},y={...a,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},l={...a,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},I={...a,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var $=u.withAutofix(e=>e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),A=y.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),k=l.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{d as t,e as f,f as o}from"./chunk-SM23XLSP.js";var s=t.withAutofix(r=>r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),u=f.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),x=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,x as rc_number_autofix,u as rc_string_autofix};
1
+ import{d as t,e as f,f as o}from"./chunk-Y6MMYOJL.js";var s=t.withAutofix(r=>r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),u=f.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),x=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,x as rc_number_autofix,u as rc_string_autofix};
@@ -0,0 +1 @@
1
+ function g(e){return{...this,s:e}}function a(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.i&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[e.n(o)]]:[!0,o]}if(e.s!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.y&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[e.n(o.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function j(e){return{...this,y:!0,o:e}}function O(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function w(){return{...this,c:!0}}function $(e){return`Type '${_(e)}' is not assignable to '${this.e}'`}function m(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function k(){return{...this,i:!0,e:`${this.e}_or_nullish`}}var c={withFallback:g,where:O,optional:w,n:$,nullable:m,withAutofix:j,nullish:k},S={...c,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},V={...c,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},N={...c,r(e,r){return a(this,e,r,()=>!0)},e:"any"},E={...c,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},I={...c,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},K={...c,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},v={...c,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function F(e){return{...c,r(r,n){return a(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function C(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return a(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${_(e[0])}_literal`:"literals"}}function z(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return a(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 d(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",s]=e.split(": "),t=n.slice(1);return`$${r}${t}: ${s}`}return`$${r}: ${e}`}function p(e){return{...c,a:e,e:"object",r(r,n){return a(this,r,n,()=>{if(!h(r))return!1;let s=new Set(Object.keys(r)),t={},o=[];for(let[i,u]of Object.entries(e)){let y=i,l=r[i];s.delete(i);let[f,T]=u.r(l,n);if(f)t[y]=l;else{let b=T;for(let x of b)o.push(d(x,`.${i}`))}}if(this.e==="strict_obj"&&s.size>0)for(let i of s)o.push(`Key '${i}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:r}:{data:t}})}}}function B(e){return{...p(e),e:"extends_object"}}function M(e){return{...p(e),e:"strict_obj"}}function U(e,r){return p({...e.a,...r.a})}function W(e){return{...c,e:`record<string, ${e.e}>`,r(r,n){return a(this,r,n,()=>{if(!h(r))return!1;let s={},t=[];for(let[o,i]of Object.entries(r)){let u=r[o],[y,l]=e.r(i,n);if(y)s[o]=u;else{let f=l;for(let T of f)t.push(d(T,`.${o}`))}}return t.length>0?{errors:t}:{data:s}})}}}function R(e,r,n){let s=-1;for(let t of e){s++;let o=Array.isArray(r)?r[s]:r,[i,u]=o.r(t,n);if(!i)return{errors:u.map(y=>d(y,`[${s}]`))}}return!0}function D(e){return{...c,e:`${e.e}[]`,r(r,n){return a(this,r,n,()=>Array.isArray(r)?r.length===0?!0:R.call(this,r,e,n):!1)}}}function q(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return a(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:R.call(this,r,e,n))}}}function A(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 G(e){return r=>A(r,e)}function P(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function H(e){return r=>P(r,e)}function _(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function h(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{S as a,V as b,N as c,E as d,I as e,K as f,v as g,F as h,C as i,z as j,p as k,B as l,M as m,U as n,W as o,D as p,q,A as r,G as s,P as t,H as u};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)f(e,n,{get:r[n],enumerable:!0})},k=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of O(r))!$.call(e,t)&&t!==n&&f(e,t,{get:()=>r[t],enumerable:!(s=w(r,t))||s.enumerable});return e};var A=e=>k(f({},"__esModule",{value:!0}),e);var ee={};m(ee,{rc_any:()=>z,rc_array:()=>L,rc_boolean:()=>B,rc_date:()=>V,rc_extends_obj:()=>G,rc_instanceof:()=>W,rc_is_valid:()=>_,rc_literals:()=>D,rc_null:()=>C,rc_number:()=>U,rc_obj_intersection:()=>J,rc_object:()=>u,rc_parse:()=>R,rc_parser:()=>X,rc_strict_obj:()=>H,rc_string:()=>M,rc_tuple:()=>Q,rc_undefined:()=>F,rc_union:()=>q,rc_validator:()=>Y});module.exports=A(ee);function P(e){return{...this,s:e}}function a(e,r,n,s){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[e.n(o)]]:[!0,o]}if(e.s!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.y&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[e.n(o.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function S(e){return{...this,y:!0,o:e}}function N(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function I(){return{...this,i:!0}}function v(e){return`Type '${b(e)}' is not assignable to '${this.e}'`}function E(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function K(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:P,where:N,optional:I,n:v,nullable:E,withAutofix:S,nullish:K},F={...i,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},C={...i,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},z={...i,r(e,r){return a(this,e,r,()=>!0)},e:"any"},B={...i,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},M={...i,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},U={...i,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},V={...i,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function W(e){return{...i,r(r,n){return a(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function D(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return a(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${b(e[0])}_literal`:"literals"}}function q(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return a(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 d(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",s]=e.split(": "),t=n.slice(1);return`$${r}${t}: ${s}`}return`$${r}: ${e}`}function u(e){return{...i,a:e,e:"object",r(r,n){return a(this,r,n,()=>{if(!Z(r))return!1;let s=new Set(Object.keys(r)),t={},o=[];for(let[c,y]of Object.entries(e)){let l=c,T=r[c];s.delete(c);let[h,x]=y.r(T,n);if(h)t[l]=T;else{let g=x;for(let j of g)o.push(d(j,`.${c}`))}}if(this.e==="strict_obj"&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:r}:{data:t}})}}}function G(e){return{...u(e),e:"extends_object"}}function H(e){return{...u(e),e:"strict_obj"}}function J(e,r){return u({...e.a,...r.a})}function p(e,r,n){let s=-1;for(let t of e){s++;let o=Array.isArray(r)?r[s]:r,[c,y]=o.r(t,n);if(!c)return{errors:y.map(l=>d(l,`[${s}]`))}}return!0}function L(e){return{...i,e:`${e.e}[]`,r(r,n){return a(this,r,n,()=>Array.isArray(r)?r.length===0?!0:p.call(this,r,e,n):!1)}}}function Q(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return a(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:p.call(this,r,e,n))}}}function R(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 X(e){return r=>R(r,e)}function _(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function Y(e){return r=>_(r,e)}function b(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function Z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_instanceof,rc_is_valid,rc_literals,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_strict_obj,rc_string,rc_tuple,rc_undefined,rc_union,rc_validator});
1
+ "use strict";var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var k=(e,r)=>{for(var n in r)p(e,n,{get:r[n],enumerable:!0})},A=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of $(r))!m.call(e,t)&&t!==n&&p(e,t,{get:()=>r[t],enumerable:!(s=w(r,t))||s.enumerable});return e};var P=e=>A(p({},"__esModule",{value:!0}),e);var re={};k(re,{rc_any:()=>z,rc_array:()=>X,rc_boolean:()=>B,rc_date:()=>W,rc_extends_obj:()=>H,rc_instanceof:()=>D,rc_is_valid:()=>b,rc_literals:()=>q,rc_null:()=>C,rc_number:()=>U,rc_obj_intersection:()=>L,rc_object:()=>f,rc_parse:()=>h,rc_parser:()=>Z,rc_record:()=>Q,rc_strict_obj:()=>J,rc_string:()=>M,rc_tuple:()=>Y,rc_undefined:()=>F,rc_union:()=>G,rc_validator:()=>ee});module.exports=P(re);function S(e){return{...this,s:e}}function a(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.i&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[e.n(o)]]:[!0,o]}if(e.s!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.y&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[e.n(o.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function V(e){return{...this,y:!0,o:e}}function N(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function E(){return{...this,c:!0}}function I(e){return`Type '${x(e)}' is not assignable to '${this.e}'`}function K(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function v(){return{...this,i:!0,e:`${this.e}_or_nullish`}}var c={withFallback:S,where:N,optional:E,n:I,nullable:K,withAutofix:V,nullish:v},F={...c,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},C={...c,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},z={...c,r(e,r){return a(this,e,r,()=>!0)},e:"any"},B={...c,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},M={...c,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},U={...c,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},W={...c,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function D(e){return{...c,r(r,n){return a(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function q(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return a(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${x(e[0])}_literal`:"literals"}}function G(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return a(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 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 f(e){return{...c,a:e,e:"object",r(r,n){return a(this,r,n,()=>{if(!g(r))return!1;let s=new Set(Object.keys(r)),t={},o=[];for(let[i,u]of Object.entries(e)){let y=i,l=r[i];s.delete(i);let[T,d]=u.r(l,n);if(T)t[y]=l;else{let j=d;for(let O of j)o.push(R(O,`.${i}`))}}if(this.e==="strict_obj"&&s.size>0)for(let i of s)o.push(`Key '${i}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:r}:{data:t}})}}}function H(e){return{...f(e),e:"extends_object"}}function J(e){return{...f(e),e:"strict_obj"}}function L(e,r){return f({...e.a,...r.a})}function Q(e){return{...c,e:`record<string, ${e.e}>`,r(r,n){return a(this,r,n,()=>{if(!g(r))return!1;let s={},t=[];for(let[o,i]of Object.entries(r)){let u=r[o],[y,l]=e.r(i,n);if(y)s[o]=u;else{let T=l;for(let d of T)t.push(R(d,`.${o}`))}}return t.length>0?{errors:t}:{data:s}})}}}function _(e,r,n){let s=-1;for(let t of e){s++;let o=Array.isArray(r)?r[s]:r,[i,u]=o.r(t,n);if(!i)return{errors:u.map(y=>R(y,`[${s}]`))}}return!0}function X(e){return{...c,e:`${e.e}[]`,r(r,n){return a(this,r,n,()=>Array.isArray(r)?r.length===0?!0:_.call(this,r,e,n):!1)}}}function Y(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return a(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:_.call(this,r,e,n))}}}function h(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 Z(e){return r=>h(r,e)}function b(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ee(e){return r=>b(r,e)}function x(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_instanceof,rc_is_valid,rc_literals,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_strict_obj,rc_string,rc_tuple,rc_undefined,rc_union,rc_validator});
@@ -41,6 +41,9 @@ declare function rc_object<T extends RcObject>(shape: T): RcObjType<T>;
41
41
  declare function rc_extends_obj<T extends RcObject>(shape: T): RcObjType<T>;
42
42
  declare function rc_strict_obj<T extends RcObject>(shape: T): RcObjType<T>;
43
43
  declare function rc_obj_intersection<A extends RcObject, B extends RcObject>(a: RcObjType<A>, b: RcObjType<B>): RcObjType<A & B>;
44
+ declare type RcRecord<V extends RcType<any>> = Record<string, V>;
45
+ declare type RcRecordType<V extends RcType<any>> = RcType<TypeOfObjectType<RcRecord<V>>>;
46
+ declare function rc_record<V extends RcType<any>>(valueType: V): RcRecordType<V>;
44
47
  declare function rc_array<T extends RcType<any>>(type: T): RcType<RcInferType<T>[]>;
45
48
  declare type MapTupleToTypes<T extends readonly [...any[]]> = {
46
49
  -readonly [K in keyof T]: RcInferType<T[K]>;
@@ -56,8 +59,9 @@ declare function rc_tuple<T extends readonly RcType<any>[]>(types: T): RcType<Ma
56
59
  * and fallback, or the errors if invalid
57
60
  */
58
61
  declare function rc_parse<S>(input: any, type: RcType<S>): RcParseResult<S>;
59
- declare function rc_parser<S>(type: RcType<S>): (input: any) => RcParseResult<S>;
62
+ declare type RcParser<T> = (input: any) => RcParseResult<T>;
63
+ declare function rc_parser<S>(type: RcType<S>): RcParser<S>;
60
64
  declare function rc_is_valid<S>(input: any, type: RcType<S>): input is S;
61
65
  declare function rc_validator<S>(type: RcType<S>): (input: any) => input is S;
62
66
 
63
- export { RcInferType, RcParseResult, RcType, rc_any, rc_array, rc_boolean, rc_date, rc_extends_obj, rc_instanceof, rc_is_valid, rc_literals, rc_null, rc_number, rc_obj_intersection, rc_object, rc_parse, rc_parser, rc_strict_obj, rc_string, rc_tuple, rc_undefined, rc_union, rc_validator };
67
+ export { RcInferType, RcParseResult, RcParser, RcType, rc_any, rc_array, rc_boolean, rc_date, rc_extends_obj, rc_instanceof, rc_is_valid, rc_literals, rc_null, rc_number, rc_obj_intersection, rc_object, rc_parse, rc_parser, rc_record, rc_strict_obj, rc_string, rc_tuple, rc_undefined, rc_union, 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}from"./chunk-SM23XLSP.js";export{c as rc_any,o as rc_array,d as rc_boolean,g as rc_date,l as rc_extends_obj,h as rc_instanceof,s as rc_is_valid,i as rc_literals,b as rc_null,f as rc_number,n as rc_obj_intersection,k as rc_object,q as rc_parse,r as rc_parser,m as rc_strict_obj,e as rc_string,p as rc_tuple,a as rc_undefined,j as rc_union,t 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}from"./chunk-Y6MMYOJL.js";export{c as rc_any,p as rc_array,d as rc_boolean,g as rc_date,l as rc_extends_obj,h as rc_instanceof,t as rc_is_valid,i as rc_literals,b as rc_null,f as rc_number,n as rc_obj_intersection,k as rc_object,r as rc_parse,s as rc_parser,o as rc_record,m as rc_strict_obj,e as rc_string,q as rc_tuple,a as rc_undefined,j as rc_union,u 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.6.0",
4
+ "version": "0.7.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",
@@ -1 +0,0 @@
1
- function x(e){return{...this,s:e}}function a(e,r,n,s){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[e.n(o)]]:[!0,o]}if(e.s!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.s];if(e.l&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[e.n(o.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function g(e){return{...this,l:!0,o:e}}function j(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function w(){return{...this,i:!0}}function O(e){return`Type '${p(e)}' is not assignable to '${this.e}'`}function $(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function m(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:x,where:j,optional:w,n:O,nullable:$,withAutofix:g,nullish:m},S={...i,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},N={...i,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},I={...i,r(e,r){return a(this,e,r,()=>!0)},e:"any"},v={...i,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},E={...i,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},K={...i,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...i,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function C(e){return{...i,r(r,n){return a(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function z(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return a(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${p(e[0])}_literal`:"literals"}}function B(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return a(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 T(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",s]=e.split(": "),t=n.slice(1);return`$${r}${t}: ${s}`}return`$${r}: ${e}`}function l(e){return{...i,a:e,e:"object",r(r,n){return a(this,r,n,()=>{if(!P(r))return!1;let s=new Set(Object.keys(r)),t={},o=[];for(let[c,u]of Object.entries(e)){let y=c,f=r[c];s.delete(c);let[R,_]=u.r(f,n);if(R)t[y]=f;else{let b=_;for(let h of b)o.push(T(h,`.${c}`))}}if(this.e==="strict_obj"&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:r}:{data:t}})}}}function M(e){return{...l(e),e:"extends_object"}}function U(e){return{...l(e),e:"strict_obj"}}function V(e,r){return l({...e.a,...r.a})}function d(e,r,n){let s=-1;for(let t of e){s++;let o=Array.isArray(r)?r[s]:r,[c,u]=o.r(t,n);if(!c)return{errors:u.map(y=>T(y,`[${s}]`))}}return!0}function W(e){return{...i,e:`${e.e}[]`,r(r,n){return a(this,r,n,()=>Array.isArray(r)?r.length===0?!0:d.call(this,r,e,n):!1)}}}function D(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return a(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:d.call(this,r,e,n))}}}function k(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 q(e){return r=>k(r,e)}function A(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function G(e){return r=>A(r,e)}function p(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function P(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{S as a,N as b,I as c,v as d,E as e,K as f,F as g,C as h,z as i,B as j,l as k,M as l,U as m,V as n,W as o,D as p,k as q,q as r,A as s,G as t};