JSPM

  • Created
  • Published
  • Downloads 5135762
  • Score
    100M100P100Q193364F
  • License MIT

An advanced url parser supporting git urls too.

Package Exports

  • parse-url

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-url) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

parse-url PayPal Travis Version Downloads Get help on Codementor

An advanced url parser supporting git urls too.

Installation

$ npm i --save parse-url

Example

// Dependencies
var ParseUrl = require("parse-url");

console.log(ParseUrl("http://ionicabizau.net/blog"));
// => {
//     protocols: [ "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"]
//   , 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"]
//   , port: null
//   , resource: "host.xz"
//   , user: "git"
//   , pathname: "/path/name.git"
//   , hash: ""
//   , search: ""
// }

console.log(ParseUrl("git@github.com:IonicaBizau/git-stats.git"));
// => {
//     protocols: []
//   , 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).
  • 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. ✨

License

MIT © Ionică Bizău