Skip to content

Commit

Permalink
extract function, make null check stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Apr 13, 2024
1 parent f270bd1 commit 9f41bb0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/node_modules/pouchdb-core/src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ function attachmentNameError(name) {
return false;
}

function isNotSingleDoc(doc) {
return doc === null || typeof doc !== 'object' || Array.isArray(doc);
}

function isValidRev(rev) {
return typeof rev === 'string' && /^\d+-/.test(rev);
}
Expand All @@ -201,7 +205,7 @@ class AbstractPouchDB extends EventEmitter {
callback = opts;
opts = {};
}
if (doc == null || typeof doc !== 'object' || Array.isArray(doc)) {
if (isNotSingleDoc(doc)) {
return callback(createError(NOT_AN_OBJECT));
}
this.bulkDocs({docs: [doc]}, opts, yankError(callback, doc._id));
Expand All @@ -212,7 +216,7 @@ class AbstractPouchDB extends EventEmitter {
cb = opts;
opts = {};
}
if (doc == null || typeof doc !== 'object' || Array.isArray(doc)) {
if (isNotSingleDoc(doc)) {
return cb(createError(NOT_AN_OBJECT));
}
invalidIdError(doc._id);
Expand Down Expand Up @@ -785,7 +789,7 @@ class AbstractPouchDB extends EventEmitter {
}

for (var i = 0; i < req.docs.length; ++i) {
if (req.docs[i] == null || typeof req.docs[i] !== 'object' || Array.isArray(req.docs[i])) {
if (isNotSingleDoc(req.docs[i])) {
return callback(createError(NOT_AN_OBJECT));
}
}
Expand Down

0 comments on commit 9f41bb0

Please sign in to comment.