JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q27489F
  • License MIT

An util to parse the URLs in Node.js and the browsers.

Package Exports

  • hyperlink-parser

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 (hyperlink-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

HyperlinkParser.js

npm version Build Status install size npm downloads

HyperlinkParser.js is an util to parse the URLs. Can be used in Node.js and the browsers. The properties of the parsed URL is same as the properties of HTMLHyperlinkElementUtils. For more details, see the example in the following section.

Installation

npm i hyperlink-parser

Example

var HyperlinkParser = require('hyperlink-parser');
var url = 'https://user:pass@example.com:8080/search?q=javascript#results';

/**
 * @type {HyperlinkParser.Hyperlink}
 */
var hyperlink = HyperlinkParser.parse(url);

The hyperlink is an instance of HyperlinkParser.Hyperlink which holds the following informations:

{
    "href": "https://user:pass@example.com:8080/search?q=javascript#results",
    "origin": "https://example.com:8080",
    "protocol": "https:",
    "username": "user",
    "password": "pass",
    "host": "example.com:8080",
    "hostname": "example.com",
    "port": "8080",
    "pathname": "/search",
    "search": "?q=javascript",
    "hash": "#results"
}

API

Do not modify the properties of the Hyperlink instance directly, because some properties has dependencies on the others. The best way to update the properties is using the setter methods, which will handle the dependencies among them. All the APIs are listed as follow:

  • HyperlinkParser.version
  • HyperlinkParser.parse(url)
  • Hyperlink.prototype.constructor([url])
  • Hyperlink.prototype.setHref(href)
  • Hyperlink.prototype.setProtocol(protocol)
  • Hyperlink.prototype.setUserName(username)
  • Hyperlink.prototype.setPassword(password)
  • Hyperlink.prototype.setHost(host)
  • Hyperlink.prototype.setHostName(hostname)
  • Hyperlink.prototype.setPort(port)
  • Hyperlink.prototype.setPathName(pathname)
  • Hyperlink.prototype.setSearch(search)
  • Hyperlink.prototype.setHash(hash)
  • Hyperlink.prototype.toString()

As you can see, there is no setter method to modify the origin property. If you want to modify the origin property, call setProtocol(protocol) and setHost(host).

Dev commands

# Start local server and compiler
npm run dev

# Build the release bundle
npm run build

# Run test
npm test

License

MIT