runcheck 0.5.1 → 0.6.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 +8 -2
- package/dist/autofixable.cjs +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-SM23XLSP.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +1 -0
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-TZCAUEQX.js +0 -1
package/README.md
CHANGED
|
@@ -159,6 +159,12 @@ const input = 1
|
|
|
159
159
|
const positiveNumberType = rc_number.where((input) => input > 0)
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
-
#
|
|
162
|
+
# Type modifiers
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
You can use also modiers like `rc_string.optional()` to extend or modify the rc types:
|
|
165
|
+
|
|
166
|
+
| runcheck modifier | ts type equivalent |
|
|
167
|
+
| ---------------------- | ------------------------ |
|
|
168
|
+
| `rc_[type].optional()` | `T \| undefined` |
|
|
169
|
+
| `rc_[type].nullable()` | `T \| null` |
|
|
170
|
+
| `rc_[type].nullish()` | `T \| null \| undefined` |
|
package/dist/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var
|
|
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});
|
package/dist/autofixable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as t,e as f,f as o}from"./chunk-
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var
|
|
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});
|
package/dist/runcheck.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare type RcType<T> = {
|
|
|
17
17
|
readonly where: (predicate: (input: T) => boolean) => RcType<T>;
|
|
18
18
|
readonly optional: () => RcOptional<T>;
|
|
19
19
|
readonly nullable: () => RcType<T | null | undefined>;
|
|
20
|
+
readonly nullish: () => RcType<T | null>;
|
|
20
21
|
readonly withAutofix: (customAutofix: (input: unknown) => false | {
|
|
21
22
|
fixed: T;
|
|
22
23
|
}) => RcType<T>;
|
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-
|
|
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};
|
package/package.json
CHANGED
package/dist/chunk-TZCAUEQX.js
DELETED
|
@@ -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];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.u&&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,u:!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 m(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:x,where:j,optional:w,n:O,nullable:m,withAutofix:g},P={...i,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},S={...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"},N={...i,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},v={...i,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},E={...i,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},K={...i,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function F(e){return{...i,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{...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 z(...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(!A(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 B(e){return{...l(e),e:"extends_object"}}function M(e){return{...l(e),e:"strict_obj"}}function U(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 V(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 W(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 $(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 D(e){return r=>$(r,e)}function k(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function q(e){return r=>k(r,e)}function p(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)}export{P as a,S as b,I as c,N as d,v as e,E as f,K as g,F as h,C as i,z as j,l as k,B as l,M as m,U as n,V as o,W as p,$ as q,D as r,k as s,q as t};
|