runcheck 0.1.0 → 0.4.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
@@ -1,3 +1,164 @@
1
1
  # Runcheck
2
2
 
3
- Runtime type checks for typescript
3
+ A lib for js/typescript runtime type checks with autofix support. Runcheck has the goal of being very lightweight. Because of that, it has only around [1.7kb Gzipped](https://bundlephobia.com/package/runcheck), has no dependencies and is tree-shakeable!
4
+
5
+ Obs: Runcheck is in Beta and it's api can still change
6
+
7
+ # Installation
8
+
9
+ ```bash
10
+ pnpm add runcheck
11
+ ```
12
+
13
+ # Basic types:
14
+
15
+ | runcheck type | ts type equivalent |
16
+ | ------------------------------- | ------------------------------------------------- |
17
+ | `rc_string` | `string` |
18
+ | `rc_number` | `number` |
19
+ | `rc_boolean` | `boolean` |
20
+ | `rc_any` | `any` |
21
+ | `rc_null` | `null` |
22
+ | `rc_undefined` | `undefined` |
23
+ | `rc_date` | `Date` |
24
+ | `rc_intanceof(instance: T)` | Classes typecheck in general |
25
+ | `rc_literals(...literals: T[])` | Type literal in general like `hello`, `true`, `1` |
26
+ | `rc_union(...types: T[])` | Union types in general like `string \| 1` |
27
+ | `rc_array<T>(type: T)` | `T[]` |
28
+ | `rc_tuple<T>(...types: T[])` | `[T, T]` |
29
+
30
+ # Object types:
31
+
32
+ ## `rc_object`
33
+
34
+ ```ts
35
+ const shape = rc_object({
36
+ name: rc_string,
37
+ age: rc_number,
38
+ isCool: rc_boolean,
39
+ })
40
+ ```
41
+
42
+ The `rc_object` will allow extra properties but, any extra propertie will be striped in parsing. To allow extra in parsing properties, use `rc_extends_obj`.
43
+
44
+ ## `rc_strict_obj`
45
+
46
+ The same as `rc_object` but, any extra propertie will be throw an error in parsing.
47
+
48
+ ## `rc_obj_intersection`
49
+
50
+ Allow to merge two `rc_object` types. Example:
51
+
52
+ ```ts
53
+ const shape = rc_obj_intersection(
54
+ rc_object({
55
+ name: rc_string,
56
+ age: rc_number,
57
+ isCool: rc_boolean,
58
+ }),
59
+ rc_object({
60
+ address: rc_string,
61
+ phone: rc_string,
62
+ }),
63
+ )
64
+ ```
65
+
66
+ # Parsing
67
+
68
+ ```ts
69
+ import { rc_parse } from 'runcheck'
70
+
71
+ const input = JSON.parse(jsonInput)
72
+
73
+ const parseResult = rc_parse(input, rc_array(rc_string))
74
+
75
+ if (parseResult.error) {
76
+ throw new Error(parseResult.errors.join('\n'))
77
+ // Errors are a array of strings
78
+ }
79
+
80
+ const result = parseResult.data
81
+ // Do something with result
82
+ ```
83
+
84
+ You can also use `rc_parser` to create a reusable parser.
85
+
86
+ ```ts
87
+ import { rc_parser } from 'runcheck'
88
+
89
+ const parser = rc_parser(rc_array(rc_string))
90
+
91
+ const parseResult = parser(jsonInput)
92
+ const parseResult2 = parser(jsonInput2)
93
+ ```
94
+
95
+ # Type assertion
96
+
97
+ Use `rc_is_valid` and `rc_validator` to do a simple type assertion.
98
+
99
+ ```ts
100
+ import { rc_is_valid } from 'runcheck'
101
+
102
+ const input = JSON.parse(jsonInput)
103
+
104
+ if (rc_is_valid(input, rc_array(rc_string))) {
105
+ // input will be inferred by ts as `string[]`
106
+ }
107
+ ```
108
+
109
+ # Autofixing and fallback values in parsing
110
+
111
+ Values can be autofixed and fallback values can be provided for parsing. The checks will pass but the result will return warnings messages.
112
+
113
+ ```ts
114
+ type SuccessResult = {
115
+ error: false
116
+ data: T
117
+ warnings: string[] | false
118
+ }
119
+ ```
120
+
121
+ ## Fallback
122
+
123
+ Use the method `rc_[type].withFallback(fallback)` to provide a fallback value if the input is not valid.
124
+
125
+ ```ts
126
+ const input = 'hello'
127
+
128
+ const result = rc_parse(input, rc_string.withFallback('world'))
129
+ ```
130
+
131
+ ## AutoFix
132
+
133
+ You can also use `rc_[type].autoFix()` to automatically fix the input if it is not valid.
134
+
135
+ ```ts
136
+ const input = 1
137
+
138
+ const result = rc_parse(
139
+ input,
140
+ rc_string.autoFix((input) => input.toString()),
141
+ )
142
+ ```
143
+
144
+ There are also some predefined autofixed types that you can import:
145
+
146
+ ```ts
147
+ import { rc_string_autofix, rc_boolean_autofix } from 'runcheck/autofixable'
148
+
149
+ // use like any other type
150
+ ```
151
+
152
+ # Performing custom checks
153
+
154
+ You can also use `rc_[type].where(customCheckFunction)` to perform custom checks.
155
+
156
+ ```ts
157
+ const input = 1
158
+
159
+ const positiveNumberType = rc_number.where((input) => input > 0)
160
+ ```
161
+
162
+ # Optional and nullable types
163
+
164
+ Use `rc_[type].optional()` to make a type optional, and `rc_[type].orNullish()` to make a type nullable.
@@ -0,0 +1 @@
1
+ "use strict";var c=Object.defineProperty;var l=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=l(r,n))||i.enumerable});return e};var _=e=>R(c({},"__esModule",{value:!0}),e);var k={};p(k,{rc_boolean_autofix:()=>O,rc_number_autofix:()=>$,rc_string_autofix:()=>A});module.exports=_(k);function x(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];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.u&&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,u:!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 '${m(e)}' is not assignable to '${this.e}'`}function w(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var a={withFallback:x,where:h,optional:g,n:j,nullable:w,withAutofix:b},S={...a,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},P={...a,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},I={...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"},f={...a,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},v={...a,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function m(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var O=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),$=f.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});
@@ -0,0 +1,7 @@
1
+ import { RcType } from './runcheck.js';
2
+
3
+ declare const rc_boolean_autofix: RcType<boolean>;
4
+ declare const rc_string_autofix: RcType<string>;
5
+ declare const rc_number_autofix: RcType<number>;
6
+
7
+ export { rc_boolean_autofix, rc_number_autofix, rc_string_autofix };
@@ -0,0 +1 @@
1
+ import{d as t,e as f,f as o}from"./chunk-TZCAUEQX.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];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};
@@ -0,0 +1 @@
1
+ "use strict";var f=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var $=(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))!m.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 Z={};$(Z,{rc_any:()=>C,rc_array:()=>J,rc_boolean:()=>z,rc_date:()=>U,rc_extends_obj:()=>q,rc_instanceof:()=>V,rc_is_valid:()=>_,rc_literals:()=>W,rc_null:()=>F,rc_number:()=>M,rc_obj_intersection:()=>H,rc_object:()=>u,rc_parse:()=>R,rc_parser:()=>Q,rc_strict_obj:()=>G,rc_string:()=>B,rc_tuple:()=>L,rc_undefined:()=>K,rc_union:()=>D,rc_validator:()=>X});module.exports=A(Z);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];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 S(e){return{...this,u:!0,o:e}}function I(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function N(){return{...this,i:!0}}function v(e){return`Type '${b(e)}' is not assignable to '${this.e}'`}function E(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:P,where:I,optional:N,n:v,nullable:E,withAutofix:S},K={...i,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},F={...i,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},C={...i,r(e,r){return a(this,e,r,()=>!0)},e:"any"},z={...i,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},B={...i,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},M={...i,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},U={...i,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function V(e){return{...i,r(r,n){return a(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{...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 D(...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(!Y(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 q(e){return{...u(e),e:"extends_object"}}function G(e){return{...u(e),e:"strict_obj"}}function H(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 J(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 L(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 Q(e){return r=>R(r,e)}function _(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function X(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 Y(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});
@@ -0,0 +1,62 @@
1
+ declare type RcParseResult<T> = {
2
+ error: false;
3
+ data: T;
4
+ warnings: string[] | false;
5
+ } | {
6
+ error: true;
7
+ errors: string[];
8
+ };
9
+ declare type RcInferType<T extends RcType<any>> = T extends RcType<infer U> ? U : never;
10
+ declare type RcOptional<T> = RcType<T | undefined>;
11
+ declare type ParseResultCtx = {
12
+ warnings: string[];
13
+ };
14
+ declare type InternalParseResult<T> = [success: true, data: T] | [success: false, errors: string[]];
15
+ declare type RcType<T> = {
16
+ readonly withFallback: (fallback: T) => RcType<T>;
17
+ readonly where: (predicate: (input: T) => boolean) => RcType<T>;
18
+ readonly optional: () => RcOptional<T>;
19
+ readonly nullable: () => RcType<T | null | undefined>;
20
+ readonly withAutofix: (customAutofix: (input: unknown) => false | {
21
+ fixed: T;
22
+ }) => RcType<T>;
23
+ };
24
+ declare const rc_undefined: RcType<undefined>;
25
+ declare const rc_null: RcType<null>;
26
+ declare const rc_any: RcType<any>;
27
+ declare const rc_boolean: RcType<boolean>;
28
+ declare const rc_string: RcType<string>;
29
+ declare const rc_number: RcType<number>;
30
+ declare const rc_date: RcType<Date>;
31
+ declare function rc_instanceof<T extends Function>(classToCheck: T): RcType<T>;
32
+ declare function rc_literals<T extends (string | number | boolean)[]>(...literals: T): RcType<T[number]>;
33
+ declare function rc_union<T extends RcType<any>[]>(...types: T): RcType<RcInferType<T[number]>>;
34
+ declare type RcObject = Record<string, RcType<any>>;
35
+ declare type TypeOfObjectType<T extends RcObject> = {
36
+ [K in keyof T]: RcInferType<T[K]>;
37
+ };
38
+ declare type RcObjType<T extends RcObject> = RcType<TypeOfObjectType<T>>;
39
+ declare function rc_object<T extends RcObject>(shape: T): RcObjType<T>;
40
+ declare function rc_extends_obj<T extends RcObject>(shape: T): RcObjType<T>;
41
+ declare function rc_strict_obj<T extends RcObject>(shape: T): RcObjType<T>;
42
+ declare function rc_obj_intersection<A extends RcObject, B extends RcObject>(a: RcObjType<A>, b: RcObjType<B>): RcObjType<A & B>;
43
+ declare function rc_array<T extends RcType<any>>(type: T): RcType<RcInferType<T>[]>;
44
+ declare type MapTupleToTypes<T extends readonly [...any[]]> = {
45
+ -readonly [K in keyof T]: RcInferType<T[K]>;
46
+ };
47
+ /**
48
+ * Check for a tuple of types
49
+ *
50
+ * TS equivalent example: [string, number, boolean]
51
+ */
52
+ declare function rc_tuple<T extends readonly RcType<any>[]>(types: T): RcType<MapTupleToTypes<T>>;
53
+ /**
54
+ * Parse a runcheck type. If valid return the valid input, with warning for autofix
55
+ * and fallback, or the errors if invalid
56
+ */
57
+ declare function rc_parse<S>(input: any, type: RcType<S>): RcParseResult<S>;
58
+ declare function rc_parser<S>(type: RcType<S>): (input: any) => RcParseResult<S>;
59
+ declare function rc_is_valid<S>(input: any, type: RcType<S>): input is S;
60
+ declare function rc_validator<S>(type: RcType<S>): (input: any) => input is S;
61
+
62
+ 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 };
package/dist/runcheck.js CHANGED
@@ -1,7 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
4
- function main() {
5
- console.log('Work in progress...');
6
- }
7
- exports.main = main;
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t}from"./chunk-TZCAUEQX.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
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "runcheck",
3
- "version": "0.1.0",
3
+ "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
+ "version": "0.4.0",
4
5
  "license": "MIT",
5
6
  "scripts": {
6
- "test": "vitest run",
7
- "test:ui": "vitest --ui",
8
- "build": "vitest run && tsc -p tsconfig.prod.json",
9
- "npm-publish": "pnpm run build && npm publish"
7
+ "test": "vitest --ui",
8
+ "test:run": "vitest run",
9
+ "benchmark": "tsm benchmarks/benchmark.ts",
10
+ "benchmark:generate-profile": "tsm benchmarks/generateProfiles.ts",
11
+ "build": "pnpm test:run && pnpm build:no-test",
12
+ "build:no-test": "tsup --minify --dts && tsm scripts/removeInternalDeclarations.ts",
13
+ "npm-publish": "./scripts/check-if-is-sync.sh && pnpm build && npm publish"
10
14
  },
11
15
  "files": [
12
16
  "dist"
@@ -14,16 +18,39 @@
14
18
  "packageManager": "^pnpm@7.6.0",
15
19
  "repository": "github:lucasols/runcheck",
16
20
  "author": "Lucas Santos",
17
- "main": "./dist/runcheck.js",
21
+ "type": "module",
22
+ "main": "./dist/runcheck.cjs",
23
+ "module": "./dist/runcheck.js",
18
24
  "types": "./dist/runcheck.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/runcheck.js",
28
+ "require": "./dist/runcheck.cjs"
29
+ },
30
+ "./autofixable": {
31
+ "import": "./dist/autofixable.js",
32
+ "require": "./dist/autofixable.cjs"
33
+ }
34
+ },
35
+ "sideEffects": false,
19
36
  "engines": {
20
37
  "node": ">=14.6.0"
21
38
  },
22
39
  "devDependencies": {
23
40
  "@types/node": "^18.7.2",
41
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
42
+ "@typescript-eslint/parser": "^5.33.0",
24
43
  "@vitest/ui": "^0.21.1",
25
- "typescript": "^4.7.4",
44
+ "eslint": "^8.22.0",
45
+ "eslint-plugin-jest": "^26.8.2",
46
+ "mitata": "^0.1.6",
47
+ "myzod": "^1.8.8",
48
+ "tsm": "^2.2.2",
49
+ "tsup": "^6.2.2",
50
+ "typescript": "^4.8.1-rc",
51
+ "v8-profiler-next": "^1.9.0",
26
52
  "vite": "^3.0.7",
27
- "vitest": "^0.21.1"
53
+ "vitest": "^0.21.1",
54
+ "zod": "^3.18.0"
28
55
  }
29
56
  }