From faa406201f4f3ffe028391eee6c358fc52bb92d3 Mon Sep 17 00:00:00 2001 From: websanova Date: Sat, 18 Jan 2020 12:43:48 +0700 Subject: [PATCH 1/6] Add link to full list of domains. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3d389fb..e25ef34 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ Also available for Node.js. * [On GitHub as node-url](https://github.com/websanova/node-url) * [On Npm as wurl](https://www.npmjs.com/package/wurl) +Full list of domains. + +* [https://publicsuffix.org/list/public_suffix_list.dat](https://publicsuffix.org/list/public_suffix_list.dat) + ## Bower Install From 00264800d8181c8533aa6a8d0f6a80f87fd58bbc Mon Sep 17 00:00:00 2001 From: websanova Date: Sat, 25 Jan 2020 16:46:08 +0700 Subject: [PATCH 2/6] Clean up package. --- .editorconfig | 12 -- README.md | 60 ++++++++ bower.json | 43 +++--- demo/index.html | 36 +++++ dist/es5-url-tld.min.js | 4 + dist/es5-url.min.js | 4 + dist/jquery-url-tld.min.js | 8 ++ dist/jquery-url.min.js | 8 ++ dist/url-tld.min.js | 2 + dist/url.min.js | 2 + gruntfile.js | 81 +++++------ index.html | 24 ---- package.json | 44 +++--- url.js => src/url-tld.js | 15 +- src/url.js | 186 +++++++++++++++++++++++++ test/es5.js | 3 + test/jquery.html | 27 ++++ test/min.html | 0 test/qunit.html | 278 +++++++++++++++++++++++++++++++++++++ tests.js | 275 ------------------------------------ url-tld.min.js | 1 - url.jquery.json | 57 ++++---- url.min.js | 1 - 23 files changed, 726 insertions(+), 445 deletions(-) delete mode 100644 .editorconfig create mode 100644 demo/index.html create mode 100644 dist/es5-url-tld.min.js create mode 100644 dist/es5-url.min.js create mode 100644 dist/jquery-url-tld.min.js create mode 100644 dist/jquery-url.min.js create mode 100644 dist/url-tld.min.js create mode 100644 dist/url.min.js delete mode 100644 index.html rename url.js => src/url-tld.js (96%) create mode 100644 src/url.js create mode 100644 test/es5.js create mode 100644 test/jquery.html create mode 100644 test/min.html create mode 100644 test/qunit.html delete mode 100644 tests.js delete mode 100644 url-tld.min.js delete mode 100644 url.min.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index f1f66cb..0000000 --- a/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -# EditorConfig is awesome: http://EditorConfig.org - -# top-most EditorConfig file -root = true - -[*] -charset = utf-8 -end_of_line = lf -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = tab -indent_size = 4 diff --git a/README.md b/README.md index e25ef34..02361c7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,63 @@ +# url + +A simple light weight JavaScript url parser. + +* [Demo](https://websanova.com/utils/url) +* [Docs](https://websanova.com/docs/url) +* [Download](https://github.com/websanova/url/tags) + +## Availability + +* [NPM](https://www.npmjs.com/package/@websanova/url) +* [jQuery](https://plugins.jquery.com/url) + +## Test + +There are a number of files for testing in the `test` folder including QUnit. + +## Build + +To build simply run: + +``` +> npm install +> npm run build +``` + +## License + +MIT licensed + +Copyright (C) 2011-2012 Websanova http://www.websanova.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # url() A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped). diff --git a/bower.json b/bower.json index 86d9c15..910e9cb 100644 --- a/bower.json +++ b/bower.json @@ -1,27 +1,20 @@ { - "name": "js-url", - "authors": [ - "Rob Nova " - ], - "description": "A simple url parser for JavaScript.", - "keywords": [ - "js", - "javascript", - "url", - "parser" - ], - "homepage": "https://github.com/websanova/js-url", - "license": "MIT", - "main": [ - "url.js" - ], - "ignore": [ - "lib", - "gruntfile.js", - "index.html", - "package.json", - "tests.js", - "url.jquery.json" - ], - "dependencies": {} + "name": "js-url", + "authors": [ + "Rob Nova " + ], + "description": "A simple url parser for JavaScript.", + "keywords": ["js", "javascript", "url", "parser"], + "homepage": "https://github.com/websanova/js-url", + "license": "MIT", + "main": [ + "url.js" + ], + "ignore": [ + "demo", + "test", + "src", + "gruntfile.js" + ], + "dependencies": {} } \ No newline at end of file diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..2486310 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,36 @@ + + + + + Demo url + + + +

Demo url

+ + +
+ + + + \ No newline at end of file diff --git a/dist/es5-url-tld.min.js b/dist/es5-url-tld.min.js new file mode 100644 index 0000000..7e7b35c --- /dev/null +++ b/dist/es5-url-tld.min.js @@ -0,0 +1,4 @@ +/*! @websanova/url - v2.6.0 - 2020-01-25 */ +var url = function(){function r(r,c){var t,o={};if("tld?"===r)return n();if(c=c||window.location.toString(),!r)return c;if(r=r.toString(),t=c.match(/^mailto:([^\/].+)/))o.protocol="mailto",o.email=t[1];else{if((t=c.match(/(.*?)\/#\!(.*)/))&&(c=t[1]+t[2]),(t=c.match(/(.*?)#(.*)/))&&(o.hash=t[2],c=t[1]),o.hash&&r.match(/^#/))return e(r,o.hash);if((t=c.match(/(.*?)\?(.*)/))&&(o.query=t[2],c=t[1]),o.query&&r.match(/^\?/))return e(r,o.query);if((t=c.match(/(.*?)\:?\/\/(.*)/))&&(o.protocol=t[1].toLowerCase(),c=t[2]),(t=c.match(/(.*?)(\/.*)/))&&(o.path=t[2],c=t[1]),o.path=(o.path||"").replace(/^([^\/])/,"/$1"),r.match(/^[\-0-9]+$/)&&(r=r.replace(/^([^\/])/,"/$1")),r.match(/^\//))return a(r,o.path.substring(1));if((t=(t=a("/-1",o.path.substring(1)))&&t.match(/(.*?)\.([^.]+)$/))&&(o.file=t[0],o.filename=t[1],o.fileext=t[2]),(t=c.match(/(.*)\:([0-9]+)$/))&&(o.port=t[2],c=t[1]),(t=c.match(/(.*?)@(.*)/))&&(o.auth=t[1],c=t[2]),o.auth&&(t=o.auth.match(/(.*)\:(.*)/),o.user=t?t[1]:o.auth,o.pass=t?t[2]:void 0),o.hostname=c.toLowerCase(),"."===r.charAt(0))return a(r,o.hostname);n()&&(t=o.hostname.match(n()))&&(o.tld=t[3],o.domain=t[2]?t[2]+"."+t[3]:void 0,o.sub=t[1]||void 0),o.port=o.port||("https"===o.protocol?"443":"80"),o.protocol=o.protocol||("443"===o.port?"https":"http")}return r in o?o[r]:"{}"===r?o:void 0}function n(){return new RegExp(/(.*?)\.?([^\.]*?)\.(gl|com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function a(r,c){var t=r.charAt(0),o=c.split(t);return t===r?o:o[(r=parseInt(r.substring(1),10))<0?o.length+r:r-1]}function e(r,c){for(var t,o=r.charAt(0),n=c.split("&"),a=[],e={},m=[],i=r.substring(1),s=0,h=n.length;s<%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */' + }, + my_target: { + files: { + './dist/url.min.js': ['./src/url.js'], + './dist/url-tld.min.js': ['./src/url-tld.js'], + } + } } - }, - files: { - src: ['./url.js'] - } - }, - uglify: { - options: { - banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> */' - }, - my_target: { - files: { - './url.min.js': ['./url.js'] - } - } - } - }); + }); - grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.registerTask('default', [ 'qunit', 'jshint', 'uglify' ]); + grunt.registerTask('default', [ 'qunit', 'jshint', 'uglify' ]); }; \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 35caee3..0000000 --- a/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - url test - - - - - - - - -

Test Suite

-

-
-

-
    -
    -
    - - - - \ No newline at end of file diff --git a/package.json b/package.json index 4680f2e..5f7ad18 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,25 @@ { - "name": "js-url", - "version": "2.5.3", - "description": "A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).", - "main": "url.js", - "repository": { - "type": "git", - "url": "https://github.com/websanova/js-url" - }, - "author": { - "name" : "Websanova" - }, - "homepage" : "http://url.websanova.com", - "license": "MIT, GPL", - "devDependencies": { - "grunt-contrib-qunit": "", - "grunt-contrib-uglify": "", - "grunt-contrib-jshint": "" - }, - "scripts": { - "prepublish": "grunt" - } + "name": "@websanova/url", + "version": "2.6.0", + "description": "A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).", + "keywords": ["websanova", "url", "parser"], + "main": "./dist/es5-url-min.js", + "repository": { + "type": "git", + "url": "https://github.com/websanova/js-url" + }, + "author": { + "name" : "Websanova" + }, + "homepage" : "http://url.websanova.com", + "license": "MIT, GPL", + "devDependencies": { + "grunt": "", + "grunt-contrib-qunit": "", + "grunt-contrib-uglify": "", + "grunt-contrib-jshint": "" + }, + "scripts": { + "build": "./node_modules/grunt/bin/grunt" + } } \ No newline at end of file diff --git a/url.js b/src/url-tld.js similarity index 96% rename from url.js rename to src/url-tld.js index 1e04127..f1fd876 100644 --- a/url.js +++ b/src/url-tld.js @@ -182,18 +182,5 @@ }; })(); - if (typeof window.define === 'function' && window.define.amd) { - window.define('js-url', [], function () { - return url; - }); - } else { - if(typeof window.jQuery !== 'undefined') { - window.jQuery.extend({ - url: function(arg, url) { return window.url(arg, url); } - }); - } - - window.url = url; - } - + window.url = url; })(); diff --git a/src/url.js b/src/url.js new file mode 100644 index 0000000..eabbda4 --- /dev/null +++ b/src/url.js @@ -0,0 +1,186 @@ +(function() { + var url = (function() { + + function _t() { + return; + } + + function _d(s) { + return decodeURIComponent(s.replace(/\+/g, ' ')); + } + + function _i(arg, str) { + var sptr = arg.charAt(0), + split = str.split(sptr); + + if (sptr === arg) { return split; } + + arg = parseInt(arg.substring(1), 10); + + return split[arg < 0 ? split.length + arg : arg - 1]; + } + + function _f(arg, str) { + var sptr = arg.charAt(0), + split = str.split('&'), + field = [], + params = {}, + tmp = [], + arg2 = arg.substring(1); + + for (var i = 0, ii = split.length; i < ii; i++) { + field = split[i].match(/(.*?)=(.*)/); + + // TODO: regex should be able to handle this. + if ( ! field) { + field = [split[i], split[i], '']; + } + + if (field[1].replace(/\s/g, '') !== '') { + field[2] = _d(field[2] || ''); + + // If we have a match just return it right away. + if (arg2 === field[1]) { return field[2]; } + + // Check for array pattern. + tmp = field[1].match(/(.*)\[([0-9]+)\]/); + + if (tmp) { + params[tmp[1]] = params[tmp[1]] || []; + + params[tmp[1]][tmp[2]] = field[2]; + } + else { + params[field[1]] = field[2]; + } + } + } + + if (sptr === arg) { return params; } + + return params[arg2]; + } + + return function(arg, url) { + var _l = {}, tmp, tmp2; + + if (arg === 'tld?') { return _t(); } + + url = url || window.location.toString(); + + if ( ! arg) { return url; } + + arg = arg.toString(); + + if (tmp = url.match(/^mailto:([^\/].+)/)) { + _l.protocol = 'mailto'; + _l.email = tmp[1]; + } + else { + + // Ignore Hashbangs. + if (tmp = url.match(/(.*?)\/#\!(.*)/)) { + url = tmp[1] + tmp[2]; + } + + // Hash. + if (tmp = url.match(/(.*?)#(.*)/)) { + _l.hash = tmp[2]; + url = tmp[1]; + } + + // Return hash parts. + if (_l.hash && arg.match(/^#/)) { return _f(arg, _l.hash); } + + // Query + if (tmp = url.match(/(.*?)\?(.*)/)) { + _l.query = tmp[2]; + url = tmp[1]; + } + + // Return query parts. + if (_l.query && arg.match(/^\?/)) { return _f(arg, _l.query); } + + // Protocol. + if (tmp = url.match(/(.*?)\:?\/\/(.*)/)) { + _l.protocol = tmp[1].toLowerCase(); + url = tmp[2]; + } + + // Path. + if (tmp = url.match(/(.*?)(\/.*)/)) { + _l.path = tmp[2]; + url = tmp[1]; + } + + // Clean up path. + _l.path = (_l.path || '').replace(/^([^\/])/, '/$1'); + + // Return path parts. + if (arg.match(/^[\-0-9]+$/)) { arg = arg.replace(/^([^\/])/, '/$1'); } + if (arg.match(/^\//)) { return _i(arg, _l.path.substring(1)); } + + // File. + tmp = _i('/-1', _l.path.substring(1)); + + if (tmp && (tmp = tmp.match(/(.*?)\.([^.]+)$/))) { + _l.file = tmp[0]; + _l.filename = tmp[1]; + _l.fileext = tmp[2]; + } + + // Port. + if (tmp = url.match(/(.*)\:([0-9]+)$/)) { + _l.port = tmp[2]; + url = tmp[1]; + } + + // Auth. + if (tmp = url.match(/(.*?)@(.*)/)) { + _l.auth = tmp[1]; + url = tmp[2]; + } + + // User and pass. + if (_l.auth) { + tmp = _l.auth.match(/(.*)\:(.*)/); + + _l.user = tmp ? tmp[1] : _l.auth; + _l.pass = tmp ? tmp[2] : undefined; + } + + // Hostname. + _l.hostname = url.toLowerCase(); + + // Return hostname parts. + if (arg.charAt(0) === '.') { return _i(arg, _l.hostname); } + + // Domain, tld and sub domain. + if (_t()) { + tmp = _l.hostname.match(_t()); + + if (tmp) { + _l.tld = tmp[3]; + _l.domain = tmp[2] ? tmp[2] + '.' + tmp[3] : undefined; + _l.sub = tmp[1] || undefined; + } + } + + // Set port and protocol defaults if not set. + _l.port = _l.port || (_l.protocol === 'https' ? '443' : '80'); + _l.protocol = _l.protocol || (_l.port === '443' ? 'https' : 'http'); + } + + // Return arg. + if (arg in _l) { return _l[arg]; } + + // Return everything. + if (arg === '{}') { return _l; } + + // Default to undefined for no match. + return undefined; + }; + })(); + + window.url = url; +})(); diff --git a/test/es5.js b/test/es5.js new file mode 100644 index 0000000..da31d9f --- /dev/null +++ b/test/es5.js @@ -0,0 +1,3 @@ +var url = require('../dist/es5-url-tld.min.js'); + +console.log(url('hostname', 'https://websanova.com')) \ No newline at end of file diff --git a/test/jquery.html b/test/jquery.html new file mode 100644 index 0000000..35e7806 --- /dev/null +++ b/test/jquery.html @@ -0,0 +1,27 @@ + + + + + Test jQuery url + + + + + + + + +
    + + + + \ No newline at end of file diff --git a/test/min.html b/test/min.html new file mode 100644 index 0000000..e69de29 diff --git a/test/qunit.html b/test/qunit.html new file mode 100644 index 0000000..5954bf0 --- /dev/null +++ b/test/qunit.html @@ -0,0 +1,278 @@ + + + + + Test url + + + + + + + +
    + + +< + \ No newline at end of file diff --git a/tests.js b/tests.js deleted file mode 100644 index 7cc7beb..0000000 --- a/tests.js +++ /dev/null @@ -1,275 +0,0 @@ -(function() { - -var url = 'http://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese'; -var urlHttps = 'https://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese'; -var urlIp = 'https://rob:abcd1234@1.2.3.4/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese'; - -module('url'); - -test('url', function() { - deepEqual( window.url( ), window.location.href ); -}); - -if (window.url('tld?')) { - test('obj', function() { - deepEqual( window.url('{}', url), { - 'auth': 'rob:abcd1234', - 'domain': 'domain.com', - 'file': 'index.html', - 'fileext': 'html', - 'filename': 'index', - 'hash': 'test=hash&chucky=cheese', - 'hostname': 'www.domain.com', - 'pass': 'abcd1234', - 'path': '/path/index.html', - 'port': '80', - 'protocol': 'http', - 'query': 'query1=test&silly=willy', - 'sub': 'www', - 'tld': 'com', - 'user': 'rob' - }); - }); - - test('tld', function() { - deepEqual( window.url('tld', 'http://sub.www.domain.co.uk'), 'co.uk' ); - deepEqual( window.url('tld', 'http://www.domain.org.uk'), 'org.uk' ); - deepEqual( window.url('tld', 'http://domain.la'), 'la' ); - deepEqual( window.url('tld', 'http://in'), undefined ); - deepEqual( window.url('tld', 'http://.asia'), 'asia' ); - deepEqual( window.url('tld', 'http://.cao.uk'), undefined ); - deepEqual( window.url('tld', 'http://'), undefined ); - deepEqual( window.url('tld', 'http://domain.zoo'), undefined ); - deepEqual( window.url('tld', url), 'com' ); - }); - - test('domain', function() { - deepEqual( window.url('domain', 'http://sub.www.domain.co.uk'), 'domain.co.uk' ); - deepEqual( window.url('domain', 'http://www.domain.org.uk'), 'domain.org.uk' ); - deepEqual( window.url('domain', 'http://domain.la'), 'domain.la' ); - deepEqual( window.url('domain', 'http://in'), undefined ); - deepEqual( window.url('domain', 'http://.asia'), undefined ); - deepEqual( window.url('domain', 'http://.cao.uk'), undefined ); - deepEqual( window.url('domain', 'http://'), undefined ); - deepEqual( window.url('domain', 'http://domain.zoo'), undefined ); - deepEqual( window.url('domain', url), 'domain.com' ); - deepEqual( window.url('domain', 'https://test.testshi.cn/test.html' ), 'testshi.cn' ); - deepEqual( window.url('domain', 'https://goo.gl/maps' ), 'goo.gl' ); - }); - - test('sub', function() { - deepEqual( window.url('sub', 'http://sub.www.domain.co.uk'), 'sub.www' ); - deepEqual( window.url('sub', 'http://www.domain.org.uk'), 'www' ); - deepEqual( window.url('sub', 'http://domain.la'), undefined ); - deepEqual( window.url('sub', 'http://in'), undefined ); - deepEqual( window.url('sub', 'http://.asia'), undefined ); - deepEqual( window.url('sub', 'http://.cao.uk'), undefined ); - deepEqual( window.url('sub', 'http://'), undefined ); - deepEqual( window.url('sub', 'http://domain.zoo'), undefined ); - deepEqual( window.url('sub', url), 'www' ); - }); -} -else { - test('obj', function() { - deepEqual( window.url('{}', url), { - 'auth': 'rob:abcd1234', - 'file': 'index.html', - 'fileext': 'html', - 'filename': 'index', - 'hash': 'test=hash&chucky=cheese', - 'hostname': 'www.domain.com', - 'pass': 'abcd1234', - 'path': '/path/index.html', - 'port': '80', - 'protocol': 'http', - 'query': 'query1=test&silly=willy', - 'user': 'rob' - }); - }); -} - -test('mailto', function() { - deepEqual( window.url( 'email', 'mailto:rob@websanova.com' ), 'rob@websanova.com' ); - deepEqual( window.url( 'protocol', 'mailto:rob@websanova.com' ), 'mailto' ); - deepEqual( window.url( 'email', 'mailto:/rob@websanova.com' ), undefined ); - deepEqual( window.url( 'email', 'mailto://rob@websanova.com' ), undefined ); - deepEqual( window.url( 'protocol', 'mailto:/rob@websanova.com' ), 'http' ); - deepEqual( window.url( 'mailto:', 'mailto:/rob@websanova.com' ), undefined ); -}); - -test('hostname', function() { - deepEqual( window.url( 'hostname', url ), 'www.domain.com' ); - deepEqual( window.url( 'hostname', urlIp ), '1.2.3.4' ); - deepEqual( window.url( 'hostname', 'https://test.testshi.cn/test.html' ), 'test.testshi.cn' ); - deepEqual( window.url( 'hostname', 'https://goo.gl/maps' ), 'goo.gl' ); -}); - -test('domain parts', function() { - deepEqual( window.url( '.', url ), ['www', 'domain', 'com'] ); - deepEqual( window.url( '.0', url ), undefined ); - deepEqual( window.url( '.1', url ), 'www' ); - deepEqual( window.url( '.2', url ), 'domain' ); - deepEqual( window.url( '.-1', url ), 'com' ); -}); - -test('auth', function() { - deepEqual( window.url( 'auth', url ), 'rob:abcd1234' ); - deepEqual( window.url( 'user', url ), 'rob' ); - deepEqual( window.url( 'pass', url ), 'abcd1234' ); -}); - -test('port', function() { - deepEqual( window.url( 'port', url ), '80' ); - deepEqual( window.url( 'port', url.toUpperCase() ), '80' ); - deepEqual( window.url( 'port', 'http://example.com:80' ), '80' ); - deepEqual( window.url( 'port', urlHttps ), '443' ); - deepEqual( window.url( 'port', urlHttps.toUpperCase() ), '443' ); - deepEqual( window.url( 'port', 'https://example.com:443' ), '443' ); - deepEqual( window.url( 'port', 'http://domain.com:400?poo=a:b' ), '400' ); - deepEqual( window.url( 'port', 'https://domain.com:80' ), '80' ); - deepEqual( window.url( 'port', 'http://domain.com:443' ), '443' ); - deepEqual( window.url( 'port', 'http://domain.com' ), '80' ); - deepEqual( window.url( 'port', 'https://domain.com' ), '443' ); - deepEqual( window.url( 'port', 'rob@domain.com' ), '80' ); -}); - -test('protocol', function() { - deepEqual( window.url( 'protocol', 'http://domain.com' ), 'http' ); - deepEqual( window.url( 'protocol', 'http://domain.com:80' ), 'http' ); - deepEqual( window.url( 'protocol', 'http://domain.com:443' ), 'http' ); - deepEqual( window.url( 'protocol', 'domain.com' ), 'http' ); - deepEqual( window.url( 'protocol', 'domain.com:80' ), 'http' ); - deepEqual( window.url( 'protocol', 'domain.com:443' ), 'https' ); - deepEqual( window.url( 'protocol', 'https://domain.com:443' ), 'https' ); - deepEqual( window.url( 'protocol', 'https://domain.com:80' ), 'https' ); - deepEqual( window.url( 'protocol', 'rob@domain.com' ), 'http' ); -}); - -test('path', function() { - deepEqual( window.url( 'path', url ), '/path/index.html' ); - deepEqual( window.url( 'path', 'http://www.domain.com/first/second' ), '/first/second' ); - deepEqual( window.url( 'path', 'http://www.domain.com/first/second/' ), '/first/second/' ); - deepEqual( window.url( 'path', 'http://www.domain.com:8080/first/second' ), '/first/second' ); - deepEqual( window.url( 'path', 'http://www.domain.com:8080/first/second/' ), '/first/second/' ); - deepEqual( window.url( 'path', 'http://www.domain.com/first/second?test=foo' ), '/first/second' ); - deepEqual( window.url( 'path', 'http://www.domain.com/first/second/?test=foo' ), '/first/second/' ); - deepEqual( window.url( 'path', 'http://www.domain.com/path#anchor' ), '/path' ); - deepEqual( window.url( 'path', 'http://www.domain.com/path/#anchor' ), '/path/' ); - deepEqual( window.url( 'path', 'http://www.domain.com' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com/' ), '/' ); - deepEqual( window.url( 'path', 'http://www.domain.com#anchor' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com/#anchor' ), '/' ); - deepEqual( window.url( 'path', 'http://www.domain.com?test=foo' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com/?test=foo' ), '/' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80/' ), '/' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80#anchor' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80/#anchor' ), '/' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80?test=foo' ), '' ); - deepEqual( window.url( 'path', 'http://www.domain.com:80/?test=foo' ), '/' ); -}); - -test('file', function() { - deepEqual( window.url( 'file', url ), 'index.html' ); - deepEqual( window.url( 'filename', url ), 'index' ); - deepEqual( window.url( 'fileext', url ), 'html' ); - deepEqual( window.url( 'file', 'http://domain.com' ), undefined ); - deepEqual( window.url( 'filename', 'http://domain.com' ), undefined ); - deepEqual( window.url( 'fileext', 'http://domain.com' ), undefined ); - deepEqual( window.url( 'file', 'http://domain.com/some.file.png' ), 'some.file.png' ); - deepEqual( window.url( 'filename', 'http://domain.com/some.file.png' ), 'some.file' ); - deepEqual( window.url( 'fileext', 'http://domain.com/some.file.png' ), 'png' ); - deepEqual( window.url( 'file', 'http://domain.com/.png' ), '.png' ); - deepEqual( window.url( 'filename', 'http://domain.com/.png' ), '' ); - deepEqual( window.url( 'fileext', 'http://domain.com/.png' ), 'png' ); -}); - -test('url parts', function() { - deepEqual( window.url( '/', url ), ['path', 'index.html'] ); - deepEqual( window.url( '0', url ), undefined ); - deepEqual( window.url( '-4', url ), undefined ); - deepEqual( window.url( '1', url ), 'path' ); - deepEqual( window.url( 1, url ), 'path' ); - deepEqual( window.url( '2', url ), 'index.html' ); - deepEqual( window.url( '3', url ), undefined ); - deepEqual( window.url( '-1', url ), 'index.html' ); - deepEqual( window.url( '1', 'http://www.domain.com/first/second' ), 'first' ); - deepEqual( window.url( '1', 'http://www.domain.com/first/second/' ), 'first' ); - deepEqual( window.url( '-1', 'http://www.domain.com/first/second?test=foo' ), 'second' ); - deepEqual( window.url( '-1', 'http://www.domain.com/first/second/?test=foo' ), '' ); - deepEqual( window.url( '-2', 'http://www.domain.com/first/second/?test=foo' ), 'second' ); -}); - -test('query string', function() { - deepEqual( window.url( 'query', url ), 'query1=test&silly=willy' ); - deepEqual( window.url( '?', url ), {'query1': 'test', 'silly': 'willy'} ); - deepEqual( window.url( '?silly', url ), 'willy' ); - deepEqual( window.url( '?poo', url ), undefined ); - deepEqual( window.url( '?poo', 'http://domain.com?poo=' ), '' ); - deepEqual( window.url( '?poo', 'http://domain.com/?poo' ), '' ); - deepEqual( window.url( '?poo', 'http://domain.com?poo' ), '' ); - deepEqual( window.url( '?poo', 'http://domain.com?' ), undefined ); - deepEqual( window.url( '?poo', 'http://domain.com' ), undefined ); - deepEqual( window.url( '?poo', 'http://domain.com?poo=a+b' ), 'a b' ); - deepEqual( window.url( '?poo', 'http://domain.com?poo=javascript%20decode%20uri%20%2B%20sign%20to%20space' ), 'javascript decode uri + sign to space' ); - deepEqual( window.url( '?key', 'http://domain.com?key=value=va?key2=value' ), 'value=va?key2=value'); - deepEqual( window.url( '?poo', 'http://domain.com:400?poo=a:b' ), 'a:b' ); - deepEqual( window.url( '?poo', 'http://domain.com:400? & & &' ), undefined ); - deepEqual( window.url( '?test', 'http://domain.com?test=45#5' ), '45' ); - deepEqual( window.url( '?test', 'http://domain.com?test=45?5' ), '45?5' ); - deepEqual( window.url( '?', 'http://domain.com?silly=willy&field[0]=zero&field[1]=one' ), {'silly': 'willy', 'field': ['zero', 'one']} ); - deepEqual( window.url( '?', 'http://domain.com?silly=willy&field[0]=zero&field[2]=two' ), {'silly': 'willy', 'field': ['zero', undefined, 'two']} ); - - deepEqual( window.url( '?field[0]', 'http://domain.com?field[0]=zero&firled[1]=one' ), 'zero' ); - deepEqual( window.url( '?field', 'http://domain.com?field[0]=zero&field[1]=one&var=test' ), ['zero', 'one'] ); - deepEqual( window.url( '?field', 'http://domain.com?field[0]=zero&field[3]=one&var=test' ), ['zero', undefined, undefined, 'one'] ); - deepEqual( window.url( '?var', 'http://domain.com?field[0]=zero&field[3]=one&var=test' ), 'test' ); - deepEqual( window.url( '?', 'http://domain.com?field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} ); -}); - -test('hash string', function() { - deepEqual( window.url( 'hash', url ), 'test=hash&chucky=cheese' ); - deepEqual( window.url( '#', url ), {'chucky': 'cheese', 'test': 'hash'} ); - deepEqual( window.url( '#chucky', url ), 'cheese' ); - deepEqual( window.url( '#poo', url ), undefined ); - deepEqual( window.url( '#poo', 'http://domain.com#poo=' ), '' ); - deepEqual( window.url( '#poo', 'http://domain.com/#poo' ), '' ); - deepEqual( window.url( '#poo', 'http://domain.com#poo' ), '' ); - deepEqual( window.url( '#poo', 'http://domain.com#' ), undefined ); - deepEqual( window.url( '#poo', 'http://domain.com' ), undefined ); - deepEqual( window.url( '#test', 'http://domain.com#test=45#5' ), '45#5' ); - - deepEqual( window.url( '#field[0]', 'http://domain.com#field[0]=zero&firled[1]=one' ), 'zero' ); - deepEqual( window.url( '#field', 'http://domain.com#field[0]=zero&field[1]=one&var=test' ), ['zero', 'one'] ); - deepEqual( window.url( '#field', 'http://domain.com#field[0]=zero&field[3]=one&var=test' ), ['zero', undefined, undefined, 'one'] ); - deepEqual( window.url( '#var', 'http://domain.com#field[0]=zero&field[3]=one&var=test' ), 'test' ); - deepEqual( window.url( '#', 'http://domain.com#field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} ); -}); - -test('hash bangs', function() { - deepEqual( window.url( '?poo', 'http://domain.com/#!?' ), undefined ); - deepEqual( window.url( '?poo', 'http://domain.com/#!/' ), undefined ); - deepEqual( window.url( '-1', 'http://www.domain.com/#!/first/second/?test=foo' ), '' ); - deepEqual( window.url( '-2', 'http://www.domain.com/#!/first/second/?test=foo' ), 'second' ); - deepEqual( window.url( '?', 'http://domain.com/#!/?field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} ); - deepEqual( window.url( '?', 'http://domain.com/#!?field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} ); - deepEqual( window.url( '#', 'http://domain.com/#!/#field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} ); -}); - -if (window.url('tld?')) { - test('tld', function() { - deepEqual( window.url( 'tld', 'www.example.ly' ), 'ly' ); - deepEqual( window.url( 'tld', 'www.example.xyz' ), 'xyz' ); - }); -} - -if (typeof jQuery !== 'undefined') { - test('jQuery', function() { - deepEqual( $.url( 'hostname', url ), 'www.domain.com' ); - deepEqual( $.url( 'path', url ), '/path/index.html' ); - deepEqual( $.url( '?silly', url ), 'willy' ); - deepEqual( $.url( '#poo', url ), undefined ); - }); -} - -}()); \ No newline at end of file diff --git a/url-tld.min.js b/url-tld.min.js deleted file mode 100644 index 46218a8..0000000 --- a/url-tld.min.js +++ /dev/null @@ -1 +0,0 @@ -/*! js-url - v2.5.3 - 2018-04-05 */!function(){var a=function(){function a(){return new RegExp(/(.*?)\.?([^\.]*?)\.(gl|com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function b(a){return decodeURIComponent(a.replace(/\+/g," "))}function c(a,b){var c=a.charAt(0),d=b.split(c);return c===a?d:(a=parseInt(a.substring(1),10),d[a<0?d.length+a:a-1])}function d(a,c){for(var d=a.charAt(0),e=c.split("&"),f=[],g={},h=[],i=a.substring(1),j=0,k=e.length;j=1.5" } - ], - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/websanova/js-url#license" - } - ], - "bugs": "https://github.com/websanova/js-url/issues", - "homepage": "http://url.websanova.com", - "docs": "https://github.com/websanova/js-url#url", - "download": "https://github.com/websanova/js-url/tags", - "dependencies": { - "jquery": ">=1.5" - } } diff --git a/url.min.js b/url.min.js deleted file mode 100644 index 2e535d8..0000000 --- a/url.min.js +++ /dev/null @@ -1 +0,0 @@ -/*! js-url - v2.5.3 - 2018-04-05 */!function(){var a=function(){function a(){}function b(a){return decodeURIComponent(a.replace(/\+/g," "))}function c(a,b){var c=a.charAt(0),d=b.split(c);return c===a?d:(a=parseInt(a.substring(1),10),d[a<0?d.length+a:a-1])}function d(a,c){for(var d=a.charAt(0),e=c.split("&"),f=[],g={},h=[],i=a.substring(1),j=0,k=e.length;j Date: Sat, 25 Jan 2020 16:50:51 +0700 Subject: [PATCH 3/6] Fix docs. --- README.md | 151 +------------------------------------ dist/es5-url-tld.min.js | 2 +- dist/es5-url.min.js | 2 +- dist/jquery-url-tld.min.js | 2 +- dist/jquery-url.min.js | 2 +- dist/url-tld.min.js | 2 +- dist/url.min.js | 2 +- package.json | 2 +- 8 files changed, 9 insertions(+), 156 deletions(-) diff --git a/README.md b/README.md index 02361c7..617e2c5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A simple light weight JavaScript url parser. * [Demo](https://websanova.com/utils/url) * [Docs](https://websanova.com/docs/url) -* [Download](https://github.com/websanova/url/tags) +* [Download](https://github.com/websanova/js-url/tags) ## Availability @@ -28,151 +28,4 @@ To build simply run: MIT licensed -Copyright (C) 2011-2012 Websanova http://www.websanova.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# url() - -A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped). - -* [Change Log](https://github.com/websanova/js-url/wiki/Change-Log) -* [View the url demo](http://url.websanova.com) -* [Download the lastest version of url](https://github.com/websanova/js-url/tags) - -Also available for Node.js. - -* [On GitHub as node-url](https://github.com/websanova/node-url) -* [On Npm as wurl](https://www.npmjs.com/package/wurl) - -Full list of domains. - -* [https://publicsuffix.org/list/public_suffix_list.dat](https://publicsuffix.org/list/public_suffix_list.dat) - - -## Bower Install - -``` -> bower install js-url -``` - -## Notes - -For path(1) and path(-1) will always act as if the path is in the form `/some/path/` regardless of whether the original path was `/some/path` or `some/path/`. - -## Tld - -There are two versions, `url.min.js` and `url-tld.min.jd`. The `tld` version contains a list of valid tld's making the file about 2kb larger. If you don't need support for it just use domain parts arguments (`url('-1')`) to get the tld pieces you need. - -## Examples - -```html -http://rob:abcd1234@www.example.co.uk/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese -``` - -```js -url(); // http://rob:abcd1234@www.example.co.uk/path/index.html?query1=test&silly=willy&field[0]=zero&field[2]=two#test=hash&chucky=cheese -url('tld'); // co.uk -url('domain'); // example.co.uk -url('hostname'); // www.example.co.uk -url('sub'); // www -url('.0') // undefined -url('.1') // www -url('.2') // example -url('.-1') // uk -url('auth') // rob:abcd1234 -url('user') // rob -url('pass') // abcd1234 -url('port'); // 80 -url('protocol'); // http -url('path'); // /path/index.html -url('file'); // index.html -url('filename'); // index -url('fileext'); // html -url('1'); // path -url('2'); // index.html -url('3'); // undefined -url('-1'); // index.html -url(1); // path -url(2); // index.html -url(-1); // index.html -url('query'); // query1=test&silly=willy -url('?'); // {query1: 'test', silly: 'willy', field: ['zero', undefined, 'two']} -url('?silly'); // willy -url('?poo'); // undefined -url('field[0]') // zero -url('field') // ['zero', undefined, 'two'] -url('hash'); // test=hash&chucky=cheese -url('#'); // {test: 'hash', chucky: 'cheese'} -url('#chucky'); // cheese -url('#poo'); // undefined -``` - -Also supports `mailto`. - -```js -url('protocol', 'mailto:rob@websanova.com'); // mailto -url('email', 'mailto:rob@websanova.com'); // rob@websanova.com - -``` - -We can also pass a url in and use all the same options on it: - -```js -url('hostname', 'test.www.example.com/path/here'); // test.www.example.com -url('protocol', 'www.example.com/path/here'); // http -url('path', 'http://www.example.com:8080/some/path'); // /some/path -url('port', 'http://www.example.com:8080/some/path'); // 8080 -url('protocol', 'https://www.example.com:8080/some/path'); // https -etc... -``` - -## jQuery - -Also include is a jQuery version of the plugin that can be called via $.url() with all the same options. If you're already using jQuery it may be better to use the jQuery version to avoid namespacing issues. - -## AMD module - -If AMD loader present (when `(typeof define === 'function' && define.amd !== undefined)` is truthy) the script registers itself as anonymous AMD module without polluting global `window`-object or extending `jQuery`. - -## Grunt.js - -If you want to use Grunt you will need to install the required plugins locally using `npm install` in the root folder of your project. If you need to setup Grunt on your system you can follow my [Setting up Grunt.js](http://www.websanova.com/blog/javascript/how-to-setup-grunt) guide. - -## Resources - -* [More jQuery plugins by Websanova](http://websanova.com/plugins) -* [jQuery Plugin Development Boilerplate](http://wboiler.websanova.com) -* [The Ultimate Guide to Writing jQuery Plugins](http://www.websanova.com/blog/jquery/the-ultimate-guide-to-writing-jquery-plugins) - -## License - -MIT licensed - -Copyright (C) 2011-2012 Websanova http://www.websanova.com +Copyright (C) 2011-2012 Websanova http://www.websanova.com \ No newline at end of file diff --git a/dist/es5-url-tld.min.js b/dist/es5-url-tld.min.js index 7e7b35c..5796c22 100644 --- a/dist/es5-url-tld.min.js +++ b/dist/es5-url-tld.min.js @@ -1,4 +1,4 @@ -/*! @websanova/url - v2.6.0 - 2020-01-25 */ +/*! @websanova/url - v2.6.1 - 2020-01-25 */ var url = function(){function r(r,c){var t,o={};if("tld?"===r)return n();if(c=c||window.location.toString(),!r)return c;if(r=r.toString(),t=c.match(/^mailto:([^\/].+)/))o.protocol="mailto",o.email=t[1];else{if((t=c.match(/(.*?)\/#\!(.*)/))&&(c=t[1]+t[2]),(t=c.match(/(.*?)#(.*)/))&&(o.hash=t[2],c=t[1]),o.hash&&r.match(/^#/))return e(r,o.hash);if((t=c.match(/(.*?)\?(.*)/))&&(o.query=t[2],c=t[1]),o.query&&r.match(/^\?/))return e(r,o.query);if((t=c.match(/(.*?)\:?\/\/(.*)/))&&(o.protocol=t[1].toLowerCase(),c=t[2]),(t=c.match(/(.*?)(\/.*)/))&&(o.path=t[2],c=t[1]),o.path=(o.path||"").replace(/^([^\/])/,"/$1"),r.match(/^[\-0-9]+$/)&&(r=r.replace(/^([^\/])/,"/$1")),r.match(/^\//))return a(r,o.path.substring(1));if((t=(t=a("/-1",o.path.substring(1)))&&t.match(/(.*?)\.([^.]+)$/))&&(o.file=t[0],o.filename=t[1],o.fileext=t[2]),(t=c.match(/(.*)\:([0-9]+)$/))&&(o.port=t[2],c=t[1]),(t=c.match(/(.*?)@(.*)/))&&(o.auth=t[1],c=t[2]),o.auth&&(t=o.auth.match(/(.*)\:(.*)/),o.user=t?t[1]:o.auth,o.pass=t?t[2]:void 0),o.hostname=c.toLowerCase(),"."===r.charAt(0))return a(r,o.hostname);n()&&(t=o.hostname.match(n()))&&(o.tld=t[3],o.domain=t[2]?t[2]+"."+t[3]:void 0,o.sub=t[1]||void 0),o.port=o.port||("https"===o.protocol?"443":"80"),o.protocol=o.protocol||("443"===o.port?"https":"http")}return r in o?o[r]:"{}"===r?o:void 0}function n(){return new RegExp(/(.*?)\.?([^\.]*?)\.(gl|com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function a(r,c){var t=r.charAt(0),o=c.split(t);return t===r?o:o[(r=parseInt(r.substring(1),10))<0?o.length+r:r-1]}function e(r,c){for(var t,o=r.charAt(0),n=c.split("&"),a=[],e={},m=[],i=r.substring(1),s=0,h=n.length;s Date: Tue, 4 Feb 2020 08:25:57 +0700 Subject: [PATCH 4/6] Fix bower file. --- bower.json | 2 +- dist/es5-url-tld.min.js | 2 +- dist/es5-url.min.js | 2 +- dist/jquery-url-tld.min.js | 2 +- dist/jquery-url.min.js | 2 +- dist/url-tld.min.js | 2 +- dist/url.min.js | 2 +- package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index 910e9cb..4fd3e4a 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ "homepage": "https://github.com/websanova/js-url", "license": "MIT", "main": [ - "url.js" + "./dist/es5-url-min.js" ], "ignore": [ "demo", diff --git a/dist/es5-url-tld.min.js b/dist/es5-url-tld.min.js index 5796c22..5516034 100644 --- a/dist/es5-url-tld.min.js +++ b/dist/es5-url-tld.min.js @@ -1,4 +1,4 @@ -/*! @websanova/url - v2.6.1 - 2020-01-25 */ +/*! @websanova/url - v2.6.2 - 2020-01-25 */ var url = function(){function r(r,c){var t,o={};if("tld?"===r)return n();if(c=c||window.location.toString(),!r)return c;if(r=r.toString(),t=c.match(/^mailto:([^\/].+)/))o.protocol="mailto",o.email=t[1];else{if((t=c.match(/(.*?)\/#\!(.*)/))&&(c=t[1]+t[2]),(t=c.match(/(.*?)#(.*)/))&&(o.hash=t[2],c=t[1]),o.hash&&r.match(/^#/))return e(r,o.hash);if((t=c.match(/(.*?)\?(.*)/))&&(o.query=t[2],c=t[1]),o.query&&r.match(/^\?/))return e(r,o.query);if((t=c.match(/(.*?)\:?\/\/(.*)/))&&(o.protocol=t[1].toLowerCase(),c=t[2]),(t=c.match(/(.*?)(\/.*)/))&&(o.path=t[2],c=t[1]),o.path=(o.path||"").replace(/^([^\/])/,"/$1"),r.match(/^[\-0-9]+$/)&&(r=r.replace(/^([^\/])/,"/$1")),r.match(/^\//))return a(r,o.path.substring(1));if((t=(t=a("/-1",o.path.substring(1)))&&t.match(/(.*?)\.([^.]+)$/))&&(o.file=t[0],o.filename=t[1],o.fileext=t[2]),(t=c.match(/(.*)\:([0-9]+)$/))&&(o.port=t[2],c=t[1]),(t=c.match(/(.*?)@(.*)/))&&(o.auth=t[1],c=t[2]),o.auth&&(t=o.auth.match(/(.*)\:(.*)/),o.user=t?t[1]:o.auth,o.pass=t?t[2]:void 0),o.hostname=c.toLowerCase(),"."===r.charAt(0))return a(r,o.hostname);n()&&(t=o.hostname.match(n()))&&(o.tld=t[3],o.domain=t[2]?t[2]+"."+t[3]:void 0,o.sub=t[1]||void 0),o.port=o.port||("https"===o.protocol?"443":"80"),o.protocol=o.protocol||("443"===o.port?"https":"http")}return r in o?o[r]:"{}"===r?o:void 0}function n(){return new RegExp(/(.*?)\.?([^\.]*?)\.(gl|com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function a(r,c){var t=r.charAt(0),o=c.split(t);return t===r?o:o[(r=parseInt(r.substring(1),10))<0?o.length+r:r-1]}function e(r,c){for(var t,o=r.charAt(0),n=c.split("&"),a=[],e={},m=[],i=r.substring(1),s=0,h=n.length;s Date: Wed, 5 Feb 2020 09:46:49 +0700 Subject: [PATCH 5/6] Fix bower main path. --- bower.json | 2 +- dist/es5-url-tld.min.js | 2 +- dist/es5-url.min.js | 2 +- dist/jquery-url-tld.min.js | 2 +- dist/jquery-url.min.js | 2 +- dist/url-tld.min.js | 2 +- dist/url.min.js | 2 +- package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index 4fd3e4a..e0adde7 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ "homepage": "https://github.com/websanova/js-url", "license": "MIT", "main": [ - "./dist/es5-url-min.js" + "./dist/es5-url.min.js" ], "ignore": [ "demo", diff --git a/dist/es5-url-tld.min.js b/dist/es5-url-tld.min.js index 5516034..66b3e97 100644 --- a/dist/es5-url-tld.min.js +++ b/dist/es5-url-tld.min.js @@ -1,4 +1,4 @@ -/*! @websanova/url - v2.6.2 - 2020-01-25 */ +/*! @websanova/url - v2.6.3 - 2020-01-25 */ var url = function(){function r(r,c){var t,o={};if("tld?"===r)return n();if(c=c||window.location.toString(),!r)return c;if(r=r.toString(),t=c.match(/^mailto:([^\/].+)/))o.protocol="mailto",o.email=t[1];else{if((t=c.match(/(.*?)\/#\!(.*)/))&&(c=t[1]+t[2]),(t=c.match(/(.*?)#(.*)/))&&(o.hash=t[2],c=t[1]),o.hash&&r.match(/^#/))return e(r,o.hash);if((t=c.match(/(.*?)\?(.*)/))&&(o.query=t[2],c=t[1]),o.query&&r.match(/^\?/))return e(r,o.query);if((t=c.match(/(.*?)\:?\/\/(.*)/))&&(o.protocol=t[1].toLowerCase(),c=t[2]),(t=c.match(/(.*?)(\/.*)/))&&(o.path=t[2],c=t[1]),o.path=(o.path||"").replace(/^([^\/])/,"/$1"),r.match(/^[\-0-9]+$/)&&(r=r.replace(/^([^\/])/,"/$1")),r.match(/^\//))return a(r,o.path.substring(1));if((t=(t=a("/-1",o.path.substring(1)))&&t.match(/(.*?)\.([^.]+)$/))&&(o.file=t[0],o.filename=t[1],o.fileext=t[2]),(t=c.match(/(.*)\:([0-9]+)$/))&&(o.port=t[2],c=t[1]),(t=c.match(/(.*?)@(.*)/))&&(o.auth=t[1],c=t[2]),o.auth&&(t=o.auth.match(/(.*)\:(.*)/),o.user=t?t[1]:o.auth,o.pass=t?t[2]:void 0),o.hostname=c.toLowerCase(),"."===r.charAt(0))return a(r,o.hostname);n()&&(t=o.hostname.match(n()))&&(o.tld=t[3],o.domain=t[2]?t[2]+"."+t[3]:void 0,o.sub=t[1]||void 0),o.port=o.port||("https"===o.protocol?"443":"80"),o.protocol=o.protocol||("443"===o.port?"https":"http")}return r in o?o[r]:"{}"===r?o:void 0}function n(){return new RegExp(/(.*?)\.?([^\.]*?)\.(gl|com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function a(r,c){var t=r.charAt(0),o=c.split(t);return t===r?o:o[(r=parseInt(r.substring(1),10))<0?o.length+r:r-1]}function e(r,c){for(var t,o=r.charAt(0),n=c.split("&"),a=[],e={},m=[],i=r.substring(1),s=0,h=n.length;s Date: Wed, 26 Aug 2020 13:23:40 +0700 Subject: [PATCH 6/6] Update license date and readme sponsors. --- .github/FUNDING.yml | 2 ++ LICENSE | 22 ++++++++++++++++++++++ README.md | 12 +++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/FUNDING.yml create mode 100644 LICENSE diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..91da654 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: websanova +patreon: websanova \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a47a077 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2020 Websanova (https://websanova.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 617e2c5..257ade1 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,21 @@ A simple light weight JavaScript url parser. * [Docs](https://websanova.com/docs/url) * [Download](https://github.com/websanova/js-url/tags) + +## Sponsor + +If you like this plugin please consider sponsoring. + +* [GitHub](https://github.com/sponsors/websanova) +* [Patreon](https://patreon.com/websanova) + + ## Availability * [NPM](https://www.npmjs.com/package/@websanova/url) * [jQuery](https://plugins.jquery.com/url) + ## Test There are a number of files for testing in the `test` folder including QUnit. @@ -28,4 +38,4 @@ To build simply run: MIT licensed -Copyright (C) 2011-2012 Websanova http://www.websanova.com \ No newline at end of file +Copyright (C) 2011-2020 Websanova http://www.websanova.com \ No newline at end of file