New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

url-js

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-js

Simple URL parser, similar to DOM URL

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
333
increased by31.1%
Maintainers
1
Weekly downloads
 
Created
Source

URL.js Build Status

Parse and format URLs

Usage

// 1. Parse full URL
    var url = URL("https://www.duzun.me/path/index.php?var1=223#hash") ->
    {
      "protocol": "https:",
      "username": "",
      "password": "",
      "host"    : "www.duzun.me",
      "hostname": "www.duzun.me",
      "port"    : "",
      "pathname": "/path/index.php",
      "search"  : "?var1=223",
      "query"   : "var1=223",
      "hash"    : "#hash",
      "path"    : "/path/index.php?var1=223",
      "origin"  : "https://www.duzun.me",
      "domain"  : "duzun.me",
      "href"    : "https://www.duzun.me/path/index.php?var1=223#hash"
    }

    String(url) -> "https://www.duzun.me/path/index.php?var1=223#hash"


// 2. Compute full URL for a relative URL
    String( URL("new/?and=var", url) ) -> "https://www.duzun.me/path/new/?and=var"


// 3. Get part of an URL
    URL.parseUrl("https://duzun.me/path/index.php", "origin") -> "https://duzun.me"
    URL.parseUrl("https://duzun.me/path/index.php", "pathname") -> "/path/index.php"
    URL.parseUrl("https://duzun.com/?var1=2&var2=d%27t&var3", "query", true) -> { var1: "2", var2: "d't", var3: "" }


// 4. Validation
    URL.is_url('http://duzun.me') -> true
    URL.is_domain('duzun.me')     -> true


// 5. GET < - > Object conversion
    URL.fromObject({a:1,b:4}, "?")   -> "?&a=1&b=4"
    URL.toObject('a=1&b=4')          -> { a: 1, b: 4 }

Note: If included in global scope with a <script> tag, you can var URLJS = URL.noConflict() to restore original window.URL and keep using URLJS in your module.

Keywords

FAQs

Package last updated on 13 Apr 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc