Unverified Commit 8bc370c8 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #1680 from hypothesis/convert-annotator-to-es-modules

Convert most modules in src/annotator to ES modules
parents d78c29cd fac2a28d
/* global PDFViewerApplication */ /* global PDFViewerApplication */
const seek = require('dom-seek'); import seek from 'dom-seek';
// `dom-node-iterator` polyfills optional arguments of `createNodeIterator` // `dom-node-iterator` polyfills optional arguments of `createNodeIterator`
// and properties of the returned `NodeIterator` for IE 11 compatibility. // and properties of the returned `NodeIterator` for IE 11 compatibility.
const createNodeIterator = require('dom-node-iterator/polyfill')(); const createNodeIterator = require('dom-node-iterator/polyfill')();
const xpathRange = require('./range'); import RenderingStates from '../pdfjs-rendering-states';
const RenderingStates = require('../pdfjs-rendering-states');
const { TextPositionAnchor, TextQuoteAnchor } = require('./types'); import xpathRange from './range';
const { toRange: textPositionToRange } = require('./text-position'); import { toRange as textPositionToRange } from './text-position';
import { TextPositionAnchor, TextQuoteAnchor } from './types';
// Caches for performance. // Caches for performance.
...@@ -342,7 +343,7 @@ function prioritizePages(position) { ...@@ -342,7 +343,7 @@ function prioritizePages(position) {
* @param {Array} selectors - Selector objects to anchor * @param {Array} selectors - Selector objects to anchor
* @return {Promise<Range>} * @return {Promise<Range>}
*/ */
function anchor(root, selectors) { export function anchor(root, selectors) {
const position = selectors.find(s => s.type === 'TextPositionSelector'); const position = selectors.find(s => s.type === 'TextPositionSelector');
const quote = selectors.find(s => s.type === 'TextQuoteSelector'); const quote = selectors.find(s => s.type === 'TextQuoteSelector');
...@@ -406,7 +407,7 @@ function anchor(root, selectors) { ...@@ -406,7 +407,7 @@ function anchor(root, selectors) {
* `toSelector` methods. * `toSelector` methods.
* @return {Promise<[TextPositionSelector, TextQuoteSelector]>} * @return {Promise<[TextPositionSelector, TextQuoteSelector]>}
*/ */
function describe(root, range, options = {}) { export function describe(root, range, options = {}) {
const normalizedRange = new xpathRange.BrowserRange(range).normalize(); const normalizedRange = new xpathRange.BrowserRange(range).normalize();
const startTextLayer = getNodeTextLayer(normalizedRange.start); const startTextLayer = getNodeTextLayer(normalizedRange.start);
...@@ -461,13 +462,7 @@ function describe(root, range, options = {}) { ...@@ -461,13 +462,7 @@ function describe(root, range, options = {}) {
* *
* This exists mainly as a helper for use in tests. * This exists mainly as a helper for use in tests.
*/ */
function purgeCache() { export function purgeCache() {
pageTextCache = {}; pageTextCache = {};
quotePositionCache = {}; quotePositionCache = {};
} }
module.exports = {
anchor,
describe,
purgeCache,
};
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* each of the relevant classes in PDF.js. * each of the relevant classes in PDF.js.
*/ */
const RenderingStates = require('../../pdfjs-rendering-states'); import RenderingStates from '../../pdfjs-rendering-states';
/** /**
* Create the DOM structure for a page which matches the structure produced by * Create the DOM structure for a page which matches the structure produced by
...@@ -197,7 +197,7 @@ class FakePDFViewer { ...@@ -197,7 +197,7 @@ class FakePDFViewer {
* *
* The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js * The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js
*/ */
class FakePDFViewerApplication { export default class FakePDFViewerApplication {
/** /**
* @param {Options} options * @param {Options} options
*/ */
...@@ -215,5 +215,3 @@ class FakePDFViewerApplication { ...@@ -215,5 +215,3 @@ class FakePDFViewerApplication {
this.pdfViewer.dispose(); this.pdfViewer.dispose();
} }
} }
module.exports = FakePDFViewerApplication;
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
// them as `<fixture name>.json` in this directory // them as `<fixture name>.json` in this directory
// 4. Add an entry to the fixture list below. // 4. Add an entry to the fixture list below.
module.exports = [ export default [
{ {
name: 'Minimal Document', name: 'Minimal Document',
html: require('./minimal.html'), html: require('./minimal.html'),
......
const html = require('../html'); import { toResult } from '../../../shared/test/promise-util';
import * as html from '../html';
const { toResult } = require('../../../shared/test/promise-util'); import fixture from './html-anchoring-fixture.html';
const fixture = require('./html-anchoring-fixture.html'); import htmlBaselines from './html-baselines';
/** Return all text node children of `container`. */ /** Return all text node children of `container`. */
function textNodes(container) { function textNodes(container) {
...@@ -419,7 +420,6 @@ describe('HTML anchoring', function() { ...@@ -419,7 +420,6 @@ describe('HTML anchoring', function() {
}); });
describe('Web page baselines', function() { describe('Web page baselines', function() {
const fixtures = require('./html-baselines');
let frame; let frame;
before(function() { before(function() {
...@@ -431,7 +431,7 @@ describe('HTML anchoring', function() { ...@@ -431,7 +431,7 @@ describe('HTML anchoring', function() {
frame.remove(); frame.remove();
}); });
fixtures.forEach(fixture => { htmlBaselines.forEach(fixture => {
it(`generates selectors which match the baseline ${fixture.name}`, () => { it(`generates selectors which match the baseline ${fixture.name}`, () => {
let fixtureHtml = fixture.html; let fixtureHtml = fixture.html;
const annotations = fixture.annotations.rows; const annotations = fixture.annotations.rows;
......
const domAnchorTextQuote = require('dom-anchor-text-quote'); import * as domAnchorTextQuote from 'dom-anchor-text-quote';
const FakePDFViewerApplication = require('./fake-pdf-viewer-application'); import * as pdfAnchoring from '../pdf';
const pdfAnchoring = require('../pdf');
import FakePDFViewerApplication from './fake-pdf-viewer-application';
/** /**
* Return a DOM Range which refers to the specified `text` in `container`. * Return a DOM Range which refers to the specified `text` in `container`.
......
const { toRange } = require('../text-position'); import { toRange } from '../text-position';
describe('text-position', () => { describe('text-position', () => {
let container; let container;
......
const types = require('../types'); import * as types from '../types';
const TextQuoteAnchor = types.TextQuoteAnchor; const TextQuoteAnchor = types.TextQuoteAnchor;
const TextPositionAnchor = types.TextPositionAnchor; const TextPositionAnchor = types.TextPositionAnchor;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* @param {number} end - Character offset within `root.textContent` * @param {number} end - Character offset within `root.textContent`
* @return {Range} Range spanning text from `start` to `end` * @return {Range} Range spanning text from `start` to `end`
*/ */
function toRange(root, start, end) { export function toRange(root, start, end) {
// The `filter` and `expandEntityReferences` arguments are mandatory in IE // The `filter` and `expandEntityReferences` arguments are mandatory in IE
// although optional according to the spec. // although optional according to the spec.
const nodeIter = root.ownerDocument.createNodeIterator( const nodeIter = root.ownerDocument.createNodeIterator(
...@@ -76,7 +76,3 @@ function toRange(root, start, end) { ...@@ -76,7 +76,3 @@ function toRange(root, start, end) {
return range; return range;
} }
module.exports = {
toRange,
};
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* @return {Object} - Any config settings returned by hypothesisConfig() * @return {Object} - Any config settings returned by hypothesisConfig()
* *
*/ */
function configFuncSettingsFrom(window_) { export default function configFuncSettingsFrom(window_) {
if (!window_.hasOwnProperty('hypothesisConfig')) { if (!window_.hasOwnProperty('hypothesisConfig')) {
return {}; return {};
} }
...@@ -30,5 +30,3 @@ function configFuncSettingsFrom(window_) { ...@@ -30,5 +30,3 @@ function configFuncSettingsFrom(window_) {
return window_.hypothesisConfig(); return window_.hypothesisConfig();
} }
module.exports = configFuncSettingsFrom;
const settingsFrom = require('./settings'); import settingsFrom from './settings';
/** /**
* Reads the Hypothesis configuration from the environment. * Reads the Hypothesis configuration from the environment.
* *
* @param {Window} window_ - The Window object to read config from. * @param {Window} window_ - The Window object to read config from.
*/ */
function configFrom(window_) { export default function configFrom(window_) {
const settings = settingsFrom(window_); const settings = settingsFrom(window_);
return { return {
annotations: settings.annotations, annotations: settings.annotations,
...@@ -44,5 +44,3 @@ function configFrom(window_) { ...@@ -44,5 +44,3 @@ function configFrom(window_) {
), ),
}; };
} }
module.exports = configFrom;
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
* website. * website.
* *
*/ */
function isBrowserExtension(app) { export default function isBrowserExtension(app) {
return !(app.startsWith('http://') || app.startsWith('https://')); return !(app.startsWith('http://') || app.startsWith('https://'));
} }
module.exports = isBrowserExtension;
const configFuncSettingsFrom = require('./config-func-settings-from'); import * as sharedSettings from '../../shared/settings';
const isBrowserExtension = require('./is-browser-extension');
const sharedSettings = require('../../shared/settings');
function settingsFrom(window_) { import configFuncSettingsFrom from './config-func-settings-from';
import isBrowserExtension from './is-browser-extension';
export default function settingsFrom(window_) {
const jsonConfigs = sharedSettings.jsonConfigsFrom(window_.document); const jsonConfigs = sharedSettings.jsonConfigsFrom(window_.document);
const configFuncSettings = configFuncSettingsFrom(window_); const configFuncSettings = configFuncSettingsFrom(window_);
...@@ -214,5 +215,3 @@ function settingsFrom(window_) { ...@@ -214,5 +215,3 @@ function settingsFrom(window_) {
hostPageSetting: hostPageSetting, hostPageSetting: hostPageSetting,
}; };
} }
module.exports = settingsFrom;
const configFuncSettingsFrom = require('../config-func-settings-from'); import configFuncSettingsFrom from '../config-func-settings-from';
describe('annotator.config.configFuncSettingsFrom', function() { describe('annotator.config.configFuncSettingsFrom', function() {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
......
const configFrom = require('../index'); import configFrom from '../index';
const { $imports } = require('../index'); import { $imports } from '../index';
describe('annotator.config.index', function() { describe('annotator.config.index', function() {
let fakeSettingsFrom; let fakeSettingsFrom;
......
const isBrowserExtension = require('../is-browser-extension'); import isBrowserExtension from '../is-browser-extension';
describe('annotator.config.isBrowserExtension', function() { describe('annotator.config.isBrowserExtension', function() {
[ [
......
const settingsFrom = require('../settings'); import settingsFrom from '../settings';
const { $imports } = require('../settings'); import { $imports } from '../settings';
describe('annotator.config.settingsFrom', function() { describe('annotator.config.settingsFrom', function() {
let fakeConfigFuncSettingsFrom; let fakeConfigFuncSettingsFrom;
......
const $ = require('jquery'); import $ from 'jquery';
// Load polyfill for :focus-visible pseudo-class. // Load polyfill for :focus-visible pseudo-class.
require('focus-visible'); import 'focus-visible';
const configFrom = require('./config/index'); import configFrom from './config/index';
const Guest = require('./guest'); import Guest from './guest';
const Sidebar = require('./sidebar'); import PdfSidebar from './pdf-sidebar';
const PdfSidebar = require('./pdf-sidebar'); import BucketBarPlugin from './plugin/bucket-bar';
import CrossFramePlugin from './plugin/cross-frame';
import DocumentPlugin from './plugin/document';
import PDFPlugin from './plugin/pdf';
import ToolbarPlugin from './plugin/toolbar';
import Sidebar from './sidebar';
const pluginClasses = { const pluginClasses = {
// UI plugins // UI plugins
BucketBar: require('./plugin/bucket-bar'), BucketBar: BucketBarPlugin,
Toolbar: require('./plugin/toolbar'), Toolbar: ToolbarPlugin,
// Document type plugins // Document type plugins
PDF: require('./plugin/pdf'), PDF: PDFPlugin,
Document: require('./plugin/document'), Document: DocumentPlugin,
// Cross-frame communication // Cross-frame communication
CrossFrame: require('./plugin/cross-frame'), CrossFrame: CrossFramePlugin,
}; };
const appLinkEl = document.querySelector( const appLinkEl = document.querySelector(
......
...@@ -10,16 +10,16 @@ ...@@ -10,16 +10,16 @@
** https://github.com/openannotation/annotator/blob/master/LICENSE ** https://github.com/openannotation/annotator/blob/master/LICENSE
*/ */
const baseURI = require('document-base-uri'); import baseURI from 'document-base-uri';
const Plugin = require('../plugin'); import Plugin from '../plugin';
const { normalizeURI } = require('../util/url'); import { normalizeURI } from '../util/url';
/** /**
* DocumentMeta reads metadata/links from the current HTML document and * DocumentMeta reads metadata/links from the current HTML document and
* populates the `document` property of new annotations. * populates the `document` property of new annotations.
*/ */
class DocumentMeta extends Plugin { export default class DocumentMeta extends Plugin {
constructor(element, options) { constructor(element, options) {
super(element, options); super(element, options);
...@@ -298,5 +298,3 @@ class DocumentMeta extends Plugin { ...@@ -298,5 +298,3 @@ class DocumentMeta extends Plugin {
return href; return href;
} }
} }
module.exports = DocumentMeta;
const { normalizeURI } = require('../util/url'); import { normalizeURI } from '../util/url';
/** /**
* @typedef Link * @typedef Link
...@@ -25,7 +25,7 @@ const { normalizeURI } = require('../util/url'); ...@@ -25,7 +25,7 @@ const { normalizeURI } = require('../util/url');
* // Do something with the URL of the PDF. * // Do something with the URL of the PDF.
* }) * })
*/ */
class PDFMetadata { export default class PDFMetadata {
/** /**
* Construct a `PDFMetadata` that returns URIs/metadata associated with a * Construct a `PDFMetadata` that returns URIs/metadata associated with a
* given PDF viewer. * given PDF viewer.
...@@ -126,5 +126,3 @@ function getPDFURL(app) { ...@@ -126,5 +126,3 @@ function getPDFURL(app) {
return null; return null;
} }
module.exports = PDFMetadata;
...@@ -9,7 +9,7 @@ module.exports = class PDF extends Plugin ...@@ -9,7 +9,7 @@ module.exports = class PDF extends Plugin
pluginInit: -> pluginInit: ->
@annotator.anchoring = require('../anchoring/pdf') @annotator.anchoring = require('../anchoring/pdf')
PDFMetadata = require('./pdf-metadata') { default: PDFMetadata } = require('./pdf-metadata')
@pdfViewer = PDFViewerApplication.pdfViewer @pdfViewer = PDFViewerApplication.pdfViewer
@pdfViewer.viewer.classList.add('has-transparent-text-layer') @pdfViewer.viewer.classList.add('has-transparent-text-layer')
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
** https://github.com/openannotation/annotator/blob/master/LICENSE ** https://github.com/openannotation/annotator/blob/master/LICENSE
*/ */
const $ = require('jquery'); import $ from 'jquery';
const DocumentMeta = require('../document'); import { normalizeURI } from '../../util/url';
const { normalizeURI } = require('../../util/url'); import DocumentMeta from '../document';
describe('DocumentMeta', function() { describe('DocumentMeta', function() {
let fakeNormalizeURI; let fakeNormalizeURI;
......
const PDFMetadata = require('../pdf-metadata'); import PDFMetadata from '../pdf-metadata';
/** /**
* Fake implementation of PDF.js `window.PDFViewerApplication.metadata`. * Fake implementation of PDF.js `window.PDFViewerApplication.metadata`.
......
const $ = require('jquery'); import $ from 'jquery';
const Toolbar = require('../toolbar'); import Toolbar from '../toolbar';
describe('Toolbar', () => { describe('Toolbar', () => {
let container; let container;
......
const adder = require('../adder'); import * as adder from '../adder';
function rect(left, top, width, height) { function rect(left, top, width, height) {
return { left: left, top: top, width: width, height: height }; return { left: left, top: top, width: width, height: height };
......
const annotationCounts = require('../annotation-counts'); import annotationCounts from '../annotation-counts';
describe('annotationCounts', function() { describe('annotationCounts', function() {
let countEl1; let countEl1;
......
const EventEmitter = require('tiny-emitter'); import EventEmitter from 'tiny-emitter';
const AnnotationSync = require('../annotation-sync'); import AnnotationSync from '../annotation-sync';
describe('AnnotationSync', function() { describe('AnnotationSync', function() {
let createAnnotationSync; let createAnnotationSync;
......
const events = require('../../shared/bridge-events'); import events from '../../shared/bridge-events';
const features = require('../features'); import features from '../features';
const { $imports } = require('../features'); import { $imports } from '../features';
describe('features - annotation layer', function() { describe('features - annotation layer', function() {
let featureFlagsUpdateHandler; let featureFlagsUpdateHandler;
......
const rangeUtil = require('../range-util'); import * as rangeUtil from '../range-util';
function createRange(node, start, end) { function createRange(node, start, end) {
const range = node.ownerDocument.createRange(); const range = node.ownerDocument.createRange();
......
const observable = require('../util/observable'); import selections from '../selections';
const selections = require('../selections'); import * as observable from '../util/observable';
function FakeDocument() { function FakeDocument() {
const listeners = {}; const listeners = {};
......
const sidebarTrigger = require('../sidebar-trigger'); import sidebarTrigger from '../sidebar-trigger';
describe('sidebarTrigger', function() { describe('sidebarTrigger', function() {
let triggerEl1; let triggerEl1;
......
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
* @param {Element} container * @param {Element} container
* @return {HTMLIFrameElement[]} * @return {HTMLIFrameElement[]}
*/ */
function findFrames(container) { export function findFrames(container) {
const frames = Array.from(container.getElementsByTagName('iframe')); const frames = Array.from(container.getElementsByTagName('iframe'));
return frames.filter(shouldEnableAnnotation); return frames.filter(shouldEnableAnnotation);
} }
// Check if the iframe has already been injected // Check if the iframe has already been injected
function hasHypothesis(iframe) { export function hasHypothesis(iframe) {
return iframe.contentWindow.__hypothesis_frame === true; return iframe.contentWindow.__hypothesis_frame === true;
} }
// Inject embed.js into the iframe // Inject embed.js into the iframe
function injectHypothesis(iframe, scriptUrl, config) { export function injectHypothesis(iframe, scriptUrl, config) {
const configElement = document.createElement('script'); const configElement = document.createElement('script');
configElement.className = 'js-hypothesis-config'; configElement.className = 'js-hypothesis-config';
configElement.type = 'application/json'; configElement.type = 'application/json';
...@@ -32,7 +32,7 @@ function injectHypothesis(iframe, scriptUrl, config) { ...@@ -32,7 +32,7 @@ function injectHypothesis(iframe, scriptUrl, config) {
} }
// Check if we can access this iframe's document // Check if we can access this iframe's document
function isAccessible(iframe) { export function isAccessible(iframe) {
try { try {
return !!iframe.contentDocument; return !!iframe.contentDocument;
} catch (e) { } catch (e) {
...@@ -63,7 +63,7 @@ function shouldEnableAnnotation(iframe) { ...@@ -63,7 +63,7 @@ function shouldEnableAnnotation(iframe) {
return isNotClientFrame && enabled; return isNotClientFrame && enabled;
} }
function isDocumentReady(iframe, callback) { export function isDocumentReady(iframe, callback) {
if (iframe.contentDocument.readyState === 'loading') { if (iframe.contentDocument.readyState === 'loading') {
iframe.contentDocument.addEventListener('DOMContentLoaded', function() { iframe.contentDocument.addEventListener('DOMContentLoaded', function() {
callback(); callback();
...@@ -73,7 +73,7 @@ function isDocumentReady(iframe, callback) { ...@@ -73,7 +73,7 @@ function isDocumentReady(iframe, callback) {
} }
} }
function isLoaded(iframe, callback) { export function isLoaded(iframe, callback) {
if (iframe.contentDocument.readyState !== 'complete') { if (iframe.contentDocument.readyState !== 'complete') {
iframe.addEventListener('load', function() { iframe.addEventListener('load', function() {
callback(); callback();
...@@ -82,12 +82,3 @@ function isLoaded(iframe, callback) { ...@@ -82,12 +82,3 @@ function isLoaded(iframe, callback) {
callback(); callback();
} }
} }
module.exports = {
findFrames: findFrames,
hasHypothesis: hasHypothesis,
injectHypothesis: injectHypothesis,
isAccessible: isAccessible,
isLoaded: isLoaded,
isDocumentReady: isDocumentReady,
};
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* values using the Observable API. * values using the Observable API.
*/ */
const Observable = require('zen-observable'); import Observable from 'zen-observable';
/** /**
* Returns an observable of events emitted by a DOM event source * Returns an observable of events emitted by a DOM event source
...@@ -12,7 +12,7 @@ const Observable = require('zen-observable'); ...@@ -12,7 +12,7 @@ const Observable = require('zen-observable');
* @param {EventTarget} src - The event source. * @param {EventTarget} src - The event source.
* @param {Array<string>} eventNames - List of events to subscribe to * @param {Array<string>} eventNames - List of events to subscribe to
*/ */
function listen(src, eventNames) { export function listen(src, eventNames) {
return new Observable(function(observer) { return new Observable(function(observer) {
const onNext = function(event) { const onNext = function(event) {
observer.next(event); observer.next(event);
...@@ -33,7 +33,7 @@ function listen(src, eventNames) { ...@@ -33,7 +33,7 @@ function listen(src, eventNames) {
/** /**
* Delay events from a source Observable by `delay` ms. * Delay events from a source Observable by `delay` ms.
*/ */
function delay(delay, src) { export function delay(delay, src) {
return new Observable(function(obs) { return new Observable(function(obs) {
let timeouts = []; let timeouts = [];
const sub = src.subscribe({ const sub = src.subscribe({
...@@ -62,7 +62,7 @@ function delay(delay, src) { ...@@ -62,7 +62,7 @@ function delay(delay, src) {
* @param {Observable<T>} src * @param {Observable<T>} src
* @return {Observable<T>} * @return {Observable<T>}
*/ */
function buffer(delay, src) { export function buffer(delay, src) {
return new Observable(function(obs) { return new Observable(function(obs) {
let lastValue; let lastValue;
let timeout; let timeout;
...@@ -92,7 +92,7 @@ function buffer(delay, src) { ...@@ -92,7 +92,7 @@ function buffer(delay, src) {
* @param {Array<Observable>} sources * @param {Array<Observable>} sources
* @return Observable * @return Observable
*/ */
function merge(sources) { export function merge(sources) {
return new Observable(function(obs) { return new Observable(function(obs) {
const subs = sources.map(function(src) { const subs = sources.map(function(src) {
return src.subscribe({ return src.subscribe({
...@@ -111,7 +111,7 @@ function merge(sources) { ...@@ -111,7 +111,7 @@ function merge(sources) {
} }
/** Drop the first `n` events from the `src` Observable. */ /** Drop the first `n` events from the `src` Observable. */
function drop(src, n) { export function drop(src, n) {
let count = 0; let count = 0;
return src.filter(function() { return src.filter(function() {
++count; ++count;
...@@ -119,11 +119,4 @@ function drop(src, n) { ...@@ -119,11 +119,4 @@ function drop(src, n) {
}); });
} }
module.exports = { export { Observable };
buffer: buffer,
delay: delay,
drop: drop,
listen: listen,
merge: merge,
Observable: Observable,
};
const baseURI = require('document-base-uri'); import baseURI from 'document-base-uri';
/** /**
* Return a normalized version of a URI. * Return a normalized version of a URI.
...@@ -9,7 +9,7 @@ const baseURI = require('document-base-uri'); ...@@ -9,7 +9,7 @@ const baseURI = require('document-base-uri');
* @param {string} [base] - Base URL to resolve relative to. Defaults to * @param {string} [base] - Base URL to resolve relative to. Defaults to
* the document's base URL. * the document's base URL.
*/ */
function normalizeURI(uri, base = baseURI) { export function normalizeURI(uri, base = baseURI) {
const absUrl = new URL(uri, base).href; const absUrl = new URL(uri, base).href;
// Remove the fragment identifier. // Remove the fragment identifier.
...@@ -18,7 +18,3 @@ function normalizeURI(uri, base = baseURI) { ...@@ -18,7 +18,3 @@ function normalizeURI(uri, base = baseURI) {
// See https://github.com/hypothesis/h/issues/3471#issuecomment-226713750 // See https://github.com/hypothesis/h/issues/3471#issuecomment-226713750
return absUrl.toString().replace(/#.*/, ''); return absUrl.toString().replace(/#.*/, '');
} }
module.exports = {
normalizeURI,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment