3 // customized for this use-case
5 typeof x === 'object' &&
7 !(x instanceof RegExp) &&
8 !(x instanceof Error) &&
11 module.exports = function mapObj(obj, fn, opts, seen) {
12 opts = Object.assign({
17 seen = seen || new WeakMap();
23 seen.set(obj, opts.target);
25 const target = opts.target;
28 for (const key of Object.keys(obj)) {
30 const res = fn(key, val, obj);
33 if (opts.deep && isObject(newVal)) {
34 if (Array.isArray(newVal)) {
35 newVal = newVal.map(x => isObject(x) ? mapObj(x, fn, opts, seen) : x);
37 newVal = mapObj(newVal, fn, opts, seen);
41 target[res[0]] = newVal;