UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

27 lines (26 loc) 831 B
import { isObject, max, measureText } from "../../util/index.js"; import { ellipses } from "../util.js"; export function isEmpty(obj) { return Object.keys(obj).length === 0; } export function generateTitle(name, id, type) { return [ellipses(`${name || id || ''}`), `${type}`] .filter(f => !!f) .join(' - '); } export function generateMaxWidth(array, prefix) { return (Math.ceil(max(array.map(key => measureText([...prefix, key[0]].join('.'), 12)))) + 10); } export function accessNested(arr, obj = {}) { let obj2 = obj; for (const elt of arr) { if (isObject(obj2)) { obj2 = obj2[elt]; } } return typeof obj2 === 'string' ? obj2 : isObject(obj2) && typeof obj2.Description === 'string' ? obj2.Description : undefined; }