bb-parse-url
v2.0.1
Published
An advanced url parser supporting git urls too.
Downloads
4
Readme
parse-url
An advanced url parser supporting git urls too.
:cloud: Installation
$ npm i --save parse-url
:clipboard: Example
// Dependencies
const parseUrl = require("parse-url");
console.log(parseUrl("http://ionicabizau.net/blog"));
// { protocols: [ 'http' ],
// protocol: 'http',
// port: null,
// resource: 'ionicabizau.net',
// user: '',
// pathname: '/blog',
// hash: '',
// search: '',
// href: 'http://ionicabizau.net/blog' }
console.log(parseUrl("http://domain.com/path/name?foo=bar&bar=42#some-hash"));
// { protocols: [ 'http' ],
// protocol: 'http',
// port: null,
// resource: 'domain.com',
// user: '',
// pathname: '/path/name',
// hash: 'some-hash',
// search: 'foo=bar&bar=42',
// href: 'http://domain.com/path/name?foo=bar&bar=42#some-hash' }
console.log(parseUrl("git+ssh://[email protected]/path/name.git"));
// { protocols: [ 'git', 'ssh' ],
// protocol: 'git',
// port: null,
// resource: 'host.xz',
// user: 'git',
// pathname: '/path/name.git',
// hash: '',
// search: '',
// href: 'git+ssh://[email protected]/path/name.git' }
console.log(parseUrl("[email protected]:IonicaBizau/git-stats.git"));
// { protocols: [],
// protocol: 'ssh',
// port: null,
// resource: 'github.com',
// user: 'git',
// pathname: '/IonicaBizau/git-stats.git',
// hash: '',
// search: '',
// href: '[email protected]:IonicaBizau/git-stats.git' }
:memo: Documentation
parseUrl(url)
Parses the input url.
Params
- String
url
: The input url.
Return
- Object An object containing the following fields:
protocols
(Array): An array with the url protocols (usually it has one element).protocol
(String): The first protocol,"ssh"
(if the url is a ssh url) or"file"
.port
(null|Number): The domain port.resource
(String): The url domain (including subdomains).user
(String): The authentication user (usually for ssh urls).pathname
(String): The url pathname.hash
(String): The url hash.search
(String): The url querystring value.href
(String): The input url.
:yum: How to contribute
Have an idea? Found a bug? See how to contribute.
:dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:
deploy-versioning
—Deploy your code keeping older versions.git-up
—A low level git url parser.hubot-will-it-connect
(by gambtho)—Connects hubot with willitconnect, to validate CF's ability to connect to external resourceskakapo
(by devlucky)—Next generation mocking framework in Javascriptlien
—Another lightweight NodeJS framework. Lien is the link between request and response objects.microbe.js
(by Brandon Dail)—A small Node.js framework for simple routingtumblr-text
(by cobaimelan)— [](https://david-dm.org/ayhanurl-local
—Checks if a given url is a local url or not.