Skip to content

Commit

Permalink
fix: remove extra promise allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
sidwebworks committed Jul 19, 2022
1 parent c687b65 commit a6eb172
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function createValidator(workbook: WorkBook, opts?: ValidatorOptions) {
header: options.header,
})

const parse = async (row: any, schema: ZodSchema) => {
const parse = (row: any, schema: ZodSchema) => {
const data = toObject(row, header)
try {
await schema.parseAsync(data)
schema.parse(data)
options.onValid && options.onValid(data)
return { issues: [], isValid: true, data }
} catch (error) {
Expand All @@ -40,10 +40,8 @@ function createValidator(workbook: WorkBook, opts?: ValidatorOptions) {
}
}

const validate = async (schema: ZodSchema): Promise<Result> => {
const promises = rows.map((row) => parse(row, schema))

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

return {
valid: result.filter((r) => r.isValid),
Expand Down

0 comments on commit a6eb172

Please sign in to comment.