const URL = (typeof window === 'undefined') ? require('url-parse') : window.URL; exports.toArchiveOrigin = function toArchiveOrigin (v) { if (v) { if (typeof v.getRecordOrigin === 'function') { return v.getRecordOrigin(); } if (typeof v.url === 'string') { v = v.url; } const urlp = new URL(v); return urlp.protocol + '//' + urlp.hostname; } throw new Error('Not a valid archive'); };