🚀 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

A tool for parsing hyperlinks

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
22
144.44%
Maintainers
1
Weekly downloads
 
Created
Source

npm version 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, please read the following example.

Installation

npm i hyperlink-parser

Example

import HyperlinkParser from 'hyperlink-parser'

const link = HyperlinkParser.parse('https://user:pass@example.com:8080/search?q=javascript#results")

console.log(link)

The result is a plain object containing following properties.

{
  "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"
}

The stringify method is designed to build a url from an object, for example:

const url = HyperlinkParser.stringify({
  "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"
})

console.log(url)

// https://user:pass@example.com:8080/search?q=javascript#results

License

MIT

Keywords

url

FAQs

Package last updated on 04 Aug 2023

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