🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

hyperlink-parser

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperlink-parser

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

Source
npmnpm
Version
0.0.1-alpha
Version published
Weekly downloads
22
144.44%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

parseURL

FAQs

Package last updated on 03 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts