Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
docs.forEach(function (doc) {
contents.push({ doc: JSON.stringify(doc, undefined, 2)
, _id: util.isDate(doc._id) ? doc._id.toISOString() : doc._id }); // The "edit" page needs to be given Date-type _ids in ISO format or it won't find them
});
function areThingsEqual (a, b) {
var aKeys , bKeys , i;
// Strings, booleans, numbers, null
if (a === null || typeof a === 'string' || typeof a === 'boolean' || typeof a === 'number' ||
b === null || typeof b === 'string' || typeof b === 'boolean' || typeof b === 'number') { return a === b; }
// Dates
if (util.isDate(a) || util.isDate(b)) { return util.isDate(a) && util.isDate(b) && a.getTime() === b.getTime(); }
// Arrays (no match since arrays are used as a $in)
// undefined (no match since they mean field doesn't exist and can't be serialized)
if (util.isArray(a) || util.isArray(b) || a === undefined || b === undefined) { return false; }
// General objects (check for deep equality)
// a and b should be objects at this point
try {
aKeys = Object.keys(a);
bKeys = Object.keys(b);
} catch (e) {
return false;
}
if (aKeys.length !== bKeys.length) { return false; }
for (i = 0; i < aKeys.length; i += 1) {
return typeof a === 'string' ? compareStrings(a, b) : 1;
}
// Booleans
if (typeof a === 'boolean') {
return typeof b === 'boolean' ? compareNSB(a, b) : -1;
}
if (typeof b === 'boolean') {
return typeof a === 'boolean' ? compareNSB(a, b) : 1;
}
// Dates
if (util.isDate(a)) {
return util.isDate(b) ? compareNSB(a.getTime(), b.getTime()) : -1;
}
if (util.isDate(b)) {
return util.isDate(a) ? compareNSB(a.getTime(), b.getTime()) : 1;
}
// Arrays (first element is most significant and so on)
if (util.isArray(a)) {
return util.isArray(b) ? compareArrays(a, b) : -1;
}
if (util.isArray(b)) {
return util.isArray(a) ? compareArrays(a, b) : 1;
}
// Objects
aKeys = Object.keys(a).sort();
bKeys = Object.keys(b).sort();
for (i = 0; i < Math.min(aKeys.length, bKeys.length); i += 1) {
function areThingsEqual (a, b) {
var aKeys , bKeys , i;
// Strings, booleans, numbers, null
if (a === null || typeof a === 'string' || typeof a === 'boolean' || typeof a === 'number' ||
b === null || typeof b === 'string' || typeof b === 'boolean' || typeof b === 'number') { return a === b; }
// Dates
if (util.isDate(a) || util.isDate(b)) { return util.isDate(a) && util.isDate(b) && a.getTime() === b.getTime(); }
// Arrays (no match since arrays are used as a $in)
// undefined (no match since they mean field doesn't exist and can't be serialized)
if (util.isArray(a) || util.isArray(b) || a === undefined || b === undefined) { return false; }
// General objects (check for deep equality)
// a and b should be objects at this point
try {
aKeys = Object.keys(a);
bKeys = Object.keys(b);
} catch (e) {
return false;
}
if (aKeys.length !== bKeys.length) { return false; }
for (i = 0; i < aKeys.length; i += 1) {
function _deepEqual(actual, expected, strict) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if (actual instanceof Buffer && expected instanceof Buffer) {
return compare(actual, expected) === 0;
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (util.isDate(actual) && util.isDate(expected)) {
return actual.getTime() === expected.getTime();
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source and
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
} else if (util.isRegExp(actual) && util.isRegExp(expected)) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase;
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if ((actual === null || typeof actual !== 'object') &&
(expected === null || typeof expected !== 'object')) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if (util.isBuffer(actual) && util.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
if (actual[i] !== expected[i]) return false;
}
return true;
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (util.isDate(actual) && util.isDate(expected)) {
return actual.getTime() === expected.getTime();
// 7.3 If the expected value is a RegExp object, the actual value is
// equivalent if it is also a RegExp object with the same source and
// properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
} else if (util.isRegExp(actual) && util.isRegExp(expected)) {
return actual.source === expected.source &&
actual.global === expected.global &&
actual.multiline === expected.multiline &&
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase;
// 7.4. Other pairs that do not both pass typeof value == 'object',
// equivalence is determined by ==.
} else if (!util.isObject(actual) && !util.isObject(expected)) {
return actual == expected;
function toUnixTimestamp(time) {
// eslint-disable-next-line eqeqeq
if (typeof time === 'string' && +time == time) {
return +time;
}
if (Number.isFinite(time)) {
if (time < 0) {
return Date.now() / 1000;
}
return time;
}
if (util.isDate(time)) {
// convert to 123.456 UNIX timestamp
return time.getTime() / 1000;
}
throw new Error('Cannot parse time: ' + time);
}
ofType: function (a, e) {
var type = typeof a;
//#JSCOVERAGE_IF typeof /a/ === 'function'
// webkit (incorrectly?) reports regexes as functions. Normalize this to 'object'.
if (type === 'function' && a.constructor === RegExp) {
type = 'object';
}
//#JSCOVERAGE_ENDIF
switch (e.toLowerCase()) {
case 'array' :
return util.isArray(a);
case 'date' :
return util.isDate(a);
case 'regexp' :
return util.isRegExp(a);
default :
return type === e;
}
},
matches: function (a, m) {
value: function (v) {
if (v === null) {
return null;
} else if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || v instanceof ObjectID) {
return v;
} else if (util.isDate(v)) {
return moment(v).utc().format('YYYY-MM-DD HH:mm:ss');
} else if (util.isArray(v)) {
if (v.length === 0) {
return v;
} else {
return v.map(function (item) {
return GCP.BigQueryTable.value(item);
}).filter(function (item) {
return item !== null;
});
}
} else {
return JSON.stringify(v);
}
},
function isPrimitiveType (obj) {
return ( typeof obj === 'boolean' ||
typeof obj === 'number' ||
typeof obj === 'string' ||
obj === null ||
util.isDate(obj) ||
util.isArray(obj));
}