Skip to content

Commit

Permalink
feat: add validate async api
Browse files Browse the repository at this point in the history
  • Loading branch information
sidwebworks committed Jul 19, 2022
1 parent a6eb172 commit 1c76393
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ function createValidator(workbook: WorkBook, opts?: ValidatorOptions) {
}
}

const validateAsync = (schema: ZodSchema): Promise<Result> => {
const result = rows.map((row) => parse(row, schema))

return Promise.resolve({
valid: result.filter((r) => r.isValid),
invalid: result.filter((r) => !r.isValid),
})
}

const validate = (schema: ZodSchema): Result => {
const result = rows.map((row) => parse(row, schema))

Expand All @@ -49,7 +58,7 @@ function createValidator(workbook: WorkBook, opts?: ValidatorOptions) {
}
}

return { validate, rows, header }
return { validate, rows, header, validateAsync }
}

export { createValidator }

0 comments on commit 1c76393

Please sign in to comment.