polyfill-service
Version:
A polyfill combinator
1 lines • 15.8 kB
JSON
{"aliases":["modernizr:urlparser","blissfuljs","default"],"browsers":{"chrome":"<49","firefox":"<29","ie":"8 - *","ie_mob":"*","safari":"*","firefox_mob":"<29","opera":"<36","android":"*"},"dependencies":["Object.defineProperties","Array.prototype.forEach"],"notes":["`searchParams` is not iterable and has no `forEach()`, `entries()`, `keys()`, `values()` methods","Polyfill requires Object getters so fails in IE < 8"],"license":"CC0","repo":"https://github.com/inexorabletash/polyfill","docs":"https://developer.mozilla.org/en-US/docs/Web/API/URL","baseDir":"URL","hasTests":true,"rawSource":"\n// URL\n// URL Polyfill\n// Draft specification: http://url.spec.whatwg.org\n\n// Notes:\n// - Primarily useful for parsing URLs and modifying query parameters\n// - Should work in IE8+ and everything more modern\n\n(function (global) {\n\t'use strict';\n\n\tvar origURL = global.URL;\n\n\tfunction URLUtils (url) {\n\t\tvar anchor = document.createElement('a');\n\t\t\tanchor.href = url;\n\n\t\treturn anchor;\n\t}\n\n\tglobal.URL = function URL (url, base) {\n\t\tif (!(this instanceof global.URL)) {\n\t\t\tthrow new TypeError(\"Failed to construct 'URL': Please use the 'new' operator.\");\n\t\t}\n\n\t\tif (base) {\n\t\t\turl = (function () {\n\t\t\t\tvar doc;\n\n\t\t\t\t// Use another document/base tag/anchor for relative URL resolution, if possible\n\t\t\t\tif (document.implementation && document.implementation.createHTMLDocument) {\n\t\t\t\t\tdoc = document.implementation.createHTMLDocument('');\n\t\t\t\t}\n\t\t\t\telse if (document.implementation && document.implementation.createDocument) {\n\t\t\t\t\tdoc = document.implementation.createElement('http://www.w3.org/1999/xhtml', 'html', null);\n\t\t\t\t\tdoc.documentElement.appendChild(doc.createElement('head'));\n\t\t\t\t\tdoc.documentElement.appendChild(doc.createElement('body'));\n\t\t\t\t}\n\t\t\t\telse if (window.ActiveXObject) {\n\t\t\t\t\tdoc = new window.ActiveXObject('htmlfile');\n\t\t\t\t\tdoc.write('<head></head><body></body>');\n\t\t\t\t\tdoc.close();\n\t\t\t\t}\n\n\t\t\t\tif (!doc) {\n\t\t\t\t\tthrow Error('base not supported');\n\t\t\t\t}\n\n\t\t\t\tvar baseTag = doc.createElement('base');\n\t\t\t\t\tbaseTag.href = base;\n\n\t\t\t\tdoc.getElementsByTagName('head')[0].appendChild(baseTag);\n\n\t\t\t\tvar anchor = doc.createElement('a');\n\t\t\t\t\tanchor.href = url;\n\n\t\t\t\treturn anchor.href;\n\t\t\t}());\n\t\t}\n\n\t\t// An inner object implementing URLUtils (either a native URL\n\t\t// object or an HTMLAnchorElement instance) is used to perform the\n\t\t// URL algorithms. With full ES5 getter/setter support, return a\n\t\t// regular object For IE8's limited getter/setter support, a\n\t\t// different HTMLAnchorElement is returned with properties\n\t\t// overridden\n\n\t\tvar instance = URLUtils(url || '');\n\n\t\t// Detect for ES5 getter/setter support\n\t\tvar ES5_GET_SET = false;\n\t\ttry {\n\t\t\tES5_GET_SET = (Object.defineProperties && (function () {\n\t\t\t\tvar o = {};\n\n\t\t\t\tObject.defineProperties(o, {\n\t\t\t\t\tp: {\n\t\t\t\t\t\t'get': function () {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\treturn o.p;\n\t\t\t}()));\n\t\t} catch (e) {\n\t\t\tES5_GET_SET = false;\n\t\t};\n\n\t\tvar self = ES5_GET_SET ? this : document.createElement('a');\n\n\t\t// NOTE: Doesn't do the encoding/decoding dance\n\t\tfunction parse (input, isindex) {\n\t\t\tvar sequences = input.split('&');\n\n\t\t\tif (isindex && sequences[0].indexOf('=') === -1) {\n\t\t\t\tsequences[0] = '=' + sequences[0];\n\t\t\t}\n\n\t\t\tvar pairs = [];\n\n\t\t\tsequences.forEach(function (bytes) {\n\t\t\t\tif (bytes.length === 0) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tvar index = bytes.indexOf('=');\n\n\t\t\t\tif (index !== -1) {\n\t\t\t\t\tvar name = bytes.substring(0, index);\n\t\t\t\t\tvar value = bytes.substring(index + 1);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tname = bytes;\n\t\t\t\t\tvalue = '';\n\t\t\t\t}\n\n\t\t\t\tname = name.replace(/\\+/g, ' ');\n\t\t\t\tvalue = value.replace(/\\+/g, ' ');\n\t\t\t\tpairs.push({name: name, value: value});\n\t\t\t});\n\n\t\t\tvar output = [];\n\n\t\t\tpairs.forEach(function (pair) {\n\t\t\t\toutput.push({\n\t\t\t\t\tname : decodeURIComponent(pair.name),\n\t\t\t\t\tvalue: decodeURIComponent(pair.value)\n\t\t\t\t});\n\t\t\t});\n\n\t\t\treturn output;\n\t\t}\n\n\t\tfunction URLSearchParams (url_object, init) {\n\t\t\tvar pairs = [];\n\n\t\t\tif (init) {\n\t\t\t\tpairs = parse(init);\n\t\t\t}\n\n\t\t\tthis._setPairs = function (list) {\n\t\t\t\tpairs = list;\n\t\t\t};\n\n\t\t\tthis._updateSteps = function () {\n\t\t\t\tupdateSteps();\n\t\t\t};\n\n\t\t\tvar updating = false;\n\n\t\t\tfunction updateSteps () {\n\t\t\t\tif (updating) return;\n\t\t\t\tupdating = true;\n\n\t\t\t\t// TODO: For all associated url objects\n\t\t\t\turl_object.search = serialize(pairs);\n\n\t\t\t\tupdating = false;\n\t\t\t}\n\n\t\t\t// NOTE: Doesn't do the encoding/decoding dance\n\t\t\tfunction serialize (pairs) {\n\t\t\t\tvar output = '',\n\t\t\t\t\tfirst = true;\n\n\t\t\t\tpairs.forEach(function (pair) {\n\t\t\t\t\tvar name = encodeURIComponent(pair.name);\n\t\t\t\t\tvar value = encodeURIComponent(pair.value);\n\n\t\t\t\t\tif (!first) {\n\t\t\t\t\t\toutput += '&';\n\t\t\t\t\t}\n\n\t\t\t\t\toutput += name + '=' + value;\n\n\t\t\t\t\tfirst = false;\n\t\t\t\t});\n\n\t\t\t\treturn output.replace(/%20/g, '+');\n\t\t\t}\n\n\t\t\tObject.defineProperties(this, {\n\t\t\t\tappend: {\n\t\t\t\t\tvalue: function (name, value) {\n\t\t\t\t\t\tpairs.push({\n\t\t\t\t\t\t\tname : name,\n\t\t\t\t\t\t\tvalue: value\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tupdateSteps();\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\t'delete': {\n\t\t\t\t\tvalue: function (name) {\n\t\t\t\t\t\tfor (var i = 0; i < pairs.length;) {\n\t\t\t\t\t\t\tif (pairs[i].name === name){\n\t\t\t\t\t\t\t\tpairs.splice(i, 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tupdateSteps();\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\tget: {\n\t\t\t\t\tvalue: function (name) {\n\t\t\t\t\t\tfor (var i = 0; i < pairs.length; ++i) {\n\t\t\t\t\t\t\tif (pairs[i].name === name) {\n\t\t\t\t\t\t\t\treturn pairs[i].value;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\tgetAll: {\n\t\t\t\t\tvalue: function (name) {\n\t\t\t\t\t\tvar result = [];\n\n\t\t\t\t\t\tfor (var i = 0; i < pairs.length; ++i) {\n\t\t\t\t\t\t\tif (pairs[i].name === name) {\n\t\t\t\t\t\t\t\tresult.push(pairs[i].value);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\thas: {\n\t\t\t\t\tvalue: function (name) {\n\t\t\t\t\t\tfor (var i = 0; i < pairs.length; ++i) {\n\t\t\t\t\t\t\tif (pairs[i].name === name) {\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\tset: {\n\t\t\t\t\tvalue: function (name, value) {\n\t\t\t\t\t\tvar found = false;\n\n\t\t\t\t\t\tfor (var i = 0; i < pairs.length;) {\n\t\t\t\t\t\t\tif (pairs[i].name === name) {\n\t\t\t\t\t\t\t\tif (!found) {\n\t\t\t\t\t\t\t\t\tpairs[i].value = value;\n\t\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tpairs.splice(i, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t++i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!found){\n\t\t\t\t\t\t\tpairs.push({name: name, value: value});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tupdateSteps();\n\t\t\t\t\t}\n\t\t\t\t},\n\n\t\t\t\ttoString: {\n\t\t\t\t\tvalue: function () {\n\t\t\t\t\t\treturn serialize(pairs);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tvar queryObject = new URLSearchParams(\n\t\t\tself, instance.search ? instance.search.substring(1) : null);\n\n\t\tObject.defineProperties(self, {\n\t\t\thref: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.href;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.href = v;\n\t\t\t\t\ttidy_instance();\n\t\t\t\t\tupdate_steps();\n\t\t\t\t}\n\t\t\t},\n\n\t\t\torigin: {\n\t\t\t\tget: function () {\n\t\t\t\t\tif ('origin' in instance) {\n\t\t\t\t\t\treturn instance.origin;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn this.protocol + '//' + this.host;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tprotocol: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.protocol;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.protocol = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tusername: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.username;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.username = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tpassword: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.password;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.password = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\thost: {\n\t\t\t\tget: function () {\n\t\t\t\t\t// IE returns default port in |host|\n\t\t\t\t\tvar re = {\n\t\t\t\t\t\t'http:' : /:80$/,\n\t\t\t\t\t\t'https:': /:443$/,\n\t\t\t\t\t\t'ftp:' : /:21$/\n\t\t\t\t\t}\n\t\t\t\t\t[instance.protocol];\n\n\t\t\t\t\treturn re ? instance.host.replace(re, '') : instance.host;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.host = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\thostname: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.hostname;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.hostname = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tport: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.port;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.port = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tpathname: {\n\t\t\t\tget: function () {\n\t\t\t\t\t// IE does not include leading '/' in |pathname|\n\t\t\t\t\tif (instance.pathname.charAt(0) !== '/') {\n\t\t\t\t\t\treturn '/' + instance.pathname;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn instance.pathname;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.pathname = v;\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tsearch: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.search;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tif (instance.search !== v) {\n\t\t\t\t\t\tinstance.search = v;\n\t\t\t\t\t\ttidy_instance();\n\t\t\t\t\t\tupdate_steps();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tsearchParams: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn queryObject;\n\t\t\t\t}\n\t\t\t\t// TODO: implement setter\n\t\t\t},\n\t\t\thash: {\n\t\t\t\tget: function () {\n\t\t\t\t\treturn instance.hash;\n\t\t\t\t},\n\n\t\t\t\tset: function (v) {\n\t\t\t\t\tinstance.hash = v;\n\t\t\t\t\ttidy_instance();\n\t\t\t\t}\n\t\t\t},\n\n\t\t\ttoString: {\n\t\t\t\tvalue: function () {\n\t\t\t\t\treturn instance.toString();\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tvalueOf: {\n\t\t\t\tvalue: function () {\n\t\t\t\t\treturn instance.valueOf();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tfunction tidy_instance () {\n\t\t\tvar href = instance.href.replace(/#$|\\?$|\\?(?=#)/g, '');\n\n\t\t\tif (instance.href !== href){\n\t\t\t\tinstance.href = href;\n\t\t\t}\n\t\t}\n\n\t\tfunction update_steps () {\n\t\t\tqueryObject._setPairs(instance.search ?\n\t\t\t\tparse(instance.search.substring(1)) : []);\n\n\t\t\tqueryObject._updateSteps();\n\t\t}\n\n\t\treturn self;\n\t};\n\n\tif (origURL) {\n\t\tfor (var i in origURL) {\n\t\t\tif (origURL.hasOwnProperty(i)) {\n\t\t\t\tglobal.URL[i] = origURL[i];\n\t\t\t}\n\t\t}\n\t}\n}(this));\n","minSource":"!function(e){\"use strict\";function t(e){var t=document.createElement(\"a\");return t.href=e,t}var n=e.URL;if(e.URL=function(n,r){function o(e,t){var n=e.split(\"&\");t&&-1===n[0].indexOf(\"=\")&&(n[0]=\"=\"+n[0]);var r=[];n.forEach(function(e){if(0!==e.length){var t=e.indexOf(\"=\");if(-1!==t)var n=e.substring(0,t),o=e.substring(t+1);else n=e,o=\"\";n=n.replace(/\\+/g,\" \"),o=o.replace(/\\+/g,\" \"),r.push({name:n,value:o})}});var o=[];return r.forEach(function(e){o.push({name:decodeURIComponent(e.name),value:decodeURIComponent(e.value)})}),o}function a(e,t){function n(){u||(u=!0,e.search=r(a),u=!1)}function r(e){var t=\"\",n=!0;return e.forEach(function(e){var r=encodeURIComponent(e.name),o=encodeURIComponent(e.value);n||(t+=\"&\"),t+=r+\"=\"+o,n=!1}),t.replace(/%20/g,\"+\")}var a=[];t&&(a=o(t)),this._setPairs=function(e){a=e},this._updateSteps=function(){n()};var u=!1;Object.defineProperties(this,{append:{value:function(e,t){a.push({name:e,value:t}),n()}},\"delete\":{value:function(e){for(var t=0;t<a.length;)a[t].name===e?a.splice(t,1):++t;n()}},get:{value:function(e){for(var t=0;t<a.length;++t)if(a[t].name===e)return a[t].value;return null}},getAll:{value:function(e){for(var t=[],n=0;n<a.length;++n)a[n].name===e&&t.push(a[n].value);return t}},has:{value:function(e){for(var t=0;t<a.length;++t)if(a[t].name===e)return!0;return!1}},set:{value:function(e,t){for(var r=!1,o=0;o<a.length;)a[o].name===e?r?a.splice(o,1):(a[o].value=t,r=!0,++o):++o;r||a.push({name:e,value:t}),n()}},toString:{value:function(){return r(a)}}})}function u(){var e=c.href.replace(/#$|\\?$|\\?(?=#)/g,\"\");c.href!==e&&(c.href=e)}function i(){l._setPairs(c.search?o(c.search.substring(1)):[]),l._updateSteps()}if(!(this instanceof e.URL))throw new TypeError(\"Failed to construct 'URL': Please use the 'new' operator.\");r&&(n=function(){var e;if(document.implementation&&document.implementation.createHTMLDocument?e=document.implementation.createHTMLDocument(\"\"):document.implementation&&document.implementation.createDocument?(e=document.implementation.createElement(\"http://www.w3.org/1999/xhtml\",\"html\",null),e.documentElement.appendChild(e.createElement(\"head\")),e.documentElement.appendChild(e.createElement(\"body\"))):window.ActiveXObject&&(e=new window.ActiveXObject(\"htmlfile\"),e.write(\"<head></head><body></body>\"),e.close()),!e)throw Error(\"base not supported\");var t=e.createElement(\"base\");t.href=r,e.getElementsByTagName(\"head\")[0].appendChild(t);var o=e.createElement(\"a\");return o.href=n,o.href}());var c=t(n||\"\"),s=!1;try{s=Object.defineProperties&&function(){var e={};return Object.defineProperties(e,{p:{get:function(){return!0}}}),e.p}()}catch(f){s=!1}var h=s?this:document.createElement(\"a\"),l=new a(h,c.search?c.search.substring(1):null);return Object.defineProperties(h,{href:{get:function(){return c.href},set:function(e){c.href=e,u(),i()}},origin:{get:function(){return\"origin\"in c?c.origin:this.protocol+\"//\"+this.host}},protocol:{get:function(){return c.protocol},set:function(e){c.protocol=e}},username:{get:function(){return c.username},set:function(e){c.username=e}},password:{get:function(){return c.password},set:function(e){c.password=e}},host:{get:function(){var e={\"http:\":/:80$/,\"https:\":/:443$/,\"ftp:\":/:21$/}[c.protocol];return e?c.host.replace(e,\"\"):c.host},set:function(e){c.host=e}},hostname:{get:function(){return c.hostname},set:function(e){c.hostname=e}},port:{get:function(){return c.port},set:function(e){c.port=e}},pathname:{get:function(){return\"/\"!==c.pathname.charAt(0)?\"/\"+c.pathname:c.pathname},set:function(e){c.pathname=e}},search:{get:function(){return c.search},set:function(e){c.search!==e&&(c.search=e,u(),i())}},searchParams:{get:function(){return l}},hash:{get:function(){return c.hash},set:function(e){c.hash=e,u()}},toString:{value:function(){return c.toString()}},valueOf:{value:function(){return c.valueOf()}}}),h},n)for(var r in n)n.hasOwnProperty(r)&&(e.URL[r]=n[r])}(this);","detectSource":"(function (global) {\n\t/*\n\t * Browsers may have:\n\t * No global URL object\n\t * URL with static methods only - may have a dummy constructor\n\t * URL with members except searchParams\n\t * Full URL API support\n\t */\n\t'use strict';\n\n\ttry {\n\t\tvar nativeURL = new global.URL('http://example.com');\n\n\t\treturn 'href' in nativeURL && 'searchParams' in nativeURL;\n\t}\n\tcatch (error) {\n\t\treturn false;\n\t}\n}(this))"}