bb-parse-url

2.0.1 • Public • Published

parse-url

PayPal AMA Travis Version Downloads Get help on Codementor

An advanced url parser supporting git urls too.

☁️ Installation

$ npm i --save parse-url

📋 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://git@host.xz/path/name.git"));
// { protocols: [ 'git', 'ssh' ],
//   protocol: 'git',
//   port: null,
//   resource: 'host.xz',
//   user: 'git',
//   pathname: '/path/name.git',
//   hash: '',
//   search: '',
//   href: 'git+ssh://git@host.xz/path/name.git' }

console.log(parseUrl("git@github.com:IonicaBizau/git-stats.git"));
// { protocols: [],
//   protocol: 'ssh',
//   port: null,
//   resource: 'github.com',
//   user: 'git',
//   pathname: '/IonicaBizau/git-stats.git',
//   hash: '',
//   search: '',
//   href: 'git@github.com:IonicaBizau/git-stats.git' }

📝 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.

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

💫 Where is this library used?

If you are using this library in one of your projects, add it in this list. ✨

  • 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 resources
  • kakapo (by devlucky)—Next generation mocking framework in Javascript
  • lien—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 routing
  • tumblr-text (by cobaimelan)—Build Status [Build Status](https://david-dm.org/ayhan
  • url-local—Checks if a given url is a local url or not.

📜 License

MIT © Ionică Bizău

Package Sidebar

Install

npm i bb-parse-url

Weekly Downloads

0

Version

2.0.1

License

MIT

Last publish

Collaborators

  • richiebres