0.0.2 • Published 8 years ago

url-param-parser v0.0.2

Weekly downloads
4
License
MIT License
Repository
-
Last release
8 years ago

URL-Param-Parser.js

We often need convert the string to object from URL, eg: QueryString, Hash, AJAX crawling scheme...

I hope this simple function can let you're at ease.

Parse Rule

URL Hash Fragment

A string which contain #, and only works at browser.

Pure Hash Fragment

A string only contain #.

NoOrigin URL StringParse Hash StringParse Hash ObjectParse Reason
1http://this.is.example.url/abcnull{hash: null}without #.
2http://this.is.example.url/#undefined{hash: undefined}nothing after #.
3http://this.is.example.url/abc#undefined{hash: undefined}nothing after #.
4http://this.is.example.url/#11{hash: {1: undefined}}String 1 after #.
5http://this.is.example.url/#a=ba=b{hash: {a: "b"}}String a=b after #.
6http://this.is.example.url/###null{hash: null}# shouldn't repeat more than one time.
7http://this.is.example.url/abc##null{hash: null}# shouldn't repeat more than one time.
8http://this.is.example.url/abc##1null{hash: null}# shouldn't repeat more than one time.

Hash Fragment With Browser-Only QueryString

A string contain #?.

NoOrigin URL StringParse Hash StringParse Hash ObjectParse Reason
1http://this.is.example.url/abc#?undefined{hash: undefined}nothing after #?.
2http://this.is.example.url/#?11{hash: {1: undefined}}String 1 after #?.
3http://this.is.example.url/#?a=ba=b{hash: {a: "b"}}String a=b after #?.

otherwise above, the Parse Hash String equal null, and Parse Hash Object equal {hash: null}.

URL Pathname

NoOrigin URL StringParse Hash StringParse Hash ObjectParse Reason
1http://this.is.example.url/ABCABC{path: {ABC: undefined}}-
2http://this.is.example.url/A=BA=B{path: {A: 'B'}}-
3http://this.is.example.url/A=B== (base64)A=B=={path: {A: 'B=='}}-
4http://this.is.example.url/=Bnull{path: null}-
5http://this.is.example.url/=null{path: null}-

otherwise above, the Parse Hash String equal null, and Parse Hash Object equal {path: null}.

QueryString

NoOrigin URL StringParse Hash StringParse Hash ObjectParse Reason
1http://this.is.example.url/?abcabc{query: {abc: undefined}}-
2http://this.is.example.url/?abc=1abc=1{query: {abc: "1"}}-
3http://this.is.example.url/???abcabc{query: {abc: undefined}}-
4http://this.is.example.url/??abc?ver=1ver=1{query: {ver: "1"}}-
5http://this.is.example.url/??abc?ver=1??abcnull{query: null-

###AJAX crawling scheme

  • to be continue...

Author

2015 - soulteary

License

MIT License