@coverbase/validate
Advanced tools
+0
-1
| export * from "./pipe"; | ||
| export * from "./result"; | ||
| export * from "./schema"; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var j=(S,R)=>{let x;for(let b of R.filter((f)=>typeof f==="function")){const{output:f,errorMessages:q}=b(S);if(S=f,q)x?x.push(...q):x=q}return{output:S,errorMessages:x}},B=(S,R="MinLength")=>{return(x)=>{if(x.length>S)return{output:x};return{output:x,errorMessages:[R]}}},C=(S,R="MaxLength")=>{return(x)=>{if(x.length<S)return{output:x};return{output:x,errorMessages:[R]}}},D=(S="EmailAddress")=>{return(R)=>{return{output:R,errorMessages:[S]}}};class A extends Error{errorMessages;constructor(S){super();this.errorMessages=S}}var J=(...S)=>{return{parse:(R)=>{if(typeof R==="string")return j(R,S);return{output:R,errorMessages:S.filter((x)=>typeof x==="string")}}}},K=(...S)=>{return{parse:(R)=>{if(typeof R==="number")return j(R,S);return{output:R,errorMessages:S.filter((x)=>typeof x==="string")}}}},L=(...S)=>{return{parse:(R)=>{if(typeof R==="bigint")return j(R,S);return{output:R,errorMessages:S.filter((x)=>typeof x==="string")}}}},N=(...S)=>{return{parse:(R)=>{if(typeof R==="boolean")return j(R,S);return{output:R,errorMessages:S.filter((x)=>typeof x==="string")}}}},O=(...S)=>{return{parse:(R)=>{if(R instanceof Date)return j(R,S);return{output:R,errorMessages:S.filter((x)=>typeof x==="string")}}}},Q=(...S)=>{return{parse:(R)=>{return j(R,S)}}},T=(S,...R)=>{return{parse:(x)=>{if(x&&typeof x==="object"){let b;for(let[f,q]of Object.entries(S)){const{output:y,errorMessages:z}=q.parse(x[f]);if(x[f]=y,z)b?b.push(...z):b=z}if(b)return{output:x,errorMessages:b};return j(x,R)}return{output:x,errorMessages:R.filter((b)=>typeof b==="string")}}}},U=(S,...R)=>{return{parse:(x)=>{if(Array.isArray(x)){const b=x.map((y)=>S.parse(y)),f=b.flatMap(({output:y})=>y),q=b.flatMap(({errorMessages:y})=>y??[]);if(q.length>0)return{output:f,errorMessages:q};return j(f,R)}return{output:x,errorMessages:R.filter((b)=>typeof b==="string")}}}},W=(S,R)=>{return{parse:(x)=>{if(x===void 0)return{output:x??R};return S.parse(x)}}},X=(S,R)=>{const{output:x,errorMessages:b}=S.parse(R);if(b)throw new A(b);return x};export{j as withPipes,J as string,X as parse,W as optional,T as object,K as number,B as minLength,C as maxLength,D as emailAddress,O as date,N as boolean,L as bigint,U as array,Q as any,A as ValidationError}; | ||
| var z=(f)=>{return{parse:(b)=>{if(typeof b==="string")return{output:b};return{output:b,errorMessages:[f??"String"]}}}},B=(f)=>{return{parse:(b)=>{if(typeof b==="number")return{output:b};return{output:b,errorMessages:[f??"Number"]}}}},C=(f)=>{return{parse:(b)=>{if(typeof b==="bigint")return{output:b};return{output:b,errorMessages:[f??"Bigint"]}}}},D=(f)=>{return{parse:(b)=>{if(typeof b==="boolean")return{output:b};return{output:b,errorMessages:[f??"Boolean"]}}}},E=(f)=>{return{parse:(b)=>{if(b instanceof Date)return{output:b};return{output:b,errorMessages:[f??"Date"]}}}},F=()=>{return{parse:(f)=>{return{output:f}}}},G=(f,b)=>{return{parse:(w)=>{if(Array.isArray(w)){const x=w.map((A)=>f.parse(A)),S=x.flatMap(({output:A})=>A),d=x.flatMap(({errorMessages:A})=>A??[]);if(d.length)return{output:S,errorMessages:d};return{output:S}}return{output:w,errorMessages:[b??"Array"]}}}},H=(f,b)=>{return{parse:(w)=>{if(typeof w==="object"){const x=[];for(let[S,d]of Object.entries(f)){const{output:A,errorMessages:j}=d.parse(w[S]);if(w[S]=A,j)x.push(...j)}if(x.length)return{output:w,errorMessages:x};return{output:w}}return{output:w,errorMessages:[b??"Object"]}}}},I=(f,b)=>{return{parse:(w)=>{if(w===void 0)return{output:w??b};return f.parse(w)}}},J=(f,b)=>{const{output:w,errorMessages:x}=f.parse(b);if(x)throw new Error(x.join(", "));return w};export{z as string,J as parse,I as optional,H as object,B as number,E as date,D as boolean,C as bigint,G as array,F as any}; |
+1
-6
@@ -1,6 +0,1 @@ | ||
| 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>; | ||
| export {}; |
+19
-14
@@ -1,20 +0,25 @@ | ||
| import { type Pipe } from "./pipe"; | ||
| import { type Result } from "./result"; | ||
| export type Output<T> = T extends Schema<infer U> ? U : unknown; | ||
| export type Success<T> = { | ||
| output: T; | ||
| errorMessages?: Array<string>; | ||
| }; | ||
| export type Failure = { | ||
| output: unknown; | ||
| errorMessages: Array<string>; | ||
| }; | ||
| export type Schema<T = any> = { | ||
| parse: (input: unknown) => Result<T>; | ||
| parse: (input: unknown) => Success<T> | Failure; | ||
| }; | ||
| export type Output<T extends Schema> = T extends Schema<infer U> ? U : unknown; | ||
| export type Args<T> = Array<Pipe<T> | string>; | ||
| export type Resolve<T extends Record<string, Schema>> = { | ||
| [Key in keyof T]: Output<T[Key]>; | ||
| }; | ||
| export declare const string: (...args: Args<string>) => Schema<string>; | ||
| export declare const number: (...args: Args<number>) => Schema<number>; | ||
| export declare const bigint: (...args: Args<bigint>) => Schema<bigint>; | ||
| export declare const boolean: (...args: Args<boolean>) => Schema<boolean>; | ||
| export declare const date: (...args: Args<Date>) => Schema<Date>; | ||
| export declare const any: (...args: Args<any>) => Schema<any>; | ||
| export declare const object: <T extends Record<string, Schema<any>>>(entries: T, ...args: Args<Resolve<T>>) => Schema<Resolve<T>>; | ||
| export declare const array: <T extends Schema<any>>(schema: T, ...args: Args<Output<T>[]>) => Schema<Output<T>[]>; | ||
| export declare const optional: <T extends Schema<any>>(schema: T, defaultValue?: T | undefined) => Schema<Output<T> | undefined>; | ||
| export declare const string: (errorMessage?: string) => Schema<string>; | ||
| export declare const number: (errorMessage?: string) => Schema<number>; | ||
| export declare const bigint: (errorMessage?: string) => Schema<bigint>; | ||
| export declare const boolean: (errorMessage?: string) => Schema<boolean>; | ||
| export declare const date: (errorMessage?: string) => Schema<Date>; | ||
| export declare const any: () => Schema<any>; | ||
| export declare const array: <T extends Schema<any>>(schema: T, errorMessage?: string) => Schema<Output<T>[]>; | ||
| export declare const object: <T extends Record<string, Schema<any>>>(entries: T, errorMessage?: string) => Schema<Resolve<T>>; | ||
| export declare const optional: <T extends Schema<any>>(schema: T, defaultValue?: Output<T> | undefined) => Schema<Output<T> | undefined>; | ||
| export declare const parse: <T extends Schema<any>>(schema: T, input: unknown) => Output<T>; |
+1
-1
| { | ||
| "name": "@coverbase/validate", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "exports": { |
| export type ErrorMessage = string; | ||
| export type Success<T> = { | ||
| output: T; | ||
| errorMessages?: Array<ErrorMessage>; | ||
| }; | ||
| export type Failure = { | ||
| output: unknown; | ||
| errorMessages: Array<ErrorMessage>; | ||
| }; | ||
| export type Result<T> = Success<T> | Failure; | ||
| export declare class ValidationError extends Error { | ||
| readonly errorMessages: Array<ErrorMessage>; | ||
| constructor(errorMessages: Array<ErrorMessage>); | ||
| } |
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.
3404
-32.14%5
-16.67%34
-34.62%