@coverbase/validate
Advanced tools
+1
-1
@@ -1,1 +0,1 @@ | ||
| var F=(x="")=>{return(f)=>{return b(f,[x])}};var b=(x,f=[])=>{return{output:x,errorMessages:f}};class A extends Error{errorMessages;constructor(x){super();this.errorMessages=x}}var J=(...x)=>{return{parse:(f)=>{if(typeof f==="string")return b(f);return b(f,x.filter((T)=>typeof T==="string"))}}},K=(...x)=>{return{parse:(f)=>{if(typeof f==="number")return b(f);return b(f,x.filter((T)=>typeof T==="string"))}}},L=(...x)=>{return{parse:(f)=>{if(typeof f==="bigint")return b(f);return b(f,x.filter((T)=>typeof T==="string"))}}},N=(...x)=>{return{parse:(f)=>{if(typeof f==="boolean")return b(f);return b(f,x.filter((T)=>typeof T==="string"))}}},O=(x,...f)=>{return{parse:(T)=>{if(T&&typeof T==="object")return Object.entries(x).reduce((j,[w,z])=>{const q=T[w],{output:B,errorMessages:C}=z.parse(q);return j.output[w]=B,j.errorMessages.push(...C),j},b(T));return b(T,f.filter((j)=>typeof j==="string"))}}},P=(x,...f)=>{return{parse:(T)=>{if(Array.isArray(T)){const j=T.map((q)=>x.parse(q)),w=j.flatMap(({output:q})=>q),z=j.flatMap(({errorMessages:q})=>q);return b(w,z)}return b(T,f.filter((j)=>typeof j==="string"))}}},Q=({parse:x})=>{return{parse:x}},S=(x,f)=>{const{output:T,errorMessages:j}=x.parse(f);if(j.length>0)throw new A(j);return T};export{J as string,S as parse,Q as optional,O as object,K as number,F as emailAddress,b as createResult,N as boolean,L as bigint,P as array,A as ValidationError}; | ||
| var y=(x,R)=>{let f;for(let b of R.filter((d)=>typeof d==="function")){const{output:d,errorMessages:j}=b(x);if(x=d,j)f?f.push(...j):f=j}return{output:x,errorMessages:f}},B=(x,R="MinLength")=>{return(f)=>{if(f.length>x)return{output:f};return{output:f,errorMessages:[R]}}},C=(x,R="MaxLength")=>{return(f)=>{if(f.length<x)return{output:f};return{output:f,errorMessages:[R]}}},D=(x="EmailAddress")=>{return(R)=>{return{output:R,errorMessages:[x]}}};class A extends Error{errorMessages;constructor(x){super();this.errorMessages=x}}var J=(...x)=>{return{parse:(R)=>{if(typeof R==="string")return y(R,x);return{output:R,errorMessages:x.filter((f)=>typeof f==="string")}}}},K=(...x)=>{return{parse:(R)=>{if(typeof R==="number")return y(R,x);return{output:R,errorMessages:x.filter((f)=>typeof f==="string")}}}},L=(...x)=>{return{parse:(R)=>{if(typeof R==="bigint")return y(R,x);return{output:R,errorMessages:x.filter((f)=>typeof f==="string")}}}},N=(...x)=>{return{parse:(R)=>{if(typeof R==="boolean")return y(R,x);return{output:R,errorMessages:x.filter((f)=>typeof f==="string")}}}},O=(x,...R)=>{return{parse:(f)=>{if(f&&typeof f==="object"){let b;for(let[d,j]of Object.entries(x)){const{output:q,errorMessages:z}=j.parse(f[d]);if(f[d]=q,z)b?b.push(...z):b=z}if(b)return{output:f,errorMessages:b};return y(f,R)}return{output:f,errorMessages:R.filter((b)=>typeof b==="string")}}}},Q=(x,...R)=>{return{parse:(f)=>{if(Array.isArray(f)){const b=f.map((q)=>x.parse(q)),d=b.flatMap(({output:q})=>q),j=b.flatMap(({errorMessages:q})=>q??[]);if(j.length>0)return{output:d,errorMessages:j};return y(d,R)}return{output:f,errorMessages:R.filter((b)=>typeof b==="string")}}}},S=({parse:x})=>{return{parse:x}},T=(x,R)=>{const{output:f,errorMessages:b}=x.parse(R);if(b)throw new A(b);return f};export{y as withPipes,J as string,T as parse,S as optional,O as object,K as number,B as minLength,C as maxLength,D as emailAddress,N as boolean,L as bigint,Q as array,A as ValidationError}; |
+4
-1
@@ -1,3 +0,6 @@ | ||
| import { type ErrorMessage, type Result } from "."; | ||
| import { type Args, type ErrorMessage, type Result } from "."; | ||
| export type Pipe<T> = (input: T) => Result<T>; | ||
| export declare const withPipes: <T>(input: T, args: Args<T>) => Result<T>; | ||
| export declare const minLength: (length: number, errorMessage?: ErrorMessage) => Pipe<string>; | ||
| export declare const maxLength: (length: number, errorMessage?: ErrorMessage) => Pipe<string>; | ||
| export declare const emailAddress: (errorMessage?: ErrorMessage) => Pipe<string>; |
+7
-3
| export type ErrorMessage = string; | ||
| export type Result<T> = { | ||
| output: T | unknown; | ||
| export type Success<T> = { | ||
| output: T; | ||
| errorMessages?: Array<ErrorMessage>; | ||
| }; | ||
| export type Failure = { | ||
| output: unknown; | ||
| errorMessages: Array<ErrorMessage>; | ||
| }; | ||
| export declare const createResult: <T>(output: T, errorMessages?: Array<ErrorMessage>) => Result<T>; | ||
| export type Result<T> = Success<T> | Failure; | ||
| export declare class ValidationError extends Error { | ||
@@ -8,0 +12,0 @@ readonly errorMessages: Array<ErrorMessage>; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import type { Pipe } from "./pipe"; | ||
| import { type Pipe } from "./pipe"; | ||
| import { type Result } from "./result"; | ||
@@ -3,0 +3,0 @@ export type Schema<T = any> = { |
+1
-1
| { | ||
| "name": "@coverbase/validate", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "exports": { |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
4609
22.94%49
22.5%