How to use the whatwg-url.parseURL function in whatwg-url

To help you get started, we’ve selected a few whatwg-url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / helpers / stylesheets.js View on Github external
function scanForImportRules(elementImpl, cssRules, baseURL) {
  if (!cssRules) {
    return;
  }

  for (let i = 0; i < cssRules.length; ++i) {
    if (cssRules[i].cssRules) {
      // @media rule: keep searching inside it.
      scanForImportRules(elementImpl, cssRules[i].cssRules, baseURL);
    } else if (cssRules[i].href) {
      // @import rule: fetch the resource and evaluate it.
      // See http://dev.w3.org/csswg/cssom/#css-import-rule
      //     If loading of the style sheet fails its cssRules list is simply
      //     empty. I.e. an @import rule always has an associated style sheet.
      const parsed = whatwgURL.parseURL(cssRules[i].href, { baseURL });
      if (parsed === null) {
        const window = elementImpl._ownerDocument._defaultView;
        if (window) {
          const error = new Error(`Could not parse CSS @import URL ${cssRules[i].href} relative to base URL ` +
                                  `"${whatwgURL.serializeURL(baseURL)}"`);
          error.type = "css @import URL parsing";
          window._virtualConsole.emit("jsdomError", error);
        }
      } else {
        fetchStylesheetInternal(elementImpl, whatwgURL.serializeURL(parsed), parsed);
      }
    }
  }
}
github open-wc / open-wc / packages / building-utils / forked-babel-plugin-bare-import-rewrite.js View on Github external
function absResolve(importPath, sourceFileName, pluginOptions = {}) {
  if (whatwgUrl.parseURL(importPath) !== null) {
    return importPath;
  }

  const result = resolve.sync(importPath, {
    basedir: basedirResolve(importPath, sourceFileName, pluginOptions),
    extensions: pluginOptions.extensions || ['.mjs', '.js', 'json'],
    moduleDirectory: pluginOptions.resolveDirectories || 'node_modules',
    preserveSymlinks: false,
    packageFilter(packageJson) {
      packageJson.main = packageJson.module || packageJson['jsnext:main'] || packageJson.main;
      return packageJson;
    },
  });

  // use node's resolve to convert symlinks to real paths
  return require.resolve(result);
github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / helpers / document-base-url.js View on Github external
exports.parseURLToResultingURLRecord = (url, document) => {
  // https://html.spec.whatwg.org/#resolve-a-url

  // Encoding stuff ignored; always UTF-8 for us, for now.

  const baseURL = exports.documentBaseURL(document);

  return whatwgURL.parseURL(url, { baseURL });
  // This returns the resulting URL record; to get the resulting URL string, just serialize it.
};
github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / nodes / HTMLFrameElement-impl.js View on Github external
// close calls delete on its document.
      frame._contentDocument._defaultView.close();
    } else {
      delete frame._contentDocument;
    }
  }

  const parentDoc = frame._ownerDocument;

  // https://html.spec.whatwg.org/#process-the-iframe-attributes
  let url;
  const srcAttribute = getAttributeValue(frame, "src");
  if (srcAttribute === "") {
    url = parseURL("about:blank");
  } else {
    url = parseURL(srcAttribute, { baseURL: documentBaseURL(parentDoc) || undefined }) || parseURL("about:blank");
  }
  const serializedURL = serializeURL(url);

  // This is not great, but prevents a require cycle during webidl2js generation
  const wnd = new parentDoc._defaultView.constructor({
    parsingMode: "html",
    url: url.scheme === "javascript" || serializedURL === "about:blank" ? parentDoc.URL : serializedURL,
    resourceLoader: parentDoc._customResourceLoader,
    userAgent: parentDoc._defaultView.navigator.userAgent,
    referrer: parentDoc.URL,
    cookieJar: parentDoc._cookieJar,
    pool: parentDoc._pool,
    encoding: parentDoc._encoding,
    agentOptions: parentDoc._agentOptions,
    strictSSL: parentDoc._strictSSL,
    proxy: parentDoc._proxy,
github flaviuse / mern-authentication / client / node_modules / jsdom / lib / jsdom / living / nodes / HTMLFrameElement-impl.js View on Github external
if (frame._contentDocument) {
    if (frame._contentDocument._defaultView) {
      // close calls delete on its document.
      frame._contentDocument._defaultView.close();
    } else {
      delete frame._contentDocument;
    }
  }

  const parentDoc = frame._ownerDocument;

  // https://html.spec.whatwg.org/#process-the-iframe-attributes
  let url;
  const srcAttribute = getAttributeValue(frame, "src");
  if (srcAttribute === "") {
    url = parseURL("about:blank");
  } else {
    url = parseURL(srcAttribute, { baseURL: documentBaseURL(parentDoc) || undefined }) || parseURL("about:blank");
  }
  const serializedURL = serializeURL(url);

  // This is not great, but prevents a require cycle during webidl2js generation
  const wnd = new parentDoc._defaultView.constructor({
    parsingMode: "html",
    url: url.scheme === "javascript" || serializedURL === "about:blank" ? parentDoc.URL : serializedURL,
    resourceLoader: parentDoc._customResourceLoader,
    userAgent: parentDoc._defaultView.navigator.userAgent,
    referrer: parentDoc.URL,
    cookieJar: parentDoc._cookieJar,
    pool: parentDoc._pool,
    encoding: parentDoc._encoding,
    agentOptions: parentDoc._agentOptions,
github sx1989827 / DOClever / node_modules / jsdom / lib / jsdom / living / nodes / Document-impl.js View on Github external
this._global = privateData.options.global;
    this._documentElement = null;
    this._ids = Object.create(null);
    this._attached = true;
    this._currentScript = null;
    this._cookieJar = privateData.options.cookieJar;
    this._parseOptions = privateData.options.parseOptions;
    if (this._cookieJar === undefined) {
      this._cookieJar = new CookieJar(null, { looseMode: true });
    }

    this.contentType = privateData.options.contentType;
    this._encoding = privateData.options.encoding;

    const urlOption = privateData.options.url === undefined ? "about:blank" : privateData.options.url;
    const parsed = whatwgURL.parseURL(urlOption);
    if (parsed === null) {
      throw new TypeError(`Could not parse "${urlOption}" as a URL`);
    }

    this._URL = parsed;
    this.origin = whatwgURL.serializeURLOrigin(parsed);

    this._location = Location.createImpl([], { relevantDocument: this });
    this._history = History.createImpl([], {
      window: this._defaultView,
      document: this,
      actAsIfLocationReloadCalled: () => this._location.reload()
    });

    if (privateData.options.cookie) {
      const cookies = Array.isArray(privateData.options.cookie) ?
github cfware / babel-plugin-bare-import-rewrite / index.js View on Github external
function tryResolve(babelPath, importPath, sourceFileName, pluginOptions) {
	if (whatwgUrl.parseURL(importPath) !== null) {
		return importPath;
	}

	if (arrify(pluginOptions.ignorePrefixes).some(ignore => importPath.startsWith(ignore))) {
		return importPath;
	}

	try {
		const importPathAbs = absResolve(importPath, sourceFileName, pluginOptions);
		const nodeModules = path.resolve(pluginOptions.rootBaseDir || process.cwd(), 'node_modules');
		const isNodeModule = pathIsInside(importPathAbs, nodeModules);
		const fromNodeModule = pathIsInside(path.resolve(sourceFileName), nodeModules);
		let importPathRel = path.relative(path.dirname(sourceFileName), importPathAbs);
		const sep = pluginOptions.fsPath === true ? path.sep : path.posix.sep;

		const {modulesDir} = pluginOptions;
github sx1989827 / DOClever / node_modules / jsdom / lib / jsdom / living / helpers / form-controls.js View on Github external
exports.isValidAbsoluteURL = url => {
  return whatwgURL.parseURL(url) !== null;
};
github sx1989827 / DOClever / node_modules / jsdom / lib / jsdom / living / websockets / WebSocket-impl.js View on Github external
constructor(constructorArgs, privateData) {
    super([], privateData);
    const { window } = privateData;
    this._ownerDocument = idlUtils.implForWrapper(window._document);

    const url = constructorArgs[0];
    let protocols = constructorArgs[1] !== undefined ? constructorArgs[1] : [];

    const urlRecord = parseURL(url);
    if (urlRecord === null) {
      throw new DOMException(`The URL '${url}' is invalid.`, "SyntaxError");
    }
    if (urlRecord.scheme !== "ws" && urlRecord.scheme !== "wss") {
      throw new DOMException(
        `The URL's scheme must be either 'ws' or 'wss'. '${urlRecord.scheme}' is not allowed.`,
        "SyntaxError"
      );
    }
    if (urlRecord.fragment !== null) {
      throw new DOMException(`The URL contains a fragment identifier ('${urlRecord.fragment}'). Fragment identifiers ` +
                             "are not allowed in WebSocket URLs.", "SyntaxError");
    }

    if (typeof protocols === "string") {
      protocols = [protocols];
github jsdom / jsdom / lib / jsdom / browser / resources / resource-loader.js View on Github external
fetch(urlString, options = {}) {
    const url = parseURL(urlString);

    if (!url) {
      return Promise.reject(new Error(`Tried to fetch invalid URL ${urlString}`));
    }

    switch (url.scheme) {
      case "data": {
        return Promise.resolve(dataURLFromRecord(url).body);
      }

      case "http":
      case "https": {
        const requestOptions = this._getRequestOptions(options);
        return request(urlString, requestOptions);
      }