websanova / js-url Goto Github PK
View Code? Open in Web Editor NEWurl() - A simple, lightweight url parser for JavaScript
Home Page: http://www.websanova.com
License: MIT License
url() - A simple, lightweight url parser for JavaScript
Home Page: http://www.websanova.com
License: MIT License
From exemple http://rob:[email protected]/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese
, I expected $url('#poo') == null
rather than an empty string.
Otherwise, there is no mechanisme to distinguish http://exemple.com#foo
and http://exemple.com
$.url('host', 'http://www.google.com.br')
> "com.br"
$.url('sub', 'http://www.google.com.br')
> "www.google"
$.url('tld', 'http://www.google.com.br')
> "br"
In your readme
link "Download the lastest version of url" https://github.com/websanova/url/tags is broken
I noticed that url('protocol', 'mailto:[email protected]')
returns http
.
Is there any way to detect for 'non-web' URI schemes? (not sure on the exact nomenclature)
You are using arg[0] to access character of a string.
This returned "" for me in IE8.
I have changed all arg[x] to arg.chatAt[x] and it worked well.
bower is handy...
Getting the last part of the url (ie. $.url(-1)) also returns the hash value.
e.g. http://www.domain.com/sub#hash gives "sub#hash" and not "hash".
Current Behaviour:
url('email', 'mailto:[email protected]?subject=Hi'); // [email protected]?subject=Hi
url('?subject', 'mailto:[email protected]?subject=Hi'); // undefined
Expected Behaviour:
url('email', 'mailto:[email protected]?subject=Hi'); // [email protected]
url('?subject', 'mailto:[email protected]?subject=Hi'); // Hi
In the documentation the following statement:
url('path', 'http://www.example.com:8080/some/path');
should return
/some/path
the result I get from version 1.8.0 is:
/some/path/
Please, can you make the behaviour the same as the documentation? The ending / should not be added.
Library from: http://cdnjs.cloudflare.com/ajax/libs/js-url/1.8.0/js-url.min.js
my url is http://localhost:50001/a/b/Index?reportno=1392
when i use
var reportno = $.url('?reportno');
Firebug error:TypeError: split[i].match is not a function url.js(line 31,col 21)
my jquery version is jquery-1.11.3.min.js
"dependencies": {
"grunt-contrib-qunit": "",
"grunt-contrib-uglify": "",
"grunt-contrib-jshint": ""
},
grunt-contrib-*
should be put into devDependencies
not dependencies
its active domain but plugin shows undefined
Not sure if people consider this an issues, however, arrays are apparently padded with nulls for missing values,
> JSON.stringify(url('?','?t[0]=x&t[1]=y'));
"{"t":["x","y"]}"
> JSON.stringify(url('?','?t[0]=x&t[2]=y'));
"{"t":["x",null,"y"]}"
Maybe the better option would be to return objects for sparse arrays, like so,
> JSON.stringify(url('?','?t[0]=x&t[1]=y'));
"{"t":["x","y"]}"
> JSON.stringify(url('?','?t[0]=x&t[2]=y'));
"{"0":"x","2":"y"}"
I believe that documentation example
url('?'); // {query1: 'test', silly: 'willy'}
is missing the field
parameter which would be an array of length 3
, but with 2
elements. Don't know how to denote that clearly, so I made an issue :)
http://localhost:6744/index.html#pagesClient/VedListCompare.html?road=2&&vv=143&relvv=148
url('?road') => undefined
Given the example -
$.url('domain'); // www.domain.com
$.url('host'); // domain.com
'domain.com' is the domain, and 'www.domain.com' is the host.
It would be very good to have the library work in node. Any plans?
url('domain','http://mall.belle.net.cn/')
now this result is wrong: net.cn
correct result: belle.net.cn
You might want to note that your parser is incompatible with Internet Explorer 7 and below. Alternatively you may want to replace arg[0]
(line 48 and others) by arg.substring(0, 1)
or something.
in Line 23 you're assuming that //hostname
equals http://hostname
. That is only true if the scheme of the document's resource the script is executed in is http
. Should the page be served via https, this little line defeats the purpose of "scheme agnostic URLs".
According to RFC 3986 Section 3.3, this is a a valid path: "/foo/xy://bar"
- but url("path", "/foo/xy://bar") === "//bar/"
- which is wrong…
I have stopped reviewing the code on line 32 because I found it unbearable to read without "running every single expression in my head".
It would be nice to have a bower package for js-url library.
Publishing in bower would make it easier to find and install js-url.js library.
version: 2.0.2
var urlString = http://localhost/news/list
window.url('file', urlString): undefined //should be "list"
window.url('filename', urlString): undefined //should be "list"
window.url('-1', urlString): list
var urlString = http://localhost/news/list.
window.url('file', urlString): undefined //should be "list."
window.url('filename', urlString): undefined //should be "list"
window.url('-1', urlString): list.
var urlString = http://localhost/news/list/
window.url('file', urlString): undefined
window.url('filename', urlString): undefined
window.url('-1', urlString): list //should be ""
var urlString = http://localhost/news/list.html
window.url('file', urlString): list.html
window.url('filename', urlString): list
window.url('-1', urlString): list.html
The domain-first domain approach is incorrect. For example, goo.gl returns undefined
$.url('domain', '//github.com')
// ''
there is a bug on your url.min.js
url('domain') not work (undefined)
the url.js works but url.min.js not work.
Input
jsUrl('fileext', 'path/pdfname.suffix.pdf')
Output:
suffix.pdf
Expected:
pdf
Needs tests
Hi Rob
Can you please take a look on this line?
Thanks for your work.
It would be helpful if this was mentioned in the examples
www.example.com/?prop
url("?prop") -> undefined
www.example.com/
url("?prop") -> null
Also it might make more sense if the first case returned ""
instead of undefined
It would be nice to include AMD support.
if ?poo is not exist,url('?poo') value is undefined,not null.
url('?poo'); // null should be -> undefined
eg. url#/page1.html?param1=value1
url('?param1'); //undefined
url('#page1.html?param1') // value1
$.url('host', 'http://[email protected]')
// "[email protected]"
Should be example.org
Seriously, this library has really nothing to do with jQuery, it should be plain JavaScript.
I am doing development with a popular framework KendoUI which uses this format for Single Page Application (SPA) on mobile, eg:
theurl = "http://localhost:8080/index.html#details?id=1";
I really like this library, currently using: window.url( '#details?id', theurl); which returns 1.
It would be great to handle the case window.url( '?id', url); and return 1 in my example or if that conflicts with another case just add this example to the tests.js to save others time trying combinations to get this case working. Cheers!
example.plus
=> pl.us
Current list of TLDs:
http://data.iana.org/TLD/tlds-alpha-by-domain.txt
Multidimensional arrays are not parsed correctly,
> JSON.stringify(url('?','?t[0][0]=x'));
"{"t[0]":["x"]}"
> JSON.stringify(url('?','?t[0][0]=x&t[1][0]=y'));
"{"t[0]":["x"],"t[1]":["y"]}"
The expected behavior is as follows,
> JSON.stringify(url('?','?t[0][0]=x'));
"{"t":[["x"]]}"
> JSON.stringify(url('?','?t[0][0]=x&t[1][0]=y'));
"{"t":[["x"],["y"]]}"
Might be more useful if you refactored to be a polyfill for the actual URL API spec
.ly is widely used.
.xyz is popular now after www.abc.xyz
Hello,
Very nice script, but doesn't work in IE 9 due to its dependence on the "split" function.
Cheers,
Jeff.
Found this issue:
When trying to parse the following url: https://facebook.com\@account.google.com/x
url('domain', 'https://facebook.com\@account.google.com/x') // outputs 'google.com'
This outputs google.com
as the domain instead of facebook.com
The library seems to be performing double decoding when user tries to access param or attr method.
How to reproduce:
I just used chrome console:
$.getScript('/js/purl.js')
var test='http://localhost:8080?id=test%255Ftest'; //where test%255Ftest is "test%5Ftest" encoded
purl(test, true).param('id'); //outputs test_test
The first decoding during parseURI phase produces correct param test%test but then it goes onto create the param list in following line
uri.param['query'] = parseString(uri.attr['query']);
parseString internally again calls decodeURI, %5F is URL encoded '_' so the final result is 'test_test'.
in summary
test%5Ftest -> encode -> test%255Ftest -> decode() Line 40 -> test%5Ftest -> decode Line 131 -> results in test_test.
Would you be so kind to release a nuget package for .NET?
Thx!
use this url 'https://test-passport.jindashi.cn/TDOA/page/pfyh/quick.html'
the result domain is hi.cn not jindashi.cn
There seems to be an issue parsing non-numeric keys in array arguments. Check out the following,
> JSON.stringify(url('?','?t[0]=x&t[1]=y'));
"{"t":["x","y"]}"
> JSON.stringify(url('?','?t[a]=x&t[b]=y'));
"{"t[a]":"x","t[b]":"y"}"
The expected behavior is,
> JSON.stringify(url('?','?t[0]=x&t[1]=y'));
"{"t":["x","y"]}"
> JSON.stringify(url('?','?t[a]=x&t[b]=y'));
"{"t":{"a":"x","b":"y"}}"
$.url('path','http://vm.sovrhistory.ru/february-v1/')
returns "/february-v1"
expected "/february-v1/"
url('?q', 'http://www.google.com/?q=a+b')
returns the raw result a+b
, rather than the querystring unencoded a b
. That means I have to decode the string--I can't think of any case I'd want the current behavior.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.