Skip to content

Commit 9f41bb0

Browse files
author
alxndrsn
committed
extract function, make null check stricter
1 parent f270bd1 commit 9f41bb0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/node_modules/pouchdb-core/src/adapter.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ function attachmentNameError(name) {
190190
return false;
191191
}
192192

193+
function isNotSingleDoc(doc) {
194+
return doc === null || typeof doc !== 'object' || Array.isArray(doc);
195+
}
196+
193197
function isValidRev(rev) {
194198
return typeof rev === 'string' && /^\d+-/.test(rev);
195199
}
@@ -201,7 +205,7 @@ class AbstractPouchDB extends EventEmitter {
201205
callback = opts;
202206
opts = {};
203207
}
204-
if (doc == null || typeof doc !== 'object' || Array.isArray(doc)) {
208+
if (isNotSingleDoc(doc)) {
205209
return callback(createError(NOT_AN_OBJECT));
206210
}
207211
this.bulkDocs({docs: [doc]}, opts, yankError(callback, doc._id));
@@ -212,7 +216,7 @@ class AbstractPouchDB extends EventEmitter {
212216
cb = opts;
213217
opts = {};
214218
}
215-
if (doc == null || typeof doc !== 'object' || Array.isArray(doc)) {
219+
if (isNotSingleDoc(doc)) {
216220
return cb(createError(NOT_AN_OBJECT));
217221
}
218222
invalidIdError(doc._id);
@@ -785,7 +789,7 @@ class AbstractPouchDB extends EventEmitter {
785789
}
786790

787791
for (var i = 0; i < req.docs.length; ++i) {
788-
if (req.docs[i] == null || typeof req.docs[i] !== 'object' || Array.isArray(req.docs[i])) {
792+
if (isNotSingleDoc(req.docs[i])) {
789793
return callback(createError(NOT_AN_OBJECT));
790794
}
791795
}

0 commit comments

Comments
 (0)