<reponame>Silveeny/TwitterSocial-Battle<filename>frontend/node_modules/original/node_modules/url-parse/fuzzy.js<gh_stars>0'use strict';

var URL = require('./')
  , url = new URL('');

/**
 * A dictionary with all kind of different options that should generate a valid
 * and parse-able URL.
 *
 * @type {Object}
 * @api private
 */
var combinations = {};

combinations.protocol = [
  'http:',
  'https:',
  'ws:',
  'wss:',
  'blob:'/*,
  ''*/
];
combinations.username = ['foo', 'bar'];
combinations.password = combinations.username;
combinations.hostname = [
  'example.com',
  'www.example.com',
  'travel.travel',
  'sub.sub.sub.domain.nl',
  'xn--n3h.com',
  'localhost',
  '127.0.0.1',
  '255.255.255.255'/*,
  'fdf8:f53e:61e4::18',
  'fdf8:f53e:61e4::18:57ab',
  'fc00:db20:35b:7399::5:1428:57ab',
  'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b',
  'fdf8:f53e:61e4::18:57ab',
  'fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b',
  'fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b',
  'fc00:db20:35b:7399::5'*/
];
combinations.port = ['8080', '844', '3340'];
combinations.pathname = [
  '/',
  '/bar',
  '/bar/',
  '/foo/bar',
  '/foo.bar/foo',
  '/fav.ico',
  '/@3rd-Eden',
  '/a/b/c/d/e/f/g/j/1/d/4/'
];
combinations.query = ['foo=bar',
  'foo[]=bar&foo[]=foo',
  'efpyi@example.com',
  'q='
];
combinations.hash = [
  'name',
  'moo-with-longer-name',
  '/what/about/slashes?querystring',
  '?querystring',
  '!/google/urls',
  'use:foo@',
  'http://'
];

/**
 * Get a random item from the given array.
 *
 * @param {String} name Name of the array we want to have a random item returned.
 * @returns {Mixed}
 * @api private
 */
function get(name) {
  var data = combinations[name];

  return data[Math.floor(Math.random() * data.length)];
}

/**
 * Return a random boolean.
 *
 * @returns {Boolean}
 * @api private
 */
function yep() {
  return !!Math.round(Math.random() * 1);
}

/**
 * Generate the actual URL.
 *
 * @returns {Object} specification
 * @api public
 */
module.exports = function generate() {
  var spec = {}
    , key;

  spec.protocol = get('protocol');
  spec.hostname = get('hostname');
  spec.pathname = get('pathname');

  if (yep()) spec.port = get('port');
  if (yep()) spec.query = '?'+ get('query');
  if (yep()) spec.hash = '#'+ get('hash');
  if (yep()) {
    spec.username = get('username');
    spec.password = get('password');
  }

  for (key in combinations) {
    url[key] = '';
  }

  for (key in spec) {
    url[key] = spec[key];
  }

  spec.href = url.toString();
  return spec;
};
