Skip to content

Commit

Permalink
Check for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovepixelart committed May 9, 2024
1 parent 5564204 commit a9486cb
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import mongoose from 'mongoose'
export const isMongooseLessThan7 = satisfies(mongoose.version, '<7')

export const convertToObject = (value: unknown): unknown => {
if (isMongooseLessThan7) {
if (value != null && typeof value === 'object' && !Array.isArray(value) && value.toObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return value.toObject()
}
if (Array.isArray(value)) {
return value.map((doc) => convertToObject(doc))
}
if (value != null && typeof value === 'object' && !Array.isArray(value) && value.toObject) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
return value.toObject()
}
if (Array.isArray(value)) {
return value.map((doc) => convertToObject(doc))
}

return value
Expand Down

0 comments on commit a9486cb

Please sign in to comment.