runcheck 0.7.0 → 0.7.1

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 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
+ "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==null||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,7 +1,11 @@
1
1
  import { RcType } from './runcheck.js';
2
2
 
3
+ /** autofixes a boolean type if input is 0 | 1 | 'true' | 'false' | undefined | null,
4
+ * returning error otherwise */
3
5
  declare const rc_boolean_autofix: RcType<boolean>;
6
+ /** autofixes a string type if input is a number, returning error otherwise */
4
7
  declare const rc_string_autofix: RcType<string>;
8
+ /** autofixes a number type if input is a a valid number string, returning error otherwise */
5
9
  declare const rc_number_autofix: RcType<number>;
6
10
 
7
11
  export { rc_boolean_autofix, rc_number_autofix, rc_string_autofix };
@@ -1 +1 @@
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};
1
+ import{d as f,e as t,f as o}from"./chunk-Y6MMYOJL.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};
@@ -16,8 +16,8 @@ declare type RcType<T> = {
16
16
  readonly withFallback: (fallback: T) => RcType<T>;
17
17
  readonly where: (predicate: (input: T) => boolean) => RcType<T>;
18
18
  readonly optional: () => RcOptional<T>;
19
- readonly nullable: () => RcType<T | null | undefined>;
20
- readonly nullish: () => RcType<T | null>;
19
+ readonly nullable: () => RcType<T | null>;
20
+ readonly nullish: () => RcType<T | null | undefined>;
21
21
  readonly withAutofix: (customAutofix: (input: unknown) => false | {
22
22
  fixed: T;
23
23
  }) => RcType<T>;
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.7.0",
4
+ "version": "0.7.1",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",