Skip to content

Instantly share code, notes, and snippets.

@booya2nd
booya2nd / mock-esmodule.js
Last active September 28, 2023 12:50
mockESModule workaround for JEST 29.x
import * as path from 'path';
import * as url from 'url';
function forEachDeep(obj, cb, options = { depth: 6 }) {
(function walk(value, property = undefined, parent = null, objPath = []) {
return value && typeof value === 'object' && objPath.length <= options.depth
? Object.entries(value).forEach(([key, val]) =>
walk(val, key, value, [...objPath, key])
)
: cb([property, value], parent, objPath);
@booya2nd
booya2nd / random-scratches.es6
Last active September 18, 2024 11:31
Collection of quick try-outs and silly random experiments
const print = x => console.log(JSON.stringify(x, null, 2));
const animals = [
{ value: 'mammals', parent: 'animals' },
{ value: 'animals', parent: null },
{ value: 'poodle', parent: 'dogs' },
{ value: 'dogs', parent: 'mammals' },
{ value: 'labrador',parent: 'dogs' },
{ value: 'siamese', parent: 'cats' },
{ value: 'cats', parent: 'mammals' },