@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
35 lines (34 loc) • 1.13 kB
JavaScript
import { isUriLocation } from "../../util/index.js";
export const MAX_LABEL_LENGTH = 5;
export function isAdminMode() {
return (typeof window !== 'undefined' &&
new URLSearchParams(window.location.search).get('adminKey') !== null);
}
export function shorten(str) {
return str.length > MAX_LABEL_LENGTH
? `${str.slice(0, MAX_LABEL_LENGTH)}…`
: str;
}
export function getAccountLabel(account) {
const { toggleContents, name } = account;
if (toggleContents) {
return typeof toggleContents === 'string'
? shorten(toggleContents)
: toggleContents;
}
return shorten(name);
}
export function getInitialSourceType(location) {
if (location &&
'internetAccountId' in location &&
location.internetAccountId) {
return location.internetAccountId;
}
return !location || isUriLocation(location) ? 'url' : 'file';
}
export function addAccountToLocation(location, account) {
if (account && isUriLocation(location)) {
return { ...location, internetAccountId: account.internetAccountId };
}
return location;
}