Skip to content

Instantly share code, notes, and snippets.

import { isArray, isObject, mapValues } from 'lodash-es'
import type { Document } from 'mongodb'
const mapValuesDeep = <T>(obj: T, cb: any): unknown => {
if (isArray(obj)) {
return obj.map(innerObj => mapValuesDeep(innerObj, cb))
} else if (isObject(obj)) {
if (!('toHexString' in obj || 'getDay' in obj)) {
return mapValues(obj, val => mapValuesDeep(val, cb))
} else {
var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
function check_serializability(value, id, path) {
const type = typeof value;
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'undefined') {
// primitives are fine
return;
}
var ObjectId = require('bson-objectid')
function check_serializability(value, id, path) {
const type = typeof value;
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'undefined') {
// primitives are fine
return;
}