common-resolver
Advanced tools
+1
-1
| { | ||
| "name": "common-resolver", | ||
| "version": "0.0.16", | ||
| "version": "0.0.17", | ||
| "scripts": { | ||
@@ -5,0 +5,0 @@ "build": "tsc" |
| export { Resolver } from '../types'; |
| export {}; |
| export declare function isSuperstructSchema<T>(validator: any): validator is import("superstruct").Struct<T, any>; |
| export function isSuperstructSchema(validator) { | ||
| return validator instanceof (require("superstruct").Struct); | ||
| } |
| export declare function superstructParser<T>(data: T, schema: import("superstruct").Struct<T, any>, options?: { | ||
| throwError: boolean; | ||
| }): T; |
| import { commonParser } from "../utils/commonParser"; | ||
| import { superstructResolver } from "./ssResolver"; | ||
| export function superstructParser(data, schema, options) { | ||
| return commonParser(data, schema, superstructResolver, options); | ||
| } |
| import { Resolver } from "../types"; | ||
| export declare function superstructResolver<T>(schema: import("superstruct").Struct<T, any>): Resolver<T>; |
| import { createErrorProxy, errorPathObjectify } from "../utils"; | ||
| export function superstructResolver(schema) { | ||
| const { validate } = require("superstruct"); | ||
| const formatter = (obj) => { | ||
| return obj.reduce((acc, { message, path }) => { | ||
| acc[path.join('.') || "root"] = message; | ||
| return acc; | ||
| }, {}); | ||
| }; | ||
| return { | ||
| validate: (state) => { | ||
| const [error] = validate(state, schema); | ||
| if (!error) { | ||
| return { | ||
| valid: true, | ||
| error: null, | ||
| data: state | ||
| }; | ||
| } | ||
| else { | ||
| return { | ||
| valid: false, | ||
| error: createErrorProxy(errorPathObjectify(formatter(error.failures()))), | ||
| data: null | ||
| }; | ||
| } | ||
| } | ||
| }; | ||
| } |
| export * from './ss/isSuperstructSchema'; | ||
| export * from './ss/ssParser'; | ||
| export * from './ss/ssResolver'; |
| export * from './ss/isSuperstructSchema'; | ||
| export * from './ss/ssParser'; | ||
| export * from './ss/ssResolver'; |
| export * from './types'; |
| export * from './types'; |
| export * from './utils/getResolver'; |
| export * from './utils/getResolver'; |
| export * from './utils/getResolver'; |
| export * from './utils/getResolver'; |
| export * from './zod/isZodSchema'; | ||
| export * from './zod/zodParser'; | ||
| export * from './zod/zodResolver'; |
| export * from './zod/isZodSchema'; | ||
| export * from './zod/zodParser'; | ||
| export * from './zod/zodResolver'; |
| export * from './zod/isZodSchema'; | ||
| export * from './zod/zodParser'; | ||
| export * from './zod/zodResolver'; |
| export * from './zod/isZodSchema'; | ||
| export * from './zod/zodParser'; | ||
| export * from './zod/zodResolver'; |
29420
-7.86%36
-35.71%288
-19.33%