Guest User

TF1 url-parse module

a guest
Jun 8th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. "0zbP": function(e, t, i) {
  2. "use strict";
  3. (function(r) {
  4. function f(e) {
  5. var t, n = {},
  6. i = typeof(e = e || r.location || {});
  7. if ("blob:" === e.protocol)
  8. n = new _(unescape(e.pathname), {});
  9. else if ("string" === i)
  10. for (t in n = new _(e, {}),
  11. o)
  12. delete n[t];
  13. else if ("object" === i) {
  14. for (t in e)
  15. t in o || (n[t] = e[t]);
  16. void 0 === n.slashes && (n.slashes = a.test(e.href))
  17. }
  18. return n
  19. }
  20.  
  21. function p(e) {
  22. var t = n.exec(e);
  23. return {
  24. protocol: t[1] ? t[1].toLowerCase() : "",
  25. slashes: !!t[2],
  26. rest: t[3]
  27. }
  28. }
  29.  
  30. function _(e, t, n) {
  31. if (!(this instanceof _))
  32. return new _(e, t, n);
  33. var i, r, a, o, s, l, u = v.slice(),
  34. c = typeof t,
  35. d = this,
  36. h = 0;
  37. for ("object" !== c && "string" !== c && (n = t,
  38. t = null),
  39. n && "function" != typeof n && (n = m.parse),
  40. t = f(t),
  41. i = !(r = p(e || "")).protocol && !r.slashes,
  42. d.slashes = r.slashes || i && t.slashes,
  43. d.protocol = r.protocol || t.protocol || "",
  44. e = r.rest,
  45. r.slashes || (u[2] = [/(.*)/, "pathname"]); h < u.length; h++)
  46. a = (o = u[h])[0],
  47. l = o[1],
  48. a != a ? d[l] = e : "string" == typeof a ? ~(s = e.indexOf(a)) && ("number" == typeof o[2] ? (d[l] = e.slice(0, s),
  49. e = e.slice(s + o[2])) : (d[l] = e.slice(s),
  50. e = e.slice(0, s))) : (s = a.exec(e)) && (d[l] = s[1],
  51. e = e.slice(0, s.index)),
  52. d[l] = d[l] || i && o[3] && t[l] || "",
  53. o[4] && (d[l] = d[l].toLowerCase());
  54. n && (d.query = n(d.query)),
  55. i && t.slashes && "/" !== d.pathname.charAt(0) && ("" !== d.pathname || "" !== t.pathname) && (d.pathname = function(e, t) {
  56. for (var n = "/".split("/").slice(0, -1).concat(e.split("/")), i = n.length, r = n[i - 1], a = !1, o = 0; i--;)
  57. "." === n[i] ? n.splice(i, 1) : ".." === n[i] ? (n.splice(i, 1),
  58. o++) : o && (0 === i && (a = !0),
  59. n.splice(i, 1),
  60. o--);
  61. return a && n.unshift(""),
  62. "." !== r && ".." !== r || n.push(""),
  63. n.join("/")
  64. }(d.pathname, t.pathname)),
  65. g(d.port, d.protocol) || (d.host = d.hostname,
  66. d.port = ""),
  67. d.username = d.password = "",
  68. d.auth && (o = d.auth.split(":"),
  69. d.username = o[0] || "",
  70. d.password = o[1] || ""),
  71. d.origin = d.protocol && d.host && "file:" !== d.protocol ? d.protocol + "//" + d.host : "null",
  72. d.href = d.toString()
  73. }
  74. var g = i("1HwD"),
  75. m = i("gmze"),
  76. n = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,
  77. a = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//,
  78. v = [
  79. ["#", "hash"],
  80. ["?", "query"],
  81. ["/", "pathname"],
  82. ["@", "auth", 1],
  83. [NaN, "host", void 0, 1, 1],
  84. [/:(\d+)$/, "port", void 0, 1],
  85. [NaN, "hostname", void 0, 1, 1]
  86. ],
  87. o = {
  88. hash: 1,
  89. query: 1
  90. };
  91. _.prototype = {
  92. set: function(e, t, n) {
  93. var i = this;
  94. switch (e) {
  95. case "query":
  96. "string" == typeof t && t.length && (t = (n || m.parse)(t)),
  97. i[e] = t;
  98. break;
  99. case "port":
  100. i[e] = t,
  101. g(t, i.protocol) ? t && (i.host = i.hostname + ":" + t) : (i.host = i.hostname,
  102. i[e] = "");
  103. break;
  104. case "hostname":
  105. i[e] = t,
  106. i.port && (t += ":" + i.port),
  107. i.host = t;
  108. break;
  109. case "host":
  110. i[e] = t,
  111. /:\d+$/.test(t) ? (t = t.split(":"),
  112. i.port = t.pop(),
  113. i.hostname = t.join(":")) : (i.hostname = t,
  114. i.port = "");
  115. break;
  116. case "protocol":
  117. i.protocol = t.toLowerCase(),
  118. i.slashes = !n;
  119. break;
  120. case "pathname":
  121. case "hash":
  122. if (t) {
  123. var r = "pathname" === e ? "/" : "#";
  124. i[e] = t.charAt(0) !== r ? r + t : t
  125. } else
  126. i[e] = t;
  127. break;
  128. default:
  129. i[e] = t
  130. }
  131. for (var a = 0; a < v.length; a++) {
  132. var o = v[a];
  133. o[4] && (i[o[1]] = i[o[1]].toLowerCase())
  134. }
  135. return i.origin = i.protocol && i.host && "file:" !== i.protocol ? i.protocol + "//" + i.host : "null",
  136. i.href = i.toString(),
  137. i
  138. },
  139. toString: function(e) {
  140. e && "function" == typeof e || (e = m.stringify);
  141. var t, n = this,
  142. i = n.protocol;
  143. i && ":" !== i.charAt(i.length - 1) && (i += ":");
  144. var r = i + (n.slashes ? "//" : "");
  145. return n.username && (r += n.username,
  146. n.password && (r += ":" + n.password),
  147. r += "@"),
  148. r += n.host + n.pathname,
  149. (t = "object" == typeof n.query ? e(n.query) : n.query) && (r += "?" !== t.charAt(0) ? "?" + t : t),
  150. n.hash && (r += n.hash),
  151. r
  152. }
  153. },
  154. _.extractProtocol = p,
  155. _.location = f,
  156. _.qs = m,
  157. e.exports = _
  158. }).call(t, i("aY11"))
  159. },
Add Comment
Please, Sign In to add comment