UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

38 lines (37 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = map; const isObject = (value) => typeof value === 'object' && value !== null; const isObjectCustom = (value) => isObject(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date) && !(globalThis.Blob && value instanceof globalThis.Blob); function map(object, mapper, isSeen = new WeakSet()) { if (isSeen.has(object)) { return; } isSeen.add(object); const mapArray = (array) => { for (const element of array) { mapper(element); if (isObject(element)) { map(element, mapper, isSeen); } } }; if (Array.isArray(object)) { mapArray(object); } for (const value of Object.values(object)) { mapper(value); if (isObjectCustom(value)) { if (Array.isArray(value)) { mapArray(value); } else { map(value, mapper, isSeen); } } } }