0.0.4 • Published 5 years ago

x-hyperlink v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Deprecated

This module is deprecated! Please use HyperlinkParser.js instead!

Hyperlink.js

npm version Build Status install size npm downloads

Hyperlink.js is an util to parse URL. Can be used in Node.js and browsers. For details, see the example in the following section.

Installation

npm i x-hyperlink

Example

// `Hyperlink` is a constructor.
var Hyperlink = require('x-hyperlink');

// The url for testing.
var url = 'https://user:pass@example.com:8080/search?q=javascript#results';

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

// Or you can use the constructor directly:
// var link = new Hyperlink(url);

The link is an instance of 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 property has dependency on other properties. The best way to update the property is use the setter methods, which will handle the dependencies among them. All available methods are listed as follow:

  • Hyperlink.parse(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

Links

License

MIT

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago