<commit_before>/* globals module, URL */

import { hasDOM } from '@ember/-internals/browser-environment';
import { IS_NODE, require } from 'node-module';
import Environment from './environment';

let nodeURL: any;
let parsingNode: HTMLAnchorElement;

export default function installProtocolForURL(environment: Environment) {
  let protocol;

  if (hasDOM) {
    protocol = browserProtocolForURL.call(environment, 'foobar:baz');
  }

  // Test to see if our DOM implementation parses
  // and normalizes URLs.
  if (protocol === 'foobar:') {
    // Swap in the method that doesn't do this test now that
    // we know it works.
    environment.protocolForURL = browserProtocolForURL;
  } else if (typeof URL === 'object') {
    // URL globally provided, likely from FastBoot's sandbox
    nodeURL = URL;
    environment.protocolForURL = nodeProtocolForURL;
  } else if (IS_NODE) {
    // Otherwise, we need to fall back to our own URL parsing.
    // Global `require` is shadowed by Ember's loader so we have to use the fully
    // qualified `module.require`.

    // tslint:disable-next-line:no-require-imports
    nodeURL = require('url');<commit_msg>Use bare `require` in conditional URL import<commit_after>/* globals module, URL */

import { hasDOM } from '@ember/-internals/browser-environment';
import Environment from './environment';

let nodeURL: any;
let parsingNode: HTMLAnchorElement;

export default function installProtocolForURL(environment: Environment) {
  let protocol;

  if (hasDOM) {
    protocol = browserProtocolForURL.call(environment, 'foobar:baz');
  }

  // Test to see if our DOM implementation parses
  // and normalizes URLs.
  if (protocol === 'foobar:') {
    // Swap in the method that doesn't do this test now that
    // we know it works.
    environment.protocolForURL = browserProtocolForURL;
  } else if (typeof URL === 'object') {
    // URL globally provided, likely from FastBoot's sandbox
    nodeURL = URL;
    environment.protocolForURL = nodeProtocolForURL;
  } else if (typeof require === 'function') {
    // Otherwise, we need to fall back to our own URL parsing.
    // Global `require` is shadowed by Ember's loader so we have to use the fully
    // qualified `module.require`.

    // tslint:disable-next-line:no-require-imports
    nodeURL = require('url');
{'fraction_non_alphanumeric': 0.10904370402423194, 'fraction_numerical': 0.0, 'mean_word_length': 3.569169960474308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5829058', 'n_tokens_mistral': 673, 'n_tokens_neox': 643, 'n_words': 232}